A bidirectional audio streaming example using local microphone and audio output devices with the LiveKit Python SDK. Features real-time audio processing with echo cancellation, dB level meters, and mute controls.
- Bidirectional Audio: Send microphone audio and receive audio from other participants
- Echo Cancellation: Built-in Acoustic Echo Cancellation (AEC)
- Real-time Meters: Visual dB level meters for local microphone and remote participants
- Mute Control: Toggle microphone mute with keyboard shortcut (M key)
- Live UI: Real-time terminal interface showing audio levels and connection stats
- Device Selection: Automatic audio device detection and configuration
First, install uv, a fast Python package manager:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Alternative (using pip):
pip install uv
Clone the repository and set up the environment:
cd local-audio-python
The script uses uv's inline script dependencies, so no additional setup is required. Dependencies are automatically managed by the script.
Set up the environment by copying .env.example
to .env
and filling in the required values:
LIVEKIT_URL
- Your LiveKit server URLLIVEKIT_API_KEY
- Your LiveKit API keyLIVEKIT_API_SECRET
- Your LiveKit API secretROOM_NAME
- Room name to join
Run the audio streamer with default settings:
uv run stream_audio.py
The script supports several command line options:
# Specify participant name
uv run stream_audio.py --name "Your Name"
# Disable echo cancellation
uv run stream_audio.py --disable-aec
# Enable debug logging
uv run stream_audio.py --debug
# Combine options
uv run stream_audio.py --name "Alice" --debug
Once running, use these keyboard controls:
- M - Toggle microphone mute/unmute
- Q - Quit the application
- Ctrl+C - Force quit
- Use headphones to avoid audio feedback between speakers and microphone
- The application automatically detects and configures audio devices
- Supports 48kHz sample rate with mono audio for optimal quality
The terminal interface shows:
- Local Microphone: Live/muted status with dB level meter
- Remote Participants: List of connected participants with their audio levels
- Statistics: Connection stats, frame counts, and queue status
- Controls: Available keyboard shortcuts
If you encounter audio device problems:
- List available devices:
uv run list_devices.py