[bb] Text-to-Speech (PC) by Radman [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Text-to-Speech (PC)
Author : Radman
Posted : 1+ years ago

Description : This program uses VBScript to turn text into speech. If you use the text-to-speech function when it is already being used, it will wait until the first speech is finished before starting the second. Feel free to use this in your programs!

Code :
Code (blitzbasic) Select
;The Text-to-Speech Program for the PC
;          Jason Hendricks            

;Types
;This type allows you to have more than one text-to-speech at once! (The program will crash without this...)
Global a = 0 ;This is the accumulator variable that is required for the text-to-speech function
Type Voice
Field file ;The file handle
End Type

;Ask "What do you want me to say?"
MyText$ = Input$("What do you want to say? ")
Say(MyText$) ;This command turns the text "Voice$" into speech.
Print "You are now saying:"
Print MyText$
Delay 10000 ;Wait for a while. (If you remove this, it still talks!)

;Functions
;Speak Function (If you paste this function and the type "Say" to your program then you can use the command Say(text$) to turn your text to speech!)
Function Say(words$)
v.Voice = New Voice ;Make a new file handle...
a = a + 1 ;Write to the next vbs file...

;Write a .vbs file to execute speech
vfile = WriteFile("C: emp" + Str$(a) + ".vbs")
WriteLine(vfile,"Set objVoice = CreateObject(" + Chr$(34) + "SAPI.SpVoice" + Chr$(34) + ")") ;Activate the text-to-speech function
WriteLine(vfile,"ObjVoice.speak " +Chr$(34) + words$ + Chr$(34)) ;"words$" is the text that is turned to speech
CloseFile(vfile) ;Save the file
ExecFile("C: emp" + Str$(a) + ".vbs") ;Turn the text into speech!
End Function

;If you want to use this in your program, copy the type and function into your program.
;Jason Hendricks


Comments :


Guy Fawkes(Posted 1+ years ago)

 Great... Now if only we had voice recognized commands such as "Computer do this, computer do that, etc..."...