jsakamoto / Toolbelt.Blazor.SpeechSynthesis

SpeechSynthesis API access for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.SpeechSynthesis/
Mozilla Public License 2.0
91 stars 19 forks source link

Setting the language in the utterance is ignored on android browsers #17

Open snapfisher opened 10 months ago

snapfisher commented 10 months ago

When you set the language/locale in the utterance as

var utterance = new SpeechSynthesisUtterance { Text = frenchText, Lang = "fr-FR" };

This works on windows, but it is ignored in Android for both Chrome and Edge/Chrome browsers. Tested with Blazor .Net 7. By default, both browsers will use the system locale of your mobile device.

Methods to get this working can be found here: https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-7.0&preserve-view=true

If the answer is, "works on .Net 8", that's awesome, but I just don't have a way to test that right now.

jsakamoto commented 9 months ago

@snapfisher Thank you for your reporting!

But unfortunately, I couldn't reproduce the problem that you reported. I tried to reproduce the problem on a simple Blazor app in .NET 7 running on my outdated Android 7.0 device and its Google Chrome browser ver.119, but it worked fine.

I'll let you know the Blazor application sites that are used for my investigation below:

The source code is like below:

@inject SpeechSynthesis SpeechSynthesis

<div style="display:flex; flex-direction:column; gap:12px;">

    <div>
        <textarea @bind="_textToSpeech"></textarea>
    </div>

    <div>
        <input type="text" @bind="_lang" />
    </div>

    <div>
        <button @onclick="OnClickSpeak">Speak</button>
    </div>

</div>

@code
{
    private string? _textToSpeech = "Bonjour";

    private string _lang = "fr-FR";

    private async Task OnClickSpeak()
    {
        var utterance = new SpeechSynthesisUtterance
            {
                Text = _textToSpeech,
                Lang = _lang
            };
        await SpeechSynthesis.SpeakAsync(utterance);
    }
}

I'll attach the whole of the project files below:

I guess the "Blazor SpeechSynthesis" and the browser's speech engine might be working, but it might take a long time to download the language files for speaking French if it is the first time speaking French. Could you try that again with the high-speed internet connection?