SpeechRecognizer GetRecognizers Method (SAPI 5.3)
Microsoft Speech API 5.3
Interface: ISpeechRecognizer
GetRecognizers Method
The GetRecognizers method returns a selection of SpeechRecognizer objects in the speech configuration database.
Recognizers are stored in the speech configuration database as a series of tokens, with each token representing one recognizer (also called a speech recognition engine). GetRecognizers retrieves all available recognizer tokens and returns the in a list as an ISpeechObjectTokens object. Additional or more detailed information about the tokens is available in methods associated with ISpeechObjectTokens. If no recognizers match the criteria, GetRecognizers returns an empty selection, that is, an ISpeechObjectTokens collection with an ISpeechObjectTokens::Count property of zero.
The recognizer token search may be further refined by using the RequiredAttributes and OptionalAttributes search attributes. Only token matching the specified search attributes are returned. If no search attributes are offered, all tokens are returned.
See Object Tokens and Registry Settings White Paper for a list of SAPI 5-defined attributes.
ISpeechRecognizer.GetRecognizers(
[RequiredAttributes As String = ""],
[OptionalAttributes As String = ""]
) As ISpeechObjectTokens
Parameters
- RequiredAttributes
[Optional] Specifies the RequiredAttributes. To be returned by GetRecognizers, recognizer tokens must contain all of the specific required attributes. If no recognizers match the selection, the selection returned will not contain any elements. By default no attributes are required and the method returns all the token discovered. - OptionalAttributes
[Optional] Specifies the OptionalAttributes. Returned tokens containing the RequiredAttributes are sorted by OptionalAttributes. If OptionalAttributes is specified, the tokens are listed with the OptionalAttributes first. By default, no attribute is specified and the list returned from the speech configuration database is in the order that attributes were discovered.
Return Value
A ISpeechObjectTokens collection containing tokens for the selected recognizers.
Remarks
The format of selection criteria may either be Value or "Attribute = Value". Values may be excluded by "Attribute != Value".
Example
This code example demonstrates the GetRecognizers method. After creating an instance for a recognizer, GetRecognizers polls the computer for available recognizer tokens, which represent individual engines. The results are displayed. Then the computer is repolled for recognizer tokens that are able to support telephony.
To run this code, create a form without any 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 i As Long
Dim recoObject As SpObjectToken
Dim SharedRecognizer As SpSharedRecognizer
Dim T As String
Dim theRecognizers As ISpeechObjectTokens
Set SharedRecognizer = CreateObject("SAPI.SpSharedRecognizer")
Set theRecognizers = SharedRecognizer.GetRecognizers
For i = 0 To theRecognizers.Count - 1
Set recoObject = theRecognizers.Item(i)
T = T & recoObject.GetDescription & NL
Next i
MsgBox T, vbInformation
T = ""
Set theRecognizers = SharedRecognizer.GetRecognizers("Telephony")
For i = 0 To theRecognizers.Count - 1
Set recoObject = theRecognizers.Item(i)
T = T & recoObject.GetDescription & NL
Next i
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