Rad
Rad

Reputation: 107

Text-to-speech does not work on different android phones

I am using exact android implementation code from https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/text-to-speech/ and same shared code example DependencyService.Get<ITextToSpeech>().Speak("Hello from Xamarin Forms"); Problem is that it works on Visual Studio android emulator and on my Huawei P9 but it does not work (It compiles but when it should speak instead it remains silent) on Samsung S6 or my friends other phone. Does anyone know what could cause the problem?

[assembly: Dependency(typeof(TextToSpeechImplementation))]
namespace DependencyServiceSample.Droid
{

public class TextToSpeechImplementation : Java.Lang.Object, ITextToSpeech, TextToSpeech.IOnInitListener
{
    TextToSpeech speaker;
    string toSpeak;

    public void Speak(string text)
    {
        toSpeak = text;
        if (speaker == null)
        {
            speaker = new TextToSpeech(Forms.Context, this);
        }
        else
        {
            speaker.Speak(toSpeak, QueueMode.Flush, null, null);
        }
    }

    public void OnInit(OperationResult status)
    {
        if (status.Equals(OperationResult.Success))
        {
            speaker.Speak(toSpeak, QueueMode.Flush, null, null);
        }
    }
}

}

Upvotes: 1

Views: 468

Answers (1)

Rad
Rad

Reputation: 107

The problem was that Samsung's text-to-speech language was set to Samsung's system language which was not supported by text-to-speech. And other android phone didn't have any text-to-speech engine installed.

Upvotes: 1

Related Questions