How to Cancel the Speech Synthesis in windows phone 8?

The Windows Phone 8 SDK provides the Speech Synthesis (Text to Speech) feature which lets the developers to provide the text input and lets the windows phone speak the text for you.

Sometimes when the Speech Synthesizer speaks the given text to the user, the user may want to cancel the speech synthesis.

How to Cancel the Speech Synthesis in windows phone 8 App?

In order to cancel the speech synthesis in Windows Phone 8 App when the phone is speaking out the text, you can use the assign the return value of the SpeakTextAsync method of the SpeechSynthesizer object to the IAsyncAction and then call the Cancel method of the IAsyncAction to cancel the speech synthesis.

For example, assume that the Speech Synthesizer and the IAsyncAction is declared in the page as shown below.

private SpeechSynthesizer synth = new SpeechSynthesizer();

private IAsyncAction task;

When the SpeakTextAsync is called, assign the result to the IAsyncAction.

task = synth.SpeakTextAsync("Welcome to developerpublish.com - All about Mobile development");

When you want to cancel the speech synthesis, call the Cancel method of the task.

task.Cancel();

Download the code sample used in this blog post here

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...