ISpeechPhraseProperty Name Property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechPhraseProperty

Name Property


The Name property returns the name of the semantic property.

The Name is the name of the semantic property from the command and control grammar. This property must be explicitly marked with the PROPNAME label. This is often associated with an ISpeechPhraseProperty.ID which is a numeric identifier and is assigned by the PROPID label.


Syntax

Set: (This property is read-only)
Get: String = ISpeechPhraseProperty.Name

Parts

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

Remarks

Either Name or Id (if available) may be used to identify the rule invoked. Some languages, such as Visual Basic, can use strings in a Case Select statement. Therefore, the rule Name may be used directly in the Case Select statement. Other languages, such as C/C++ can only use numeric values in switch statements. In this case, the Id is more appropriate.

Example

The following code demonstrates getting the Name and Id property from a command and control recognition.

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 Form_Load procedure creates and activates a command and control 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 displays the recognized text in Label1. Label2 displays the additional information about the grammar properties. In this case, the rules would be "color" and "rank" along with their numeric values.

    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
            
            'Property name used
            Label2.Caption = Label2.Caption & _
                "Property Name: " & Result.PhraseInfo.Properties.Item(i).Name
                
             'Property Id used
            Label2.Caption = Label2.Caption & _
                " (" & Result.PhraseInfo.Properties.Item(i).Id & ")"
                
            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