|
|
Speaking Some TextIn the etTTSSimple and etTextToSpeech sample programs, you can type text into the text memo box and it will be spoken out your sound card or over an active call via your telephony device. In the previous pages we have done all the setup for selecting our audio format and routing it to the proper audio device, so in this chapter we will focus on actually using text to speech to speak written text and showing you how to control how the speech sounds. To speak text, you can use just one line of code: In VB... SpVoice1.Speak "Buy TeleTools now!" iSpeechFlags In Delphi... SpVoice1.Speak("Buy TeleTools now!", iSpeechFlags) Setting Speech FlagsAs a matter of fact, without all of the previous code, if you typed typed this one line of code, it would say the line of text over your sound card. You would need to do one thing though and that is to define iSpeechFlags which is an integer variable that contains the constants that control how the speech stream is sent. Here are your options:
I like to speak asynchronously so that my program is free to do other things while the speech is played and I can respond to speech events to tell me about it's status. I also like to make sure that any text in the speech buffer is purged when I go to speak again, and to be able to use XML tags to control how the text is spoken. Since these are bitflags, you can combine them like this: In VB... Dim iSpeechFlags As Integer In Delphi... var You sometimes see people use "+" to combine the bitflags which will work in this case where bitflags have only one bit set in them and are unique, but technically the logical or is the proper method. We use the "or" operator to logically or all the bitflags together so that each individual bit that is set with each constant is maintained. If you remember your high school logic course in math, if you or 00000001 with 00000010, you get 00000011. The flags in position 7 and 8 are switched on and will control your speech accordingly. Using XML to Control Text To SpeechXML, which stands for eXtensible Markup Language offers a lot of flexibility to control how your text is spoken. What if trying to say "ExceleTel" sounds like cursing in a bad French accent? Or what if you want the accented syllable in "umbrella" to be where you want it? You can do that and more with XML. Here is the text from our etTextToSpeech Sample program. Notice all the XML tags. <EMPH>Hello</EMPH><PRON SYM="f eh l ow">Fellow</PRON>developers. I can As you read through this notice that we are using the following tags:
There are even more, but we will leave that up to you to look through
the SAPI 5.1 SDK documentation to find all the others. Using these
XML tags you can almost completely control the inflections and pronunciations
in your spoken text.
|
|
|
|
||||
|
||||