CHMlib Logo Leading Translation Management System for Translation Agencies, Top Translation Management Software for Freelance Translators, Time Tracking Software, Word Count, Character Count and Line Count Software, Computer Assisted Translation Tool for Easy Word Count, Clipboard Character Count Software, User-Friendly Translation Memory Software, Terminology Management Software, Terminology Management Server, Microsoft Glossary Software, Dictionary of Acronyms, Social Network for Translators and Translation Agencies, Acronyms and Abbreviations Search Engine, Russian Translation Lab, Ukrainian Translation Lab.
You are reading help file online using chmlib.com
CrisisHelper - First Aid in Tough Times of World Economic Crisis


Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

VB Application Sample: Command and Control Recognition

The following code sample represents a simple, but functional, recognition application. It uses a command and control grammar which limits the recognizable text to those listed in the configuration file. In this case, the file is named sol.xml and the file contents are listed in the second code box below. The text is restricted to the single command "new game."

The commented lines in the Visual Basic code refer to hypothetical labels in a form to possibly display information. If a speech attempt does not match the new game rule pattern, it could also display "(no recognition)". Of course you may modify this application as needed to fit your own requirements.

Before running the application, a speech reference must be included. Using the Project->References menu, find and select the Microsoft Speech Object Library.

Public WithEvents RC As SpSharedRecoContext
Public myGrammar, b 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_FalseRecognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)
    'Label1.Caption = "(no recognition)"
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
End Sub

Private Sub RC_StartStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    'Label2.Caption = Val(StreamNumber)
End Sub

In addition to copying the code to the Visual Basic project, copy the following XML code into a new file named sol.xml.

<GRAMMAR LANGID="409">
    <DEFINE>
	<ID NAME="RID_NewGame" VAL="101"/>
    </DEFINE>
	
   <RULE NAME="newgame" ID="RID_NewGame" TOPLEVEL="ACTIVE">
      <P>new +game</P>
   </RULE>
</GRAMMAR>

In cases when a second grammar file is needed, copy the following XML code into a new file named sol2.xml.

<GRAMMAR LANGID="409">
    <DEFINE>
	<ID NAME="RID_FileGame" VAL="200"/>
    </DEFINE>
	
   <RULE NAME="filegame" ID="RID_FileGame" TOPLEVEL="ACTIVE">
      <P>file +game</P>
   </RULE>
</GRAMMAR>


You are reading help file online using chmlib.com

If you want your help file to be removed or added please send e-mail to chmlibcom@gmail.com
Partner sites: Logo Design, Simple Anti-Crisis Accounting Software, Voice Search for Web