Skip to main content

Overview

The UnmuteHandler class is the core component of the Unmute system that manages the complete voice conversation pipeline. It inherits from AsyncStreamHandler and coordinates audio streaming, speech recognition, language model generation, and text-to-speech synthesis.

Class Definition

Constructor

Initializes the UnmuteHandler with default configuration:
  • input_sample_rate: 24000 Hz
  • output_frame_size: 480 samples
  • output_sample_rate: 24000 Hz

Properties

stt

Returns the current SpeechToText instance if available, otherwise None. Returns: SpeechToText | None

tts

Returns the current TextToSpeech instance if available, otherwise None. Returns: TextToSpeech | None

Core Methods

receive

Processes incoming audio frames from the user’s microphone.
tuple[int, np.ndarray]
required
Audio frame tuple containing sample rate and mono audio array
Behavior:
  • Sends audio to STT for transcription
  • Detects pauses in user speech
  • Handles bot interruptions
  • Manages conversation state transitions

emit

Returns output to be sent to the client (audio, events, or additional outputs). Returns: tuple[int, np.ndarray] | AdditionalOutputs | ora.ServerEvent | CloseStream | None

start_up

Initializes the handler by starting up the STT service and preparing for audio processing.

cleanup

Cleans up resources, including shutting down the recorder if enabled.

Conversation Management

add_chat_message_delta

Adds a message delta to the chat history.
str
required
Text to add to the current message
Literal['user', 'assistant']
required
Role of the message sender
int | None
Index of the message being generated (to avoid race conditions)
Returns: bool - True if this created a new message, False if appended to existing

interrupt_bot

Interrupts the bot while it’s speaking, clearing queues and stopping TTS/LLM tasks. Raises: RuntimeError if called when conversation state is not “bot_speaking”

update_session

Updates session configuration including instructions, voice, and recording preferences.
ora.SessionConfig
required
Session configuration object

Utility Methods

audio_received_sec

Returns how much audio has been received in seconds. Used for timing instead of wall-clock time. Returns: float - Seconds of audio received

get_gradio_update

Returns debug information and chat history for UI updates. Returns: AdditionalOutputs containing GradioUpdate with:
  • chat_history: List of message dictionaries
  • debug_dict: Debug information dictionary
  • debug_plot_data: Plot data for visualizations

copy

Creates a new instance of UnmuteHandler. Returns: UnmuteHandler

Internal Methods

determine_pause

Determines if the user has paused speaking based on STT pause prediction. Returns: bool - True if pause detected

detect_long_silence

Handles situations where the user doesn’t respond for more than 7 seconds by inserting a silence marker.

check_for_bot_goodbye

Checks if the assistant’s last message ends with “bye!” and closes the stream if so.

Configuration Constants

Example Usage

Notes

  • The handler uses a quest manager system to coordinate async tasks for STT, TTS, and LLM
  • Conversation state is managed through the internal Chatbot instance
  • Audio is processed at 24kHz sample rate with mono channel
  • The handler supports echo cancellation and VAD-based interruption detection