Created
October 29, 2017 13:06
-
-
Save aadennis/41aa5090ab75cbe70b37b9947f38fb45 to your computer and use it in GitHub Desktop.
Simple TextToSpeech in XAML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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