You are reading help file online using chmlib.com
|
Interface: ISpeechRecoContext Events
The RecognitionForOtherContext event occurs when the recognition context encounters a recognition result that belongs to another recognition context.
A RecognitionForOtherContext event indicates a successful recognition but that another application currently running claims it. This is a useful event if multiple shared instances are running at the same time. If the owning application cannot use or claim the recognition, the recognition event is sent to another context that can claim it. In that case, the recognition context claiming it receives the Recognition event and all other contexts receive a RecognitionForOtherContext event.
This event is more applicable to command and control grammars than to dictation. For example, the current recognition context returns a recognition result such as "file." If that recognition context does not have the word "file" in its active grammar, the speech recognition engine searches all the other open and active grammars, even if they belong to other applications. If another context has the word "file" available, the recognition event is sent there instead.
If other recognition contexts should not receive recognition events, because the window or application is not the current one for example, change state of those contexts using ISpeechRecoContext.State.
SpeechRecoContext.RecognitionForOtherContext(
StreamNumber As Long,
StreamPosition As Variant
)
There are three possible results from a recognition attempt:
The following Visual Basic form code demonstrates the use of the RecognitionForOtherContext event. The application displays the text of a successful recognition or indicates that the recognition belongs to another application.
The setup for this scenario is somewhat complex. To duplicate two applications running command and control instances, the following code must be compiled into two different applications. Create a form with the following controls:
Paste this code into the Declarations section of the form.
The Form_Load procedure creates and activates a dictation grammar. Create the grammar file sol.xml and use the XML code from the RecoCC sample application. The second application should open sol2.xml. This will be the only modification.
The xml files have only one phrase each that can be recognized. Run both applications. Now speak, "new game." The first application gets the recognition while the second application displays "For another context." Now speak "file game" and the situation reverses. These applications will assign and display commands properly regardless of the front-most application.
Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar
Private Sub Form_Load()
Set RC = New SpSharedRecoContext
Set myGrammar = RC.CreateGrammar
myGrammar.CmdLoadFromFile "sol.xml", SLODynamic
myGrammar.CmdSetRuleIdState 0, SGDSActive
End Sub
Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
Label1.Caption = Result.PhraseInfo.GetText
Label4.Caption = ""
End Sub
Private Sub RC_RecognitionForOtherContext(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
Label4.Caption = "For another context"
Label1.Caption = ""
End Sub
You are reading help file online using chmlib.com
|