Search code examples
wpfspeech-to-textspeech-synthesis

SpeechSynthesizer audio to text as its spoken


I Am currently working on a project where I want to have the SpeechSynthesizer speak a text. I also want a textblock to display the words as they are spoken. This is so you can read along if you don't understand the Speech Synthesizer.

So basically the problem is that i cant find a efficient way to append every letter to a text within a textbox right when its spoken by the Speech Synthesizer. So it looks like the Speech Synthesizer is typing along with what he is saying.

Example

If I would do this:

SpeechSynthesizer x = new SpeechSynthesizer();
x.SpeakAsync("Hello there");

I want the textbox text to write along as the words are spoken by the x (SpeechSynthesizer ). Something like this: http://youtu.be/hx6JL7PsLrg?t=1m56s


Solution

  • As Eric mentioned, you have to use the SpeechSynthesizer.SpeakProgress event:

    For Example:

    var ss = new SpeechSynthesizer();
    ss.SpeakProgress += (sender, args) => txtBox.Text += args.Text;
    ss.Speak("Hello this is " + true);