You are reading help file online using chmlib.com
|
Interface: ISpeechPhraseProperty
The FirstElement property returns the offset of the first spoken element spanned by this property.
Set: | (This property is read-only) |
Get: | Long = ISpeechPhraseProperty.FirstElement |
The following code demonstrates retrieving the Name property from a command and control recognition.
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 and activates a dictation grammar. The grammar file sol.xml is the solitaire grammar provided with the SDK. The path listed is for a standard SDK install and may be changed as needed.
If "play the red five" has been recognized, the application will display the recognized text in label1. Label2 displays the names of the two properties used from the grammar along with the actual word or phrase which activated the rule. In this case, the rules would be "color=red" and "rank=five." The number of elements in the phrase matching the property is displayed in parenthesis. It is possible for more than one word to activate a rule for a property. In the case of sol.xml, only single words are used. However, if the file were changed, for example, so that the ColorRed definition becomes "red card" instead of just "red", then the expression "play the red card five" would display two elements for the property.
Option Explicit
Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar
Private Sub Form_Load()
Set RC = New SpSharedRecoContext
Set myGrammar = RC.CreateGrammar
myGrammar.CmdLoadFromFile "C:\Program Files\Microsoft Speech SDK 5.1\Samples\Common\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)
Beep
Label1.Caption = "(no recognition)"
Label2.Caption = ""
End Sub
Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
Dim i, j, theFirstElement, theNumberOfElements As Long
Dim theString As String
Label1.Caption = Result.PhraseInfo.GetText & vbCrLf
Label2.Caption = "Rule Properties Found : " & Result.PhraseInfo.Properties.Count & vbCrLf
For i = 0 To Result.PhraseInfo.Properties.Count - 1
Label2.Caption = Label2.Caption & _
"Rules Name: " & Result.PhraseInfo.Properties.Item(i).Name
theFirstElement = Result.PhraseInfo.Properties.Item(i).FirstElement
theNumberOfElements = Result.PhraseInfo.Properties.Item(i).NumberOfElements
theString = ""
For j = 0 To theNumberOfElements - 1
theString = theString & Result.PhraseInfo.Elements(theFirstElement + j).DisplayText
theString = theString & " "
Next
Label2.Caption = Label2.Caption & _
" = " & theString & " (" & theNumberOfElements & ")" & vbCrLf
Next
End Sub
You are reading help file online using chmlib.com
|