Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created October 29, 2017 13:06
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 aadennis/41aa5090ab75cbe70b37b9947f38fb45 to your computer and use it in GitHub Desktop.
Save aadennis/41aa5090ab75cbe70b37b9947f38fb45 to your computer and use it in GitHub Desktop.
Simple TextToSpeech in XAML
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App1
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
//https://docs.microsoft.com/en-us/uwp/api/windows.media.speechsynthesis.speechsynthesisstream
var mediaElement = new MediaElement();
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
var message = "Don't try this on Windows 10 N, as Media Player, and the like, is not supported.";
var stream = await synth.SynthesizeTextToStreamAsync(message);
mediaElement.SetSource(stream, stream.ContentType);
mediaElement.Play();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment