Share via


SpObjectToken MatchesAttributes Method (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpObjectToken

MatchesAttributes Method

The MatchesAttributes method indicates whether the token matches specified attributes.

  
    SpObjectToken.MatchesAttributes(
     Attributes As String
) As Boolean

Parameters

  • Attributes
    Specifies the Attributes.

Return Value

A Boolean variable. If True, the token matches the specified attributes; if False, it does not match.

Example

The following Visual Basic form code demonstrates the use of the MatchesAttibutes method. To run this code, create a form with the following controls:

  • A combo box control called Combo1
  • A command button called Command1
  • A list box called List1

Paste this code into the Declarations section of the form.

The Form_Load procedure initializes a new SpObjectTokenCategory object to the voices category, selects all voices into an ISpeechObjectTokens collection, and loads Combo1 with several attribute declarations. These attributes are intentionally irregular with regard to capitalization, spacing, and spelling.

The Command1 procedure contains a loop that performs a MatchesAttibutes call on each available voice. The name of each voice and the Boolean result of the MatchesAttibutes method is displayed in the list box.

  
Option Explicit

Dim C As SpeechLib.SpObjectTokenCategory
Dim E As SpeechLib.ISpeechObjectTokens
Dim T As SpeechLib.SpObjectToken

Private Sub Form_Load()
    On Error GoTo EH

    With Combo1
        .AddItem "vendor=microsoft"
        .AddItem "gender=female"
        .AddItem "Gender = Male"
        .AddItem "gender!=male"
        .AddItem "name=Microsoft sam"
        .AddItem "Name != microsoft Sam"
        .AddItem "name=MICROSOFT SAM,gender=female"   'no possible matches
        .AddItem "gedner = male"          'no possible matches
        .ListIndex = 0
    End With

    Set C = New SpObjectTokenCategory   'create new token category object
    C.SetId SpeechCategoryVoices        'init ID of voices category
    Set E = C.EnumerateTokens()         'no parameters -- get all voices

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    Dim Vname, Vmatch

    List1.Clear
    List1.AddItem "Test for voices matching """ & Combo1.Text & """"
    List1.AddItem ""

    For Each T In E
        Vname = T.GetDescription
        Vmatch = T.MatchesAttributes(Combo1.Text)
        List1.AddItem "   " & Vname & "  " & Vmatch
    Next

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Dim T As String

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

End Sub