Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

TextToSpeech.SpeakAsync from Xamarin.Essentials doesn't produce any sound

EliranEliran USMember ✭✭✭

Hi,
I try the TextToSpeech.SpeakAsync feature, but it I gets no sound and no error is shown.
In addition, the row after the await is never reached.

private async void Button1_OnClicked(object sender, EventArgs e)
{
await TextToSpeech.SpeakAsync("Hi there");
int x = 9; //this row is never reached
}

P.S I use Android 6.0.1 The media and sounds level are on maximum.

Best Answer

  • EliranEliran USMember ✭✭✭
    Accepted Answer

    @LeonLu
    Thank you Leon for your answer. It seems the problem was else: The minute I set the Locale property
    in SpeechOptions and added SpeechOptions as an argument, it worked.

    The solution:

    IEnumerable locals = await TextToSpeech.GetLocalesAsync();
    Locale local = locals.FirstOrDefault(y=> string.Equals(y.Country, "USA"));
    var mySpeechOptions = new SpeechOptions
    {
    Volume = 1,
    Pitch = 0.2f,
    Locale = local
    };

    await TextToSpeech.SpeakAsync("HI there", mySpeechOptions);

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    I test my code in Google Pixel and Huawei device(Android 6.0), both of them are worked as normal. please use my demo to make a test in your device, and make sure the Media volume is enabled like following screenshot.

  • EliranEliran USMember ✭✭✭
    Accepted Answer

    @LeonLu
    Thank you Leon for your answer. It seems the problem was else: The minute I set the Locale property
    in SpeechOptions and added SpeechOptions as an argument, it worked.

    The solution:

    IEnumerable locals = await TextToSpeech.GetLocalesAsync();
    Locale local = locals.FirstOrDefault(y=> string.Equals(y.Country, "USA"));
    var mySpeechOptions = new SpeechOptions
    {
    Volume = 1,
    Pitch = 0.2f,
    Locale = local
    };

    await TextToSpeech.SpeakAsync("HI there", mySpeechOptions);

Sign In or Register to comment.