Object: SpVoice (Events)
AudioLevel Event
The AudioLevel event occurs when the text-to-speech (TTS) engine detects an audio level change while speaking a stream for the SpVoice object.
SpVoice.AudioLevel(
StreamNumber As Long,
StreamPosition As Variant,
AudioLevel As Long
)
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 audio level change occurs.
- AudioLevel
- The new audio level.
Example
The following Visual Basic form code demonstrates the use of the AudioLevel event. To run this code, create a form with the following controls:
Paste this code into the Declarations section of the form.
The Form_Load code creates an SpVoice object, adds AudioLevel to its event interests, and places sample text in Text1. The Command1_Click procedure speaks the text in Text1. The Word event code displays each word spoken. The AudioLevel event code converts each new audio level to a string of asterisks, effectively displaying the audio levels in a graph format.
Option Explicit
Public WithEvents vox As SpeechLib.SpVoice
Private Sub Command1_Click()
List1.Clear
vox.Speak Text1.Text, SVSFlagsAsync + SVSFIsXML
End Sub
Private Sub Form_Load()
' SVEAudioLevel not in default EventInterests -- must be added!
Set vox = New SpVoice
vox.EventInterests = vox.EventInterests Or SVEAudioLevel
Text1.Text = "audio levels change often"
End Sub
Private Sub vox_AudioLevel(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, _
ByVal AudioLevel As Long)
List1.AddItem String(AudioLevel, "*") 'AudioLevel value sets length of string
End Sub
Private Sub vox_Word(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, _
ByVal CharacterPosition As Long, ByVal Length As Long)
List1.AddItem Mid(Text1.Text, CharacterPosition + 1, Length)
End Sub