SpeechRecognizer AudioInputStream Property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecognizer

AudioInputStream Property


The AudioInputStream property gets and sets the recognizer's audio input stream.

Using the AudioInputStream enables an application to use file streams or other stream objects for input rather than audio devices.

AudioInputStream is used with InProc recognizers only. Attempting to use it in a shared environment will result in an SPERR_NOT_SUPPORTED_FOR_SHARED_RECOGNIZER error.

Syntax

Set: SpeechRecognizer.AudioInputStream = ISpeechBaseStream
Get: ISpeechBaseStream = SpeechRecognizer.AudioInputStream

Parts

SpeechRecognizer
The owning object.
ISpeechBaseStream
Set: An ISpeechBaseStream variable that sets the property. If no value is stated, the default of Nothing will be passed in.
Get: An ISpeechBaseStream variable that gets the property.

Example

The following Visual Basic form code demonstrates the use of AudioInputStream. The application gets a wav file and uses that as the input source.

To run this code, create a form without any controls. The file is found in the SAPI 5.1 SDK and is a small, one word file. The location is assumed to be on the C: drive, although the string may be changed to accommodate other locations.

Dim WithEvents InProcRecoContext As SpInProcRecoContext
Dim InProcRecognizer As Object

Private Sub Form_Load()
    Set InProcRecognizer = CreateObject("SAPI.SpInprocRecognizer")
    Set InProcRecoContext = InProcRecognizer.CreateRecoContext

    Dim FileName As String
    FileName = "C:\Program Files\Microsoft Speech SDK 5.1\Samples\CPP\Engines\TTS\MkVoice\selected.wav"
    Dim FileStream As ISpeechFileStream
    Set FileStream = CreateObject("SAPI.SpFileStream")
    FileStream.Open FileName
    
    Set InProcRecognizer.AudioInputStream = FileStream
End Sub