Skip to main content
When to Use clearAudioYou can send a clearAudio event to interrupt the audio that has been sent to Vobiz. This will clear all the buffered audio. Common scenarios include:
  • Barge-in: User starts speaking while AI prompt is playing
  • Context switch: User changes topic mid-conversation
  • Error recovery: Cancel current playback and play error message
  • Priority messages: Interrupt to play urgent information

Attributes

Request & Response

Request Format

Send this JSON message through the WebSocket to Vobiz to clear buffered audio:
clearAudio event request

Response Format

Vobiz acknowledges the clearAudio event with a clearedAudio response:
clearedAudio acknowledgment
The sequenceNumber field helps track the order of events in the stream.
Important:After sending clearAudio, all previously sent playAudio events that haven’t been played yet are discarded. Any pending checkpoint events will not receive acknowledgments. You can immediately send new playAudio events after clearAudio to replace the interrupted audio.

Common use cases

1. Voice Assistant Barge-In

When building conversational AI, users often start speaking before the AI finishes its response. Detect user speech and send clearAudio to stop the AI from continuing its playback.
Detect speech and interrupt

2. Dynamic Content Updates

If you’re playing a long audio message and receive updated information (e.g., real-time data), you can interrupt the current playback and play the updated content.
Update with new information

3. Error Handling & Recovery

When an error occurs during a transaction or API call, interrupt the current flow and play an appropriate error message.
Handle errors gracefully

Implementation Examples

Node.js Example

Complete clearAudio implementation

Python Example

clearAudio with asyncio

Ordering and edge cases

  • clearAudio only flushes audio that hasn’t reached the caller yet. Anything already played out cannot be recalled. Keeping playAudio chunks small (~20 ms) maximises how much a barge-in can cancel.
  • Pending checkpoints are voided. Every checkpoint whose audio was still queued at the moment of the flush will not produce a playedStream. Reset your per-utterance state (timers, botSpeaking flags) when you send clearAudio, and don’t wait on those acks.
  • Gate new playback on clearedAudio. If you playAudio immediately after clearAudio without waiting for the clearedAudio ack, the new audio can race the flush and be partially dropped. Wait for clearedAudio, then enqueue the replacement.
  • Debounce barge-in detection. A single noisy media frame can trip a naive energy threshold. Require a short run of speech-level frames (or use a proper VAD) before firing clearAudio, or you will cut off the bot on background noise.
  • clearedAudio carries sequenceNumber and streamId. Use streamId to confirm it matches the active stream; sequenceNumber reflects ordering within the stream.
Barge-in that gates replacement audio on clearedAudio

Best Practices

Wait for clearedAudio Acknowledgment

Before sending new playAudio events after clearAudio, it’s best practice to wait for the clearedAudio acknowledgment to ensure the buffer is fully cleared.

Track Playback State

Maintain a state variable to track whether audio is currently playing. This helps you decide when to send clearAudio events and avoid unnecessary interruptions.

Use Appropriate Detection Thresholds

When implementing barge-in, tune your speech detection threshold carefully to avoid false positives from background noise while still being responsive to actual user speech.