Share via


ISpeechPhraseProperty Value Property (SAPI 5.4)

Microsoft Speech API 5.4

Interface: ISpeechPhraseProperty

Value Property

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.

Syntax

Set: (This property is read-only)
Get: Variant = ISpeechPhraseProperty.Value

Parts

  • ISpeechPhraseProperty
    The owning object.
  • Variant
    Set: (This property is read-only)
    Get: A Variant variable that gets the property.

Example

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:

  • Two labels called Label1 and Label2

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()
    On Error GoTo EH
    Set RC = New SpSharedRecoContext

    Set myGrammar = RC.CreateGrammar
    myGrammar.CmdLoadFromFile "C:\Program Files\Microsoft Speech SDK 5.4\Samples\Common\sol.xml", SLODynamic
    myGrammar.CmdSetRuleIdState 0, SGDSActive

EH:
    If Err.Number Then ShowErrMsg
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

    On Error GoTo EH

    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

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Const NL = vbNewLine
    Dim T As String

    T = "Desc: " & Err.Description & NL
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"
    End

End Sub