SpObjectTokenCategory SetId Method (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Object: SpObjectTokenCategory

SetId Method

The SetId method sets the ID of the SpObjectTokenCategory object.

The ID of the object is the path to its folder within the Speech configuration database.

An SpObjectTokenCategory object is created with its Id property in an uninitialized state; attempting to reference the Id of a new SpObjectTokenCategory object will result in an SPERR_UNINITIALIZED error. An SpObjectTokenCategory object in this state is not associated with any of the seven SAPI object token categories.

The SpeechStringConstants module contains constants that specify the paths of SAPI's object token categories within the configuration database. The SetId method typically sets one of those constants as the category object's Id property. This has the effect of setting the object to one of the SAPI object token categories.

This table shows the SpeechStringConstants constant for each of the seven object token categories:

Object Token Category SpeechStringConstants member
Voices SpeechCategoryVoices
Recognizers SpeechCategoryRecognizers
AppLexicons SpeechCategoryAppLexicons
AudioInput SpeechCategoryAudioIn
AudioOutput SpeechCategoryAudioOut
PhoneConverters SpeechCategoryPhoneConverters
Recoprofiles SpeechCategoryRecoProfiles
SpObjectTokenCategory.SetId(
     Id As String,
     [CreateIfNotExist As Boolean = False]
)

Parameters

Id
Specifies the Id, usually with a member of SpeechStringConstants.
CreateIfNotExist
[Optional] Specifies creating the token. If True, an entry is created if one does not already exist. By default the value is False and no file is created.

Return Value

None.


Example

The following Visual Basic form code demonstrates the use of the SetId method. 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 Command1 procedure creates a new SpObjectTokenCategory object, generates an error by attempting to reference the Id property of the uninitialized object, and then performs a SetId call which assigns the object to the category of TTS voices. The code then displays the token category's default token, which is the default TTS voice, and finally demonstrates the error which occurs from attempting to perform a second SetId on the SpObjectTokenCategory object.


Option Explicit

Dim C As SpeechLib.SpObjectTokenCategory

Const SPERR_UNINITIALIZED = &H80045001;
Const SPERR_ALREADY_INITIALIZED = &H80045002;

Private Sub Command1_Click()
    On Error Resume Next

    'Uninitialized object
    List1.AddItem "New SpObjectTokenCategory object:"
    Set C = New SpObjectTokenCategory
    If Err = 0 Then
        List1.AddItem "   SUCCEEDED"
    End If

    'Show the Id of a new object
    List1.AddItem "Id of New SpObjectTokenCategory object:"
    List1.AddItem C.Id
    If Err.Number = SPERR_UNINITIALIZED Then
        List1.AddItem "   SPERR_UNINITIALIZED"
        Err.Clear
    End If

    'Show the SpeechCategoryVoices constant
    List1.AddItem "SpeechCategoryVoices constant:"
    List1.AddItem "   " & SpeechCategoryVoices

    'Perform the SetId, which assigns it to the Voices category
    List1.AddItem "Perform SetId on New SpObjectTokenCategory object:"
    C.SetId SpeechCategoryVoices
    List1.AddItem "   " & C.Id

    'Show the default item of the new category
    List1.AddItem "Show SpObjectTokenCategory's default item:"
    List1.AddItem "   " & C.Default

    'Show error on second SetId
    List1.AddItem "Try a second SetId on SpObjectTokenCategory object:"
    C.SetId SpeechCategoryRecognizers
    If Err.Number = SPERR_ALREADY_INITIALIZED Then
        List1.AddItem "   SPERR_ALREADY_INITIALIZED"
        Err.Clear
    End If

End Sub