Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DemoTTS: TextToSpeechUWP.cs
using System;
using Windows.UI.Xaml.Controls;
using Xamarin.Forms;
using DemoTTS.UWP.Clases;
using DemoTTS.Interfaces;
[assembly: Dependency(typeof(TextToSpeechUWP))]
namespace DemoTTS.UWP.Clases
{
public class TextToSpeechUWP : ITextToSpeech
{
public async void Speak(string text)
{
var mediaElement = new MediaElement();
var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
var stream = await synth.SynthesizeTextToStreamAsync(text);
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
You can’t perform that action at this time.