|
|
Selecting the Audio Output DeviceThe first method of finding and selecting our audio output device involves using the SAPI tokens ISpeechObjectToken and ISpeechObjectTokens and the SpVoice object. Using methods built into SAPI you can create your own Speech object variables of the token types like this: In VB...Dim WithEvents Voice1 As SpVoice and in Delphi...Var (we don't need to define the voice object since in Delphi it's a visual component!) Then we can use methods built into the SpVoice object to get a list of Audio Output devices out of the registry and put them into our variables. VBSet Sp Voice1 = New SpVoice 'create the voice
object Delphi......since you have an SpVoice component you can just drop it on a form and name it SpVoice1, then get our tokens like this: SOTokenDevices := SpVoice1.GetAudioOutputs('',''); Here you can see that one of the methods of SpVoice is GetAudioOutputs. This one line puts all of the enumerated audio outputs into SOTokenDevices. If we want to fill a combobox with all of the devices, we could do it like this: VB... For Each SOTokenDevice In
SpVoice1.GetAudioOutputs Delphi... for i := 0 to SOTokenDevices.Count - 1 do Changing the Audio Output DeviceNow all that's left is to change the audio output device to the one selected in the combobox. Once again we can just use the methods built into the SpVoice object: VB...Set SpVoice1.AudioOutput = SpVoice1.GetAudioOutputs().Item(ComboBoxWaveDevice.ListIndex) Delphi...SOTokenDevice:=ISpeechObjectToken(Pointer
Creating the Audio Output Stream and Setting the Wave FormatWe have our audio output formats available and a list of output devices, now we have to create an AudioOutputStream object and associate it with both of these in order to be able to send our text-to-speech as a stream of wave data. Notice that here we use a hidden property "AllowAudioOutputFormatChangesOnNextSet" to make sure that the format we select is not changed when change the device. VB...SpVoice1.AllowAudioOutputFormatChangesOnNextSet = False Delphi...
But can't this be simpler, you ask? Yes it can. This Tutorial shows both how to use SAPI to accomplish TTS without TeleTools and how to make it even easier if you have TeleTools. Keep reading to the end where we will provide source code and sample programs that show exactly how to do Text To Speech with even easier code with TeleTools. Wow, we are almost there. We've learned about wave formats and
selected the one we want, we have learned about audio output devices and
selected that too, and we have created an audio stream to route our audio,
now all that we need to do is speak something! Click below to
continue to the next page where we will type some text and use Text To
Speech to speak it. Continue to Page 4 |
|
|
|
||||
|
||||