WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Speech

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Text to Speech

 Keywords: SAPI SPEECH TTS

WinBatch can control text-to-speech (TTS) using the ISpVoice Component Object Model (COM) interface. Once you create an ISpVoice object, you only need to call the Speak method to generate speech output from some text data. In addition, the IspVoice interface also provides several methods for changing voice and synthesis properties such as speaking rate (SetRate), output volume (SetVolume) and changing the current speaking voice (SetVoice).

Special SAPI controls can also be inserted along with the input text to change real-time synthesis properties like voice, pitch, word emphasis, speaking rate and volume. This synthesis markup sapi.xsd, using standard XML format, is a simple but powerful way to customize the TTS speech, independent of the specific engine or voice currently in use.

The Speak method can operate either synchronously (return only when completely finished speaking) or asynchronously (return immediately and speak as a background process). When speaking asynchronously, real-time status information such as speaking state and current text location can polled using the GetStatus method. Also while speaking asynchronously, new text can be spoken by either immediately interrupting the current output (SPF_PURGEBEFORESPEAK), or by automatically appending the new text to the end of the current output.

You can download the SAPI SDK documentation here http://msdn.microsoft.com/en-us/library/ee413476(v=vs.85).aspx

Download SAPI:http://www.microsoft.com/download/en/details.aspx?id=10121

Here is a simple example to have it read a file back to you using the default voice:

v = ObjectOpen("Sapi.SpVoice")
rfile=FileOpen("speech.txt", "READ") 
While 1
readline=FileRead(rfile)
if readline == "*EOF*" then break
v.speak(readline)
EndWhile
Fileclose(rfile)
ObjectClose(v)
At the simplest, you can use:
v = ObjectOpen("Sapi.SpVoice")
v.speak("Do you want to play a game?")
ObjectClose(v)

Here is an example, using standard XML format, to customize the TTS speech, independent of the specific engine or voice currently in use.

;Open the SP voice object
v = ObjectOpen("Sapi.SpVoice")

;set a few variables
vol50tag = '<volume level="50">'  ;enclosed in single quotes as string has double quotes in it
vol100tag = '<volume level="100">'  
endvoltag = "</volume>"

;build strings and speak them
speaktext = "This is an example of using XML to control speech."
v.speak(speaktext)

speaktext = StrCat(vol50tag, "This text is spoken at volume level fifty.", endvoltag )
v.speak(speaktext, 8) ; provide the second parameter 8 to specify SVSFIsXML

speaktext = StrCat(vol100tag, "This text is spoken at volume level one hundred.", endvoltag )
V.Speak(speaktext, 8)

speaktext = '<pitch middle="10">This text is spoken at pitch ten.<pitch middle="-10">This text is spoken at pitch zero.</pitch></pitch>'
V.Speak(speaktext, 8)

speaktext = `Homer Simpson, Jack O'Neil, & Bill Meek often say, <rate speed="3"><emph> "Doh" </emph></rate>`
V.Speak(speaktext, 8)

;build todays date in the format of day/month/year
cdt=TimeYmdHms()
year = ItemExtract(1, cdt, ":")
month = ItemExtract(2, cdt, ":") 
day = ItemExtract(3, cdt, ":")
cd = StrCat(day, "/", month, "/", year)

;Show the date format being misunderstood
speaktext = "The test date is said as 01/02/2002 with the format of day, month, year."
V.Speak(speaktext, 8)

;use the context id to correctly speak the date
speaktext = 'Using the context <spell>ID</spell>, the test date is correctly stated as <context id="date_dmy">01/02/2002</context>.'
V.Speak(speaktext, 8)

speaktext = StrCat('Todays date is <context id="date_dmy"> ', cd, ' </context>.')
V.Speak(speaktext, 8)

ObjectClose(v)
Exit

Article ID:   W15170
File Created: 2012:02:27:12:00:54
Last Updated: 2012:02:27:12:00:54