ISpeechRecoResult Audio Method

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoResult

Audio Method

The Audio method creates an audio stream from the audio data in the result object.

The resulting stream can be used as input for SPVoice.SpeakStream. However, a single call to ISpeechRecoResults.SpeakAudio performs the same action of speaking the recognized result.

The audio portion of the recognition is not automatically available. By default, the recognition context does not retain audio. To retain it, call the RetainedAudio property and set it to SRAORetainAudio. While RetainedAudio can be toggled at anytime, audio for a specific phrase must be retained before recognition attempts begin. Therefore, RetainedAudio must be called before the phrase is spoken.


ISpeechRecoResult.Audio(
     [StartElement As Long = 0],
     [Elements As Long = -1]
) As ISpeechBaseStream

Parameters

StartElement
[Optional] Specifies the starting element. The default value is zero, indicating the first element is used.
Elements
[Optional] Specifies the number of elements to speak. Default value is -1, indicating all elements are to be played.

Return Value

The Audio method returns an ISpeechBaseStream stream.

Remarks

Even if there are no elements, that is, StartElement = 0 and Elements = 0, the audio will still be played. Unrecognized results not having elements will still have audio.

Example

The following code snippet assumes a valid RecoResult. The stream is returned and passed to SPVoice.SpeakStream to hear. The code also shows support for RetainedAudio in the current recognizer. As a note, the voice object is created using a late binding method.

Dim WithEvents RecoResult As SpSharedRecoContext
Set RecoResult = New SpSharedRecoContext
RecoResult.RetainedAudio = SRAORetainAudio

'Demonstrates retrieving the RetainedAudio value
Dim audioOption As SpeechRetainedAudioOptions
audioOption = RecoResult.RetainedAudio

'Rest of the code to process recognition goes here
...

'Gets the stream to speak
Dim stream As ISpeechBaseStream
Set stream = RecoResult.Audio
    
'Creates the voice
Dim Voice As SpVoice
Set Voice = CreateObject("SAPI.SpVoice")
Voice.SpeakStream stream