Is it possible for an application to speak to a user? Of course! The speech synthesis mechanism, also referred as Text To Speech (TTS), is available for developers, and you will learn how to use it in this recipe.
As an example, you will create an application that says Hello, dear reader! How are you? when a user is navigated to the main page.
To synthesize the text Hello, dear reader! How are you?
after navigating to the page, override the OnNavigatedTo
method in the MainPage.xaml.cs
file, as follows:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
SpeechSynthesisStream stream = await
synthesizer.SynthesizeTextToStreamAsync(
"Hello, dear reader! How are you?");
MediaElement audio = new MediaElement();
audio.SetSource...