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