Friday 6 September 2019

How to stop/cut-off xamarin essentials text-to-speech on iOS to start new speech

Having trouble stopping xamarin essentials text-to-speech in order to start a new text to speech "SpeakAsync" call.

Using this application as a simulated operator for a "practice phone call", I would like to cut off the operator saying "hello this is...." when the user hangs up the call, and use speak async to start saying "This call has ended" immediately after cutting off the previous text to speech

await TextToSpeech.SpeakAsync("Hello this is the operator, thank you for calling, how can I help you?"
    , SpeechTokenSource.Token);

This currently works as expected on android

public void CancelSpeech()
{
    if (SpeechTokenSource?.IsCancellationRequested ?? true)
    return;

    SpeechTokenSource.Cancel();
}

Trying to use cancellation token as listed in the documentation (https://docs.microsoft.com/en-us/xamarin/essentials/text-to-speech) however I cannot get the current "SpeakAsync" speech to stop playing, or the next speakasync command to start speaking the text on iOS.

   CancelSpeech();

   IsCallActive = false;
   DialedText = null;

   //Reset speech cancellation token
   SpeechTokenSource = new CancellationTokenSource();

   await TextToSpeech.SpeakAsync("This call has ended. Goodbye."
   , SpeechTokenSource.Token);

Is there something I am missing? how can I cancel the current text-to-speech that is playing and start the next speech immediately after?



from How to stop/cut-off xamarin essentials text-to-speech on iOS to start new speech

No comments:

Post a Comment