I am working with a simple Text to Speech application using the System.Speech.Synthesis reference. I would like to add a slider control to the application and control the volume of the speech with it. In order to set the volume I'm using:
speech.Volume = 100;
Do I need to use some kind of event handler in order to update this value? By the way I'm creating this as a WPF application with C# (please not VB.NET code).
Add two sliders,
sliderVolume
for Volume control andsliderRate
for Rate control. Then in SpeakProgress event, assign new volume and rate tospeech
and by usingcharacterPosition
make a sub-string of original reading content. Then restart speak using this new sub-string. See the following code.The Slider control raises an event
ValueChanged
whenever its value changes. If you handle this event you could update your speech volume from there by checking theValue
property.There does not appear to be a built-in way of doing this. Handling the SpeakProgress event will give you access to the CharacterPosition property. This gives you position in the prompt at the start of the last word read. If you do a substring on the next white-space character and pass this as a new prompt, the rest of the prompt will be spoken from this point. If you're up to it, you can calculate how long a prompt will take to be read and use the AudioPosition property to get a TimeSpan object for how long the prompt has been running.
create event of
slider_ValueChanged
and setSpeech.volume = (int)sliderID.value;