Speech Synthesizer in Blitz

BlitzMax Forums/BlitzMax Programming/Speech Synthesizer in Blitz

I used to have software speech synthesizers on both my BBC Micro and Amiga computers. You could just type a command like Say "Hello - How are you today?" and it would say it. You could alter the tone and timbre and speed of the voice too.

I was wondering if there are any modules available for Blitz to do this?

No.

Fairly tricky to do I'd think you'd have to generate audio sample data on the fly based on presampled parts of words or whatever, to make it sound half decent. The Amiga version was quite monotonous.

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 Type


example.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()


Actually I don;t mind if it doesn;t sound like a real human - just something recognizeable as speech will do.

Plash - so what you're saying is that that library doesn't work yet?

Thanks for the help.

so what you're saying is that that library doesn't work yet?
Not for Max.. I still don't know why it crashes on the call.

It still works in BlitzPlus.

ok - thats a shame :(

I wish I could help - but I'm not very knowledgeable with this sort of thing. Maybe someone else could help?

Good luck - hopefully one day I will be able to use that module too!

It seems to be that one function.. the function VoiceAvailable() seems to be working (although, it was written illogically, with a return of False actually saying that there is a voice API present.)

Updated code in previous post..

EDIT: I apparently cannot read BlitzPlus code anymore. VoiceAvailable is logically correct, I just didn't pay attention.. It seems to be returning False always, where in BlitzPlus it returns True.

I am very interested in using text to speech unde blitzmax; I know 'So to speak' library is usable in blitzplus, but I never succeeded in porting it to blitzmax; can someone help please?

i guess the others 'worked' on lowly 8 and 16bit computers as they had 'chip music' sound chips and we never really had that option with adlib or creative in the early days and beep wouldnt cut it

to them the phonetic alphabet would just be small chunks of data (by todays standards) yet on a pc you'd need alot of (perhaps) cd quality wav files to stitch words together
or do what interplay did over a decade ago with a startrek game
have some patented script that people read out that sounded gibberish
then mark the sound file with reference points
they managed to get jean luc picard to sound like jean luc picard even though patric stewart only read a small script instead of every line of dialogue (which was the norm for the time)

mmmhh
I wonder if there is a way to access Microsoft Speech SDK 5.1 through Speech API (SAPI)
yes I know it's Microsoft, and only working on windows, but it's free and it works...
someone could show me a way to access Speech API in BlitzMax?
I think a dedicated module should do the work, but it'out of my programming abilities....

if you have maxgui you may want to try playing with microsoft agent technology

not sure if this stuff just works or not from vista, all downloads for xp at microsoft seem to be broken