我如何知道文本到语音过程何时在 Xamarin 中开始和结束
How do I know when a text-to-speech process starts and ends in 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
每个平台都有这样的能力,如果你使用Xamarin.Forms,你可以使用依赖注入从每个平台调用原生代码,如果你只使用原生项目,甚至可以直接调用。
您可能会看看是否有其他插件具有这种功能,但我不知道。
不幸的是,James 不再更新该插件,因此出现新功能的可能性很小。
所以一般来说这是可能的,但它需要大量的工作和相当好的知识,我已经为你提供了一些指导,因为答案不能超出这个范围。
您可以等待发言过程:
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");
}
我正在尝试在 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
每个平台都有这样的能力,如果你使用Xamarin.Forms,你可以使用依赖注入从每个平台调用原生代码,如果你只使用原生项目,甚至可以直接调用。
您可能会看看是否有其他插件具有这种功能,但我不知道。
不幸的是,James 不再更新该插件,因此出现新功能的可能性很小。
所以一般来说这是可能的,但它需要大量的工作和相当好的知识,我已经为你提供了一些指导,因为答案不能超出这个范围。
您可以等待发言过程:
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");
}