Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created November 22, 2018 18:56
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 icebeam7/1e5bf675cdf0532aaad2445d7a23c8ab to your computer and use it in GitHub Desktop.
Save icebeam7/1e5bf675cdf0532aaad2445d7a23c8ab to your computer and use it in GitHub Desktop.
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