You are reading help file online using chmlib.com
|
Interface: ISpeechPhraseProperty
The Value property returns the value of the semantic property.
The Value property is the value of a semantic property set in either the VAL or VALSTR attributes in the grammar. Each terminal node can have a value associated with it assigned by the VAL (for numeric values) or VALSTR (for string) attributes. This value may be used for processing the rule.
For instance, in the sol.xml grammar for the card game solitaire used in the example below, the actual rank of the card (e.g., ace, five, king) is the terminal node since no other word or phrase is needed to complete the rule for rank. Each word as an associated value to assist with processing the rule. In the case of card rank, ace is assigned 1, two is assigned 2, and so on, through the king which is assigned a value of 13. Additionally, a common alternate for king is included as emperor which also has a value of 13.
Set: | (This property is read-only) |
Get: | Variant = ISpeechPhraseProperty.Value |
The following code demonstrates retrieving the value property from a command and control recognition. The application displays the recognized text and also makes a subjective statement about the worth of the card played based on rank. A low card (which includes the ace in this solitaire game), displays "You played a low card," for instance.
To run this code, create a form with the following controls:
Paste this code into the Declarations section of the form.
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.
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 As Long
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
If Result.PhraseInfo.Properties.Item(i).Name = "rank" Then
Select Case Result.PhraseInfo.Properties.Item(i).Value
Case Is < 5
Label2.Caption = "You played a low card"
Case Is < 9
Label2.Caption = "You played a mediocre card"
Case Else
Label2.Caption = "You played a good card"
End Select
End If
Next
End Sub
You are reading help file online using chmlib.com
|