Text-to-speech!

Blitz3D Forums/Blitz3D Programming/Text-to-speech!

ClayPigeon(Posted 2014) [#1]
I came up with a little trick for performing text-to-speech with B3D! It uses a VB script, so it's obviously not going to be very flexible, but if you really need TTS for some reason, let there be TTS!

Graphics 640,480,0,2

speak$ = Input("Say: ")

If FileType("TTS.vbs") = 1 Then DeleteFile "TTS.vbs"
strScript% = WriteFile("TTS.vbs")
WriteLine strScript,"Set objVoice = CreateObject("+Chr(34)+"SAPI.SpVoice"+Chr(34)+")"
WriteLine strScript,"objVoice.Speak "+Chr(34)+speak+Chr(34)
CloseFile strScript

ExecFile "TTS.vbs"

Print "Speaking..."
WaitKey()

End


If you're interested in how it works, take a look at the TTS.vbs file it spits out. The script is fairly straightforward and should clarify some things at a glance. Enjoy!

EDIT: If you want to change the voice, simply add the following code between the two original WriteLines, replacing "Name=Microsoft Anna" with whatever voice you want:

WriteLine strScript,"Set objVoice.Voice = objVoice.GetVoices("+Chr(34)+"Name=Microsoft Anna"+Chr(34)+").Item(0)"


Just remember, if you enter the name of a voice that isn't installed on the user's computer, it will flash a nasty error message on your screen and fail to read the text, so to prevent that, it's best to just leave it at the default (don't add that line ^).

EDIT 2: A little more research yielded this gem of a useful function:

WriteLine strScript,"Set objFile = CreateObject("+Chr(34)+"SAPI.SpFileStream.1"+Chr(34)+")"
WriteLine strScript,"objFile.Open "+Chr(34)+CurrentDir()+"TTS.wav"+Chr(34)+",3"
WriteLine strScript,"Set objVoice.AudioOutputStream = objFile"


Just wedge those three lines in between the two original WriteLines, and instead of reading the text aloud, it will render it directly to a wave file called TTS.wav, located in the same folder as the EXE. Then, you could just open the .wav in B3D with LoadSound. I could see this being used to batch generate some spoken dialogue at the startup of a game.


John Blackledge(Posted 2014) [#2]
Not wanting to steal your thunder ClayPigeon, but this one is Blitz specific, with a .bb demo.

I've noticed a few other threads have been asking for it.
It's ages old, but seems to have disappeared from these forums.

I've zipped it up, and included the M$ setup program, some extra voices, and a quick read me.

http://www.tla-data.co.uk/download/blitz/speech.zip


ClayPigeon(Posted 2014) [#3]
Yeah, I've seen So to Speak. I was just supplying a slightly quicker/smaller solution that doesn't require a DLL or any libs. StS is a great lib, though!


Yue(Posted 2014) [#4]
@John
How I can add a voice in Spanish in Windows XP?


Dan(Posted 2014) [#5]
Maybe this link is usefull for you Yue:
http://msagentring.org/setup.aspx