Tuesday, December 30, 2014

How do I pause my loop until text-to-speech has read every word in a string?

You won't really be able to do this in a loop properly. You will have to adopt an event driven approach. Basically you would read the first paragraph, register to the MediaElement's CurrentStateChanged Event and then have the MediaElement read it out loud. When the event triggers you would then load the next paragraph and start Playback again. When Playback finished the event would trigger and you would read the next paragraph, etc.


Basically that is what async/await does behind the scenes anyway in APIs that support it - it just hides those details and makes it easier to write and read asynchronous code.


One way to perhaps optimize this would be to start playback and immediately load the next paragraph using a ThreadPool thread so it's already loaded and synthesized when the event fires. You would then have it read the next paragraph and again launch your ThreadPool thread to load the next one.


No comments:

Post a Comment