SpVoice AudioOutputStream property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Object: SpVoice

AudioOutputStream Property


The AudioOutputStream property gets and sets the current audio stream object used by the voice.

Setting the voice's AudioOutputStream property may cause its audio output format to be automatically changed to match the text-to-speech (TTS) engine's preferred audio output format. If the voice's AllowAudioOutputFormatChangesOnNextSet property is True, the format change takes place; if False, the format remains unchanged. In order to set the AudioOutputStream property of a voice to a specific format, its AllowOutputFormatChangesOnNextSet should be False.


Syntax

Set: SpVoice.AudioOutputStream = ISpeechBaseStream
Get: ISpeechBaseStream = SpVoice.AudioOutputStream

Parts

SpVoice
The owning object.
ISpeechBaseStream
Get: An ISpeechBaseStream object that gets the current audio output stream.
Set: An ISpeechBaseStream object that sets the audio output stream.

Remarks

Voice status and voice events are closely associated with the status of the audio output device. A voice speaking to a file stream produces no audio output, generates no events, and has no audio output status. As a result, the ISpeechVoiceStatus data returned by that voice will always indicate that it is inactive.


Example

The following Visual Basic form code demonstrates the use of the AudioOutputStream property. To run this code, create a form with the following controls:

  • A textbox called Text1
  • Two command buttons called Command1 and Command2
  • Paste the this code into the Declarations section of the form.

    The Command1_Click procedure sets the AudioOutputStream property of the voice to a file called AudioOutputStream.wav and speaks the contents of the text box into a wave file. It then sets the voice's AudioOutputStream property to Nothing, so that subsequent voice output will be directed to the audio system rather than to a file.

    The Command2_Click procedure plays back the wave file that created by the Command1_Click procedure.


    Option Explicit
    
    Dim objVOICE As SpeechLib.SpVoice
    Dim objFSTRM As SpeechLib.SpFileStream
    
    Const strFName = "C:\AudioOutputStream.wav"
    
    Private Sub Command1_Click()
    
        'Build a local file path and open it as a stream
        Call objFSTRM.Open(strFName, SSFMCreateForWrite, False)
        
        'Set voice AudioOutputStream to the stream and speak
        Set objVOICE.AudioOutputStream = objFSTRM
        objVOICE.Speak Text1.Text
        
        'Close the stream and set voice back to speaking
        Call objFSTRM.Close
        Set objVOICE.AudioOutputStream = Nothing
        
        Command2.Enabled = True
    
    End Sub
    
    Private Sub Command2_Click()
        objVOICE.Speak Text1.Text, SVSFIsXML
    End Sub
    
    Private Sub Form_Load()
        Set objVOICE = New SpVoice
        Set objFSTRM = New SpFileStream
        Command2.Enabled = False    'Force create file before playback
        Text1.Text = "The TTS voice will speak this text into a file."
    End Sub