Having trouble stopping xamarin essentials text-to-speech in order to start a new text to speech "SpeakAsync" call w/ Xamarin.Forms.
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://learn.microsoft.com/en-us/xamarin/essentials/text-to-speech) however I cannot get the current "SpeakAsync" speech to stop playing immediately on iOS, or the next speakasync command to start speaking the text on iOS once the initial text-to-speech is cancelled.
CancelSpeech();
IsCallActive = false;
DialedText = null;
//Reset speech cancellation token
SpeechTokenSource = new CancellationTokenSource();
await TextToSpeech.SpeakAsync("This call has ended. Goodbye."
, SpeechTokenSource.Token);
Error logged in iOS output: "[AXTTSCommon] _BeginSpeaking: couldn't begin playback"
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?
Edit:
This needs to be done on a single button tap (both canceling current speech and starting the "This call has ended" speech)