You are reading help file online using chmlib.com
|
Interface: ISpeechRecognizer
The State property returns the current state of the recognition engine.
The recognition engine may be in one of several states of audio processing. If active, the engine receives audio data and processes it. Likewise, if inactive, neither audio data nor additional processing takes place. See the enumeration SpeechRecognizerState for complete details of the states.
Set: | SpeechRecognizer.State = SpeechRecognizerState |
Get: | SpeechRecognizerState = SpeechRecognizer.State |
This code sample demonstrates the State method. After creating an instance for a recognizer, State retrieves the processing state about the recognizer. The recognizer may be turned on and off with the button and the current state will be displayed afterward. Speech will be recognized and displayed but only when the engine is active.
To run this code, create a form with the following controls:
Paste this code into the Declarations section of the form.
The Form_Load procedure creates the recognizer. Click the button to toggle the engine on and off. Speaking while the engine is active will display the text in the second label.
Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar
Private Sub Command1_Click()
If Label1.Caption = 1 Then
RC.Recognizer.State = SRSInactive
Else
RC.Recognizer.State = SRSActive
End If
ShowState
RenameButton
End Sub
Private Sub Form_Load()
Set RC = New SpSharedRecoContext
Set myGrammar = RC.CreateGrammar
myGrammar.DictationSetState SGDSActive
Dim recoState As SpeechRecognizerState
recoState = RC.Recognizer.State
ShowState
RenameButton
End Sub
Private Function RenameButton()
If Label1.Caption = 1 Then
Command1.Caption = "Turn Off Engine"
Else
Command1.Caption = "Turn On Engine"
End If
End Function
Private Function ShowState()
Dim engineState As SpeechRecognizerState
Label1.Caption = RC.Recognizer.State
End Function
Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
Label2.Caption = Result.PhraseInfo.GetText
End Sub
You are reading help file online using chmlib.com
|