paraJdox1
paraJdox1

Reputation: 983

How do I know when a text-to-speech process starts and ends in Xamarin

I am trying to add animation when the TTS process begins (animation also starts), and when the TTS function ends the animation also ends.

I have this as my code for now:


            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");
            }

I am using Xam.Plugins.TextToSpeech as my TTS, it works fine, but I cant seem to find what I want here: https://github.com/jamesmontemagno/TextToSpeechPlugin

Upvotes: 1

Views: 145

Answers (2)

nevermore
nevermore

Reputation: 15806

You can wait the speak process:

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");

}

Refer: programming-guide/concepts/async

Upvotes: 4

Ivan I
Ivan I

Reputation: 9990

Each platform has such a capability, and you can call the native code from each platform using dependency injections if you are using Xamarin.Forms, or even directly if you use just native projects.

You may look if there is another plugin that would have such a capability, but I am not aware of it.

Unfortunately James is not updating that plugin anymore so chances for a new feature are very low.

So in general it is possible but it requires a lot of work and fairly good knowledge, I have provided you with some guidance as the answer cannot go beyond that.

Upvotes: 1

Related Questions