Share via


SpObjectToken Category Property (SAPI 5.4)

Microsoft Speech API 5.4

Object: SpObjectToken

Category Property

The Category property returns the category of the object token as an SpObjectTokenCategory object.

If the object token has not been initialized, an attempt to reference this property will generate an SPERR_UNINITIALIZED error.

Syntax

Set: (This property is read-only)
Get: SpObjectTokenCategory = SpObjectToken.Category

Parts

  • SpObjectToken
    The owning object.
  • SpObjectTokenCategory
    Set: (This property is read-only)
    Get: An SpObjectTokenCategory object returning the category.

Example

The following Visual Basic form code demonstrates the use of the SpObjectToken's Category and Id properties and its GetDescription method. It also demonstrates the handling of uninitialized object tokens. To run this code, create a form with the following controls:

  • A list box called List1
  • A command button called Command1

Paste this code into the Declarations section of the form.

The Form_Load procedure creates a voice object and a recognizer object. The Command1_Click procedure creates several object tokens and sends them to a subroutine which displays information about them in the list box. The first token sent is a newly-created token with no Category. The subroutine code generates an error when it tries to get the Category property of this token. The other tokens passed to the subroutine are properly initialized; for each of these tokens the subroutine displays the token's description, ID, and category ID.

  
Option Explicit

Const SPERR_UNINITIALIZED = &H80045001;
Dim T As SpeechLib.SpObjectToken
Dim C As SpeechLib.SpObjectTokenCategory
Dim V As SpeechLib.SpVoice
Dim R As SpeechLib.SpSharedRecognizer

Private Sub Form_Load()
    On Error GoTo EH

    ' Voice object furnishes Voice and AudioOutput tokens.
    ' Recognizer object furnishes Recognizer and AudioInput tokens.
    Set V = New SpVoice
    Set R = New SpSharedRecognizer

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    List1.Clear

    ' Create new token -- uninitialized:
    Set T = New SpObjectToken
    Call TokenInfo("new token", T)

    ' Voice object furnishes Voice and AudioOutput tokens:
    Set T = V.GetVoices().Item(0)
    Call TokenInfo("voice token", T)

    Set T = V.GetAudioOutputs().Item(0)
    Call TokenInfo("audioout token", T)

    ' Recognizer object furnishes recognizer and AudioInput tokens:
    Set T = R.GetRecognizers().Item(0)
    Call TokenInfo("recognizer token", T)

    Set T = R.GetAudioInputs().Item(0)
    Call TokenInfo("audioin token", T)

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub TokenInfo(text, token As SpObjectToken)
    On Error GoTo TokenInfo

    List1.AddItem text
    Set C = token.Category

TokenInfo:
    Select Case Err.Number
        Case 0
            List1.AddItem "  Token.GetDescription:"
            List1.AddItem "    " & token.GetDescription
            List1.AddItem "  Token.Category.Id:"
            List1.AddItem "    " & token.Category.Id
            List1.AddItem "  Token.Id:"
            List1.AddItem "    " & token.Id

        Case SPERR_UNINITIALIZED
            List1.AddItem "   SPERR_UNINITIALIZED"
    End Select

    List1.AddItem ""

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