Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SpVoice VoiceChange event (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3

Object: SpVoice (Events)

VoiceChange Event


The VoiceChange event occurs when the text-to-speech (TTS) engine detects a change of voice while speaking a stream for the SpVoice object.


SpVoice.VoiceChange(
     StreamNumber As Long,
     StreamPosition As Variant,
     VoiceObjectToken As SpObjectToken
)

Parameters

StreamNumber
The stream number which generated the event. When a voice enqueues more than one stream by speaking asynchronously, the stream number is necessary to associate an event with the appropriate stream.
StreamPosition
The character position in the output stream at which the change of voice occurs.
VoiceObjectToken
The ObjectToken of the new voice.

Example

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

  • A command button called Command1
  • A text box called Text1

Paste this code into the Declarations section of the form.

The Form_Load code creates an SpVoice object. The Command1_Click procedure sets the object's Voice property to three different voices, and enqueues a short sentence in each voice. Each time the TTS engine speaks with a new Voice property, a VoiceChange event is raised. The VoiceChange event code displays the name of the new voice in Text1.


Option Explicit

Public WithEvents vox As SpeechLib.SpVoice
Const cstrText = "my voice just changed."

Private Sub Command1_Click()

    Set vox.voice = vox.GetVoices("name = microsoft mary").Item(0)
    vox.Speak cstrText, SVSFlagsAsync

    Set vox.voice = vox.GetVoices("name = microsoft mike").Item(0)
    vox.Speak cstrText, SVSFlagsAsync

    Set vox.voice = vox.GetVoices("name = microsoft sam").Item(0)
    vox.Speak cstrText, SVSFlagsAsync

End Sub

Private Sub Form_Load()

    Set vox = New SpVoice

End Sub

Private Sub vox_VoiceChange(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, _
                            ByVal VoiceObjectToken As SpeechLib.ISpeechObjectToken)

    Text1.Text = VoiceObjectToken.GetDescription

End Sub
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.