Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created November 22, 2018 18:30
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/66a2b031fefd665916e4f5fc3df96acc to your computer and use it in GitHub Desktop.
Save icebeam7/66a2b031fefd665916e4f5fc3df96acc to your computer and use it in GitHub Desktop.
DemoTTS: TextToSpeechAndroid.cs
using Android.Speech.Tts;
using Xamarin.Forms;
using DemoTTS.Droid.Clases;
using DemoTTS.Interfaces;
[assembly: Dependency(typeof(TextToSpeechAndroid))]
namespace DemoTTS.Droid.Clases
{
public class TextToSpeechAndroid : Java.Lang.Object, ITextToSpeech, TextToSpeech.IOnInitListener
{
TextToSpeech tts;
string message;
public void Speak(string text)
{
message = text;
if (tts == null)
tts = new TextToSpeech(MainActivity.Instance, this);
else
tts.Speak(text, QueueMode.Flush, null, null);
}
public void OnInit(OperationResult status)
{
if (status.Equals(OperationResult.Success))
tts.Speak(message, QueueMode.Flush, null, null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment