SpeechRecognizer Recognizer Property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecognizer

Recognizer Property


The Recognizer property specifies characteristics about the active recognizer.

Recognizers and the attributes associated with them are stored in the speech configuration database as a series of tokens, with each token representing one attribute. Recognizer retrieves an object (SpObjectToken) which is capable of accessing the attributes for the recognizer. Additional or more detailed information about the tokens is available in methods associated with SpObjectToken.

See Object Tokens and Registry Settings White Paper for a list of SAPI 5-defined engine attributes.


Syntax

Set: SpeechRecognizer.Recognizer = SpObjectToken
Get: SpObjectToken = SpeechRecognizer.Recognizer

Parts

SpeechRecognizer
The owning object.
SpObjectToken
Set: An SpObjectToken variable that sets the property.
Get: An SpObjectToken variable that gets the property.

Example

This code sample demonstrates the Recognizer property. After creating an instance for a recognizer, the Recognizer property can retrieve attribute information about the active recognizer. The engine ID is displayed. Also two attributes are attempted to be displayed. The first is "SpeakingStyle" (an attribute for the SAPI 5 SR engine. The other is "MyEngineAttribute," and should not be present. Tokens not found will cause a run-time error and as a result, require the error handling code.

To run this code, create a form with the following control:

  • A label called Label1
  • Paste this code into the Declarations section of the form.

    The Form_Load procedure creates the recognizer.

    Public WithEvents RC As SpSharedRecoContext
    Public myGrammar As ISpeechRecoGrammar
    
    Private Sub Form_Load()
        On Error GoTo TokenNotFound
        Set RC = New SpSharedRecoContext
        
        Set myGrammar = RC.CreateGrammar
        myGrammar.DictationSetState SGDSActive
        
        Label1.Caption = RC.Recognizer.Recognizer.Id & vbCrLf
        
        Dim objectToken As SpObjectToken
        Set objectToken = RC.Recognizer.Recognizer
        
        Dim tokenName As String
        tokenName = "SpeakingStyle"
        Label1.Caption = Label1.Caption & tokenName & " : " & objectToken.GetAttribute(tokenName) & vbCrLf
        
        tokenName = "MyEngineAttribute"
        Label1.Caption = Label1.Caption & tokenName & " : " & objectToken.GetAttribute(tokenName) & vbCrLf
        Exit Sub
        
    TokenNotFound:
        Label1.Caption = Label1.Caption & tokenName & " : " & "Token not found"
    End Sub