ExceleTel Header Logo

 

menu_end_leftmenu_homemenu_aboutmenu_productsmenu_salesmenu_supportmenu_searchmenu_end_right

 

Selecting the Audio Output Device

The 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
Dim SOTokenDevices As ISpechObjectToken
Dim SOTokenDevices As ISpeechObjectTokens

and in Delphi...

Var
  SOTokenDevice: ISpeechObjectToken;
  SOTokenDevices: IspeechObjectTokens;

         (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.  

VB

Set 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
  ComboBoxWaveDevice.AddItem (SOTokenDevice.GetDescription)
Next

Delphi...

for i := 0 to SOTokenDevices.Count - 1 do
  begin
    SOTokenDevice := SOTokenDevices.Item(i);
    ComboBoxWaveDevice.Items.AddObject(SOTokenDevice.GetDescription(0), TObject(SOTokenDevice));
    SOTokenDevice._AddRef; // increment to make sure desc. not destroyed
end;

Changing the Audio Output Device

Now 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
    (ComboBoxWaveDevice.Items.Objects[ComboBoxWaveDevice.ItemIndex]));
SpVoice1.AudioOutput := SOTokenDevice;

NOTE: It is very important to note that changing the audio output device can also change the wave format since SAPI tries to match a wave format to the device.  Fortunately, we have a way to prevent this change.  You will see how to do this when we put all these pieces together in the following pages.

Creating the Audio Output Stream and Setting the Wave Format

We 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
' The format Type is associated with the selected list item as a long.
SpVoice1.AudioOutputStream.Format.Type = ComboBoxWaveFormats.ItemData(ComboBoxWavFormats.ListIndex)
' Currently you have to call this so that SAPI picks up the new format.
Set SpVoice1.AudioOutputStream = SpVoice1.AudioOutputStream

Delphi...


SpVoice1.AllowAudioOutputFormatChangesOnNextSet := False;
SpVoice1.AudioOutputStream.type_ :=
Integer(ComboBoxWaveFormats.Items.Objects[ComboBoxWaveFormats.ItemIndex]);
SpVoice1.AudioOutputStream := SpMMAudioOut1.DefaultInterface;

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

 

 About ] First Time Visit ] TAPI Made Easy ] What You Can Do ] Products ] How To Order ] Support ] Search ]
 Home ] Up ]


Copyright © 1997-2007 ExceleTel Inc. All rights reserved. Friday August 17, 2007 11:05:24 AM

Contact Us