SpVoice AudioOutputStream property (SAPI 5.3)
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.
|Set:||SpVoice.AudioOutputStream = ISpeechBaseStream|
|Get:||ISpeechBaseStream = SpVoice.AudioOutputStream|
- The owning object.
Get: An ISpeechBaseStream object that gets the current audio output stream.
Set: An ISpeechBaseStream object that sets the audio output stream.
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.
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 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 Const strFName = "C:\AudioOutputStream.wav" Dim objVOICE As SpeechLib.SpVoice Dim objFSTRM As SpeechLib.SpFileStream Private Sub Form_Load() On Error GoTo EH 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." EH: If Err.Number Then ShowErrMsg End Sub Private Sub Command1_Click() On Error GoTo EH Const FName = "C:\ExCodeAudioOutputStream.wav" ' Build a local wav file path and open it as a stream. Call objFSTRM.Open(FName, SSFMCreateForWrite, False) ' Set voice AudioOutputStream to the stream and speak ' the contents of the text box into the new wave file: 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 EH: If Err.Number Then ShowErrMsg End Sub Private Sub Command2_Click() On Error GoTo EH objVOICE.Speak Text1.Text, SVSFIsXML EH: If Err.Number Then ShowErrMsg End Sub Private Sub ShowErrMsg() ' Declare identifiers: Dim T As String T = "Desc: " & Err.Description & vbNewLine T = T & "Err #: " & Err.Number MsgBox T, vbExclamation, "Run-Time Error" End End Sub