Simple, elegant spatial audio orchestration for immersive experiences
Project description
Cue
Simple audio orchestration for immersive experiences.
Overview
Cue is a Python library for MQTT-controlled audio systems.
It provides declarative audio clip management with real-time mixing, polyphonic playback, and automatic device detection.
Perfect for escape rooms, interactive installations, theater tech, and any application requiring responsive spatial audio on a budget.
Features
- Declarative audio clip configuration
- MQTT integration for remote triggering
- Stereo and 5.1 surround sound support
- Polyphonic audio with instance limits
- Automatic audio device detection
- Graceful error handling and recovery
- Real-time audio mixing with fade support
- Choke groups for mutually exclusive sounds
Quick Start
from Cue import AudioController, AudioClip
# Create audio controller
audio = AudioController(
channels="stereo",
mqtt_broker="192.168.1.100",
mqtt_credentials=("username", "password")
)
# Register audio clips
audio.register_clip("thunder", AudioClip(
file="thunder.wav",
volume=1.0,
mqtt_triggers={"storm/thunder": "play"}
))
audio.register_clip("rain", AudioClip(
file="rain.wav",
loop=True,
auto_play=True
))
# Start the system
audio.start()
API Reference
AudioController
Main controller class for managing audio system and MQTT connections.
AudioController(
channels="stereo",
device="default",
mqtt_broker=None,
mqtt_credentials=None,
mqtt_port=1883
)
Parameters:
-
channels(str): Audio channel configuration"stereo"- 2 channel stereo output"5.1"- 6 channel surround sound
-
device(str): Audio output device selection"default"- Use system default audio device- Device name - Specify exact device name
-
mqtt_broker(str, optional): MQTT broker IP address or hostnameNone- Disable MQTT functionality- IP/hostname - Enable MQTT with specified broker
-
mqtt_credentials(tuple, optional): MQTT authenticationNone- No authentication required("username", "password")- MQTT credentials tuple
-
mqtt_port(int): MQTT broker port number- Default:
1883
- Default:
Methods:
register_clip(name, clip)
Register an AudioClip instance with unique identifier.
start()
Start the audio system and MQTT client. Blocks until interrupted.
stop()
Gracefully stop audio system and disconnect MQTT.
AudioClip
Declarative audio clip configuration class.
AudioClip(
file,
volume=1.0,
fade_out=0.0,
fade_in=0.0,
length=None,
choke_group=None,
mqtt_triggers=None,
loop=False,
auto_play=False,
routing=None,
poly=False,
max_poly=4
)
Parameters:
-
file(str): Path to audio file (WAV format, stereo) -
volume(float): Playback volume level- Range:
0.0to2.0 - Default:
1.0
- Range:
-
fade_in(float): Fade in duration in seconds- Default:
0.0(no fade in)
- Default:
-
fade_out(float): Fade out duration in seconds- Default:
0.0(no fade out)
- Default:
-
length(float, optional): Maximum playback durationNone- Play full file duration- Seconds - Stop after specified duration
-
choke_group(str, optional): Mutual exclusion groupNone- No choke group- Group name - Only one clip in group plays at time
-
mqtt_triggers(dict, optional): MQTT topic bindingsNone- No MQTT triggers{"topic": "action"}- Map topics to actions- Actions:
"play","stop"
-
loop(bool): Enable continuous loopingFalse- Play once and stopTrue- Loop indefinitely until stopped
-
auto_play(bool): Start playing on system startupFalse- Manual triggering onlyTrue- Begin playback immediately
-
routing(dict, optional): Speaker channel routingNone- Default stereo routing{"left": "left", "right": "right"}- Custom routing map- Channels:
"left","right" - Speakers:
"left","right","front_left","front_right","center","subwoofer","rear_left","rear_right"
-
poly(bool): Enable polyphonic playbackFalse- Monophonic (one instance at a time)True- Polyphonic (multiple simultaneous instances)
-
max_poly(int): Maximum polyphonic instances- Default:
4 - Only applies when
poly=True
- Default:
Configuration Examples
Basic MQTT Triggered Audio
clip = AudioClip(
file="doorbell.wav",
volume=0.8,
mqtt_triggers={"house/doorbell": "play"}
)
Looping Ambient Sound
ambient = AudioClip(
file="forest.wav",
volume=0.5,
loop=True,
auto_play=True,
fade_in=2.0
)
Polyphonic Sound Effects
footsteps = AudioClip(
file="step.wav",
volume=0.7,
poly=True,
max_poly=6,
mqtt_triggers={"player/step": "play"}
)
5.1 Surround Routing
explosion = AudioClip(
file="boom.wav",
volume=1.0,
routing={
"left": "front_left",
"right": "front_right",
}
)
Choke Groups
# Only one voice clip can play at a time
voice1 = AudioClip(
file="voice1.wav",
choke_group="dialogue",
mqtt_triggers={"npc/speak1": "play"}
)
voice2 = AudioClip(
file="voice2.wav",
choke_group="dialogue",
mqtt_triggers={"npc/speak2": "play"}
)
MQTT Integration
Cue subscribes to specified MQTT topics and triggers audio actions based on incoming messages.
Topic Structure
your/topic/structure
Direct topic binding via mqtt_triggers parameter.
Message Format
Topic-bound triggers expect any message payload.
Action is determined by mqtt_triggers configuration.
Connection Resilience
- Automatic reconnection on connection loss
- Audio continues playing during MQTT outages
- Graceful error handling with status logging
Error Handling
Cue follows "fail gracefully" principles:
- Missing audio files generate warnings, not crashes
- MQTT connection failures don't stop audio playback
- Invalid configurations log errors and continue
- Thread-safe operations prevent race conditions
Requirements
- Python 3.8+
- PyAudio
- paho-mqtt
- numpy
Installation
pip install -e .
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cue_audio-1.0.0.tar.gz.
File metadata
- Download URL: cue_audio-1.0.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d93e87ef1bf86cf815933dd2f54d149ed1b10127df041a1c7bd6226ea150b21
|
|
| MD5 |
6701e7dea7ed97c2891dc7ae2adb5bf8
|
|
| BLAKE2b-256 |
f030fc40367c849894c13d7fccf17a4c08c2be8c6a08b5f1072155bb5e231483
|
File details
Details for the file cue_audio-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cue_audio-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b7f4743afca838e82a8c74be60b686d8b3f6876655adcd73dde8fb238ab78b
|
|
| MD5 |
8d5c5e71a68690b67b6e28e4b86bdbf8
|
|
| BLAKE2b-256 |
ce637909e640bd59df3f03d464b9aad11f84878c379222991da57ec26735013b
|