Search code examples
maui

SpeechToText method does not provide Turkish results


I'm trying the speech-to-text method, but the resulting text is in English.

.net 9.0, CommunityToolkit.Maui 11.0

These are my codes:

    public async Task<string> MediaToolKitSpeechToTextAsync()
{
    var options = new SpeechToTextOptions
    {
        Culture = CultureInfo.GetCultureInfo("tr-TR") 
    };

    await SpeechToText.Default.StartListenAsync(options, CancellationToken.None);

    SpeechToText.Default.RecognitionResultCompleted += (s, args) =>
    {
        if (args.RecognitionResult != null && !string.IsNullOrEmpty(args.RecognitionResult.Text))
        {
            transcript = args.RecognitionResult.Text;
        }
        else
        {
            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await DisplayAlert("Hata", "Ses anlaşılamadı.", "Tamam");
            });
        }
    };

    return transcript;
}

Solution

  • And finally, I found the bug. I replaced culture with tr_TR and done.

    public async Task<string> MediaToolKitSpeechToTextAsync(){
    
    var options = new SpeechToTextOptions
    {
        Culture = CultureInfo.GetCultureInfo("tr_TR") 
    };
    
    await SpeechToText.Default.StartListenAsync(options, CancellationToken.None);
    
    SpeechToText.Default.RecognitionResultCompleted += (s, args) =>
    {
        if (args.RecognitionResult != null && !string.IsNullOrEmpty(args.RecognitionResult.Text))
        {
            transcript = args.RecognitionResult.Text;
        }
        else
        {
            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await DisplayAlert("Hata", "Ses anlaşılamadı.", "Tamam");
            });
        }
    };
    
    return transcript;
    

    }