SpVoice Voice property (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Object: SpVoice

Voice Property

The Voice property gets and sets the currently active member of the Voices collection.

The Voice property can be thought of as the person of a voice object; examples of Voices are "Microsoft Mary" and "Microsoft Mike." Use the GetVoices method to determine what voices are available.


Syntax

Set: SpVoice.Voice = SpObjectToken
Get: SpObjectToken = SpVoice.Voice

Parts

SpVoice
The owning object.
SpObjectToken
Set: An SpObjectToken object that sets the voice property.
Get: An SpObjectToken object that gets the current voice.

Remarks

If there is not a voice currently in use, this property will return the token for the default voice.

Example

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

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

Paste this code into the Declarations section of the form.

The Form_Load procedure creates a voice object, and displays the names of all available voices in the list box. Select a voice name in the list box and then click Command1; the Command1 procedure sets the voice object's Voice property to the selected name, and causes the voice to speak its new name.


Option Explicit

Private V As SpeechLib.SpVoice
Private T As SpeechLib.ISpeechObjectToken

Private Sub Command1_Click()

    If List1.ListIndex > -1 Then

        'Set voice object to voice name selected in list box
        'The new voice speaks its own name

        Set V.Voice = V.GetVoices().Item(List1.ListIndex)
        V.Speak V.Voice.GetDescription

    Else
        MsgBox "Please select a voice from the listbox"
    End If

End Sub

Private Sub Form_Load()
    Dim strVoice As String

    Set V = New SpVoice

    'Get each token in the collection returned by GetVoices
    For Each T In V.GetVoices
        strVoice = T.GetDescription     'The token's name
        List1.AddItem strVoice          'Add to listbox
    Next

End Sub