Share via


SpeechRecognizer GetFormat Method (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecognizer

GetFormat Method

The GetFormat method returns the current input audio format.

The sound format may be different at different times or at different points during processing. For example, the audio format at the time the input reaches the sound device (the audio card for instance) may differ from the audio format by the time it reaches the speech recognition (SR) engine. GetFormat specifies which location should be polled and returns the audio format for that location.

  
    SpeechRecognizer.GetFormat(
     Type As SpeechFormatType) As SpAudioFormat

Parameters

  • Type
    Request for the audio format at entering the sound device or SR engine.

Return Value

The GetFormat method returns an SpAudioFormat variable.

Example

This code example demonstrates the GetFormat method. After a successful recognition, two GetFormat calls poll SAPI for the audio formats of the sound device and the SR engine and display the results in a message box.

To run this code, create a form without any controls. Paste this code into the Declarations section of the form.

  
Option Explicit

Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar

Private Sub Form_Load()
    On Error GoTo EH

    Set RC = New SpSharedRecoContext
    Set myGrammar = RC.CreateGrammar
    myGrammar.DictationSetState SGDSActive
    RC.Recognizer.EmulateRecognition ("We the people")

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub RC_Recognition _
   (ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
    ByVal Result As SpeechLib.ISpeechRecoResult)

    On Error GoTo EH

    Const NL = vbNewLine
    Dim audioFormat As SpAudioFormat
    Dim T As String

    T = "Text recognized: " & Result.PhraseInfo.GetText & NL

    Set audioFormat = RC.Recognizer.GetFormat(SFTInput)
    T = T & "Audio input type: " & audioFormat.Type & NL

    Set audioFormat = RC.Recognizer.GetFormat(SFTSREngine)
    T = T & "SR engine input type: " & audioFormat.Type
    MsgBox T, vbInformation

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