首页 > 解决方案 > 我如何知道 Xamarin 中的文本转语音过程何时开始和结束

问题描述

我试图在 TTS 进程开始时添加动画(动画也开始),当 TTS 函数结束时,动画也结束。

我现在有这个作为我的代码:


            if (!string.IsNullOrWhiteSpace(TTSEditor.Text))
            {
                animationView.Loop = true;
                animationView.AutoPlay = true;
                animationView.Play();

                //insert TTS function Here
                var Text = TTSEditor.Text;
                CrossTextToSpeech.Current.Speak(Text, speakRate: (float)0.9, pitch: (float)1.1f);
            }          

            else
            {
                DisplayAlert("Error", "Text Field Should not be Blank to Use Text-to-Speech Functionality!", "OK");
            }

我使用 Xam.Plugins.TextToSpeech 作为我的 TTS,它工作正常,但我似乎无法在这里找到我想要的:https ://github.com/jamesmontemagno/TextToSpeechPlugin

标签: xamarintext-to-speech

解决方案


您可以等待发言过程:

private async void Button_Clicked(object sender, EventArgs e)
{
    Console.WriteLine("begin");

    await CrossTextToSpeech.Current.Speak("Hello world! Hello world! Hello world! Hello world!", speakRate: (float)0.9, pitch: (float)1.1f);

    Console.WriteLine("end");

}

参考:编程指南/概念/异步


推荐阅读