Here is a library for BlitzPlus/3D for TTS ('So To Speak')
I'm attempting to convert it to Max but InitVoice is throwing an unhandled memory exception error.
I've tried "C" and "win32" at the end of the function declarations, that didn't do anything.
Debugging shows the functions have obtained pointers.
sts_lib.bmx
Extern "win32"
'Function LoadLibraryA(dll$Z)
Function FreeLibrary(hnd:Int)
'Function GetProcAddress:Byte Ptr(libhandle:Int, func$Z)
End Extern
Global sts_InitVoice() '"C"
Global sts_FreeVoice() '"C"
Global sts_GetVoiceCount:Int() '"C"
Global sts_GetVoiceName$Z(Index:Int) '"C"
Global sts_Say(str$Z) '"C"
Global sts_SayAndWait(str$Z) '"C"
Global sts_PauseVoice() '"C"
Global sts_ResumeVoice() '"C"
Global sts_SetVoice(Index:Int) '"C"
Global sts_WaitUntilDone:Int(millisec:Int) '"C"
Global sts_SetVoiceRate(i:Int) '"C"
Global sts_GetVoiceRate:Int() '"C"
Global sts_VoiceAvailable:Int() '"C"
Global sts_GetVoiceState:Int() '"C"
Global sts_SpeakToFile:Int(FileName$Z, SayStr$Z) '"C"
Global sts_GetVoiceVolume:Int() '"C"
Global sts_SetVoiceVolume(volume:Int) '"C"
Local tspk:TSpeaker = New(TSpeaker)
Type TSpeaker
Global lib_handle:Int
Function SetupSpeaker:Int()
lib_handle = LoadLibraryA("speaker.dll")
Print(lib_handle)
If lib_handle
sts_InitVoice = GetProcAddress(lib_handle, "InitVoice")
sts_FreeVoice = GetProcAddress(lib_handle, "FreeVoice")
sts_GetVoiceCount = GetProcAddress(lib_handle, "GetVoiceCount")
sts_GetVoiceName = GetProcAddress(lib_handle, "GetVoiceName")
sts_Say = GetProcAddress(lib_handle, "Say")
sts_SayAndWait = GetProcAddress(lib_handle, "SayAndWait")
sts_PauseVoice = GetProcAddress(lib_handle, "PauseVoice")
sts_ResumeVoice = GetProcAddress(lib_handle, "ResumeVoice")
sts_SetVoice = GetProcAddress(lib_handle, "SetVoice")
sts_WaitUntilDone = GetProcAddress(lib_handle, "WaitUntilDone")
sts_SetVoiceRate = GetProcAddress(lib_handle, "SetVoiceRate")
sts_GetVoiceRate = GetProcAddress(lib_handle, "GetVoiceRate")
sts_VoiceAvailable = GetProcAddress(lib_handle, "VoiceAvailable")
sts_GetVoiceState = GetProcAddress(lib_handle, "GetVoiceState")
sts_SpeakToFile = GetProcAddress(lib_handle, "SpeakToFile")
sts_GetVoiceVolume = GetProcAddress(lib_handle, "GetVoiceVolume")
sts_SetVoiceVolume = GetProcAddress(lib_handle, "SetVoiceVolume")
If sts_InitVoice = Null Or sts_FreeVoice = Null Or ..
sts_GetVoiceCount = Null Or sts_GetVoiceName = Null Or ..
sts_Say = Null Or sts_SayAndWait = Null Or sts_PauseVoice = Null Or ..
sts_ResumeVoice = Null Or sts_SetVoice = Null Or sts_WaitUntilDone = Null Or ..
sts_SetVoiceRate = Null Or sts_GetVoiceRate = Null Or sts_VoiceAvailable = Null Or ..
sts_GetVoiceVolume = Null Or sts_SetVoiceVolume = Null
DebugLog("Failed to retrieve a function address")
Return(False)
End If
'Illogical function, original source called it as 'If Not VoiceAvailable() ...'
If sts_VoiceAvailable() = False
sts_InitVoice()
Return(True)
Else
Print("Voice synth not found on your computer")
Return(False)
End If
Else
Return(False)
End If
End Function
Function FreeSpeaker()
If lib_handle
sts_FreeVoice()
FreeLibrary(lib_handle)
End If
End Function
End Typeexample.bmx
SuperStrict
Import brl.standardio
Import pub.win32
Include "sts_lib.bmx"
If TSpeaker.SetupSpeaker() = True
sts_SetVoiceRate(1)
sts_Say("Hello World!")
Else
Print("Failed to load speaker.dll") ; End
End If
TSpeaker.FreeSpeaker()