Important: This is documentation for the legacy version of the Vivox Unity SDK. This documentation will be removed after July 2025. Refer to the v16 documentation for the new version of the SDK.

Cancel a text-to-speech message

To cancel a currently playing or queued text-to-speech (TTS) message, use ITextToSpeech.CancelMessage() or ITextToSpeech.Messages.Remove() with the TTSMessage that you want to cancel. You can also use the Dequeue() method on any ITTSMessageQueue collection to cancel the message at the head of the queue.

You can directly cancel any TTSMessage object that was previously spoken by using TTSMessage.Cancel(). This is detailed in the following example:

TTSDestination destination = TTSDestination.QueuedRemoteTransmissionWithLocalPlayback;
TTSMessage m1 = new TTSMessage("One", destination); myLoginSession.TTS.Speak(m1);
TTSMessage m2 = new TTSMessage("Two", destination); myLoginSession.TTS.Speak(m2);
TTSMessage m3 = new TTSMessage("Three", destination); myLoginSession.TTS.Speak(m3);
TTSMessage m4 = new TTSMessage("Four", destination); myLoginSession.TTS.Speak(m4);

myLoginSession.TTS.CancelMessage(m1);
myLoginSession.TTS.Messages.Remove(m2);
myLoginSession.TTS.Messages.Dequeue();
m4.Cancel();

In destinations that contain queues, canceling an ongoing TTS message automatically triggers playback of the next message. Canceling a queued TTS message shifts all later messages up one place in the queue.

You can cancel all TTS messages in a destination (ongoing and queued), or all TTS messages in all destinations.

// Cancel all TTS messages in the destination for Queued Local Playback
myLoginSession.TTS.CancelDestination(TTSDestination.QueuedLocalPlayback);

// Cancel all TTS messages in all destinations
myLoginSession.TTS.CancelAll();