Skip to content

Instantly share code, notes, and snippets.

@dragthor
Created January 23, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragthor/3cccf7e82838f07b1f22 to your computer and use it in GitHub Desktop.
Save dragthor/3cccf7e82838f07b1f22 to your computer and use it in GitHub Desktop.
private void Image_PointerPressed(object sender, PointerRoutedEventArgs e)
{
var img = e.OriginalSource as Windows.UI.Xaml.Controls.Image;
if (img == null) return;
var title = img.Tag as string;
// The object for controlling the speech-synthesis engine (voice).
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
// Generate the audio stream from plain text.
IAsyncOperation<SpeechSynthesisStream> stream = synth.SynthesizeTextToStreamAsync(title);
stream.Completed = Speak;
}
private void Speak(IAsyncOperation<SpeechSynthesisStream> asyncInfo, AsyncStatus asyncStatus)
{
var results = asyncInfo.GetResults();
this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
MediaElement mediaElement = this.media;
// Send the stream to the media object.
mediaElement.SetSource(results, "");
mediaElement.Play();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment