Skip to main content
The Python SDK gives you programmatic control over the local microphone and lets you inject custom audio (WAV files or raw 16-bit PCM bytes) directly into the room.

Microphone Management

Start/Stop Microphone

Programmatically connect or disconnect the microphone track:

Muting and Unmuting

Mute or unmute microphone input without tearing down the audio track:

Get Microphone State

get_input_audio_state() returns an InputAudioState object containing both the mute status and mic permission status:

TruGenRunner shortcut

If you’re using TruGenRunner, toggle mute from the main thread safely:

Audio Injection

You can stream custom audio into the room — a pre-recorded WAV file or raw 16-bit PCM bytes. Useful for scripted playback, voice cloning demos, or piping in audio from another source.
Auto-mute the microphone before injecting audio, then unmute after it completes. Without muting, the agent’s response to your injected audio loops back through the mic and floods the STT pipeline — see the WAV-injection helper in examples/advanced_session_ui.py for the recommended pattern.

Upload a WAV file

Stream a PCM WAV file into the room:
The SDK handles reading, decoding, and pacing the audio into the session at the right sample rate.

Send raw PCM bytes

Inject raw 16-bit PCM bytes directly:
Use send_audio() when your source is already decoded — TTS output from another provider, live audio from a different track, or synthetic audio you’re generating on the fly.

Safe injection pattern

The recommended pattern (used in examples/advanced_session_ui.py) mutes the mic during injection and restores its previous state afterwards:

Next steps

Event Handling

Listen to connection, speaking, and transcription events.

Advanced Example

Full GUI viewer with WAV injection, captions, and speaking state.