Pergunta

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

Foi útil?

Solução

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);

Outras dicas

This is kind of hacky (and isn't guaranteed to do letter-by-letter), but you could use the PhonemeReached event as a hint to display the next letter (and stop at word breaks) and then use the SpeakProgress event to generate the remaining letters in the word. If you're using SSML, you'll need to skip over markup, of course.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top