Interface: ISpeechRecognizer
GetAudioInputs Method
The GetAudioInputs method returns a selection of the available audio input devices.
Audio input devices (sound cards, for example) are stored in the speech configuration database as a series of tokens, with each token representing one audio input device. GetAudioInputs retrieves all available audio tokens. The returned list is an ISpeechObjectTokens object. Additional or more detailed information about the tokens is available in methods associated with ISpeechObjectTokens.
The token search may be further refined using the RequiredAttributes and OptionalAttributes search attributes. Only tokens matching the specified RequiredAttributes search attributes are returned. Of those tokens matching the RequiredAttributes key, OptionalAttributes lists devices in the order matching OptionalAttributes. If no search attributes are offered, all tokens are returned. If no audio devices match the criteria, GetAudioInputs returns an empty selection, that is, an ISpeechObjectTokens collection with an ISpeechObjectTokens::Count property of zero.
See Object Tokens and Registry Settings White Paper for a list of SAPI 5-defined attributes.
SpeechRecognizer.GetAudioInputs(
[RequiredAttributes As String = ""],
[OptionalAttributes As String = ""]
) As ISpeechObjectTokens
Parameters
- RequiredAttributes
- [Optional] Specifies the RequiredAttributes. To be returned by GetAudioInputs, audio input tokens must contain all of the specific required attributes. If no profiles match the selection, the selection returned will not contain any elements. By default, no attributes are required and so returns all the tokens 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
An ISpeechObjectTokens collection containing the selected audio input tokens.
Remarks
The format of selection criteria may either be Value or "Attribute = Value". Values may be excluded by "Attribute != Value".
Example
This code sample demonstrates the GetAudioInputs method. After creating an instance for a recognizer, GetAudioInputs polls the computer for available audio input tokens and displays the results.
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 SharedRecognizer As SpSharedRecognizer
Dim T As String
Dim theRecognizers As ISpeechObjectTokens
Dim tokenObject As SpObjectToken
Set SharedRecognizer = CreateObject("SAPI.SpSharedRecognizer")
Set theRecognizers = SharedRecognizer.GetAudioInputs
For i = 0 To theRecognizers.Count - 1
Set tokenObject = theRecognizers.Item(i)
T = T & tokenObject.GetDescription & NL
Next i
T = "Available audio input devices--" & NL & NL & T
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