Interface: ISpeechRecoResult
SpeakAudio Method
The SpeakAudio method plays the audio sequence containing the recognized phrase.
The audio portion of the recognition is not automatically available. By default, the recognition context does not retain audio. Call RetainedAudio and set it to SRAORetainAudio to retain the audio. Although 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.
SpeakAudio combines two other methods. The first, ISpeechRecoResult.Audio, which retrieves the audio. The second call is SpVoice.SpeakStream, which plays it back.
ISpeechRecoResult.SpeakAudio(
[StartElement As Long = 0],
[Elements As Long = -1],
[Flags As SpeechVoiceSpeakFlags = SVSFDefault]
) As Long
Parameters
- StartElement
- [Optional] Specifies the starting element. The default value is zero, indicating that the first element is used.
- Elements
- [Optional] Specifies the number of elements to speak. Default value is -1, indicating that all elements are to be played.
- Flags
- [Optional] Specifies the Flags. Default value is SVSFDefault indicating that no special speak restrictions are imposed.
Return Value
The SpeakAudio method returns a Long variable indicating the stream number.
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.
Also see ISpeechRecoContext.RetainedAudio for an additional code sample.
Example
The following code snippet assumes a valid RecoResult and that RetainedAudio is set for the current recognizer. The first sample plays back the entire recognized phrase.
RecoResult.SpeakAudio
The next example demonstrates SpeakAudio speaking every other word in the phrase and skipping the others. The code also shows support for RetainedAudio in the current recognizer.
Dim WithEvents RecoResult As SpSharedRecoContext
Dim theCount, i As Long
Set RecoResult = New SpSharedRecoContext
RecoResult.RetainedAudio = SRAORetainAudio
'Rest of the code to process recognition goes here
'Get the number of phrase elements (words in the phrase) and
'step through every other one.
theCount = RecoResult.PhraseInfo.Elements.Count
For i = 0 To theCount - 1 Step 2
streamNumber = RecoResult.SpeakAudio(i, 1, SVSFDefault)
Next i