One can let the SpeechSynthesizer speak text in an asynchronous way, for example like this:
Private WithEvents _Synth As New SpeechSynthesizer
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Enter Then
_Synth.SpeakAsync(New Prompt(Me.TextBox1.Text))
End If
End Sub
The events that SpeechSynthesizer
generates enables us to tell what the computer voice is just speaking.
For example, you may visualize the speech output by selecting the characters like this:
Private Sub _Synth_SpeakProgress(sender As Object, e As SpeakProgressEventArgs) Handles _Synth.SpeakProgress
Me.TextBox1.SelectionStart = e.CharacterPosition
Me.TextBox1.SelectionLength = e.CharacterCount
End Sub
However, when SpeakAsync
is called repeatedly (for example when we tell the SpeechSyntesizer
to speak the same text while it's currently just speaking), the speech requests are queued, and the SpeechSynthesizer
plays them one by one.
However, I haven't been able to find out which request the synthesizer is currently speaking. The SpeakProgressEventArgs
don't reveal this:
Using SAPI5, the events provided a StreamNumber
:
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.
Using this StreamNumber, you could always tell what the SpeechSynthesizer is just playing / speaking.
The System.Speech.Synthesis implementation is a modern version of the SAPI5 implementation.
However, I just don't find a StreamNumber indiciator or similiar information.
System.Speech.Synthesis provides information about just everything that is just happening, so it's highly unlikely that it doesn't provide the information which of the requests it's just processing.
How could this be retrieved?