SpeechRecognizer AudioInputStream Property (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

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.


Option Explicit

Private Sub Form_Load()
    On Error GoTo EH

    Const NL = vbNewLine
    Dim Buffer As Variant
    Dim FileName As String
    Dim FileStream As ISpeechFileStream
    Dim InProcRecoContext As SpInProcRecoContext
    Dim InProcRecognizer As SpInprocRecognizer

    Dim NumBytes As Variant
    Dim T As String

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

    FileName = "C:\Program Files\Microsoft Speech SDK 5.4\Samples\"
    FileName = FileName & "CPP\Engines\TTS\MkVoice\selected.wav"
    Set FileStream = CreateObject("SAPI.SpFileStream")
    FileStream.Open FileName

    Set InProcRecognizer.AudioInputStream = FileStream
    NumBytes = InProcRecognizer.AudioInputStream.Read(Buffer, 100)
    T = "The first 100 bytes of recognizer's audio input stream are--"
    T = T & NL & NL & Buffer
    MsgBox T, vbInformation
    End

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