SpeechRecognizer Recognizer Property (SAPI 5.3)
Microsoft Speech API 5.3
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.
|Set:||SpeechRecognizer.Recognizer = SpObjectToken|
|Get:||SpObjectToken = SpeechRecognizer.Recognizer|
The owning object.
Set: An SpObjectToken variable that sets the property.
Get: An SpObjectToken variable that gets the property.
This code example 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 "VendorPreferred", an attribute that exists for the SAPI 5 SR engine. The other is "MyEngineAttribute", which should not be present. Tokens not found will cause a run-time error and as a result, require error handling code.
To run this code, create a form with no controls. Paste this code into the Declarations section of the form.
Option Explicit Private Sub Form_Load() On Error GoTo EH Const NL = vbNewLine Dim objectToken As SpObjectToken Dim RC As SpSharedRecoContext Dim T As String Dim TokenName As String Dim Value As String Set RC = New SpSharedRecoContext Set objectToken = RC.Recognizer.Recognizer T = "Id: " & RC.Recognizer.Recognizer.Id & NL TokenName = "VendorPreferred" Value = objectToken.GetAttribute(TokenName) If Len(Value) = 0 Then T = T & TokenName & " attribute's value: Zero-length string" & NL End If TokenName = "MyEngineAttribute" On Error Resume Next T = TokenName & " : " & objectToken.GetAttribute(TokenName) If Err.Number Then Err.Clear T = T & "There is no attribute named 'MyEngineAttribute'." End If 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