MQTT-controlled simple command line audio player, designed for building interactive entertainment on a budget.
To install: sudo make install-dependencies
Dependencies to be installed include sdl2, librt, mosquitto, asound and curl (see Makefile for details)
All Linux platforms should work, but only tested on Raspberry Pi/Raspbian
To build: make mqttaudio
mqttaudio --server localhost --port 1883 --topic audio/commands --alsa-device yourdevicename --preload http://myserver.example.com/really_large_audio_file.wav
All command line switches are optional except 'topic'.
To find ALSA devices: mqttaudio --list-devices
To control, send a valid JSON message to the topic specified:
{"command": "play", "message": {"file": "http://example.com/audio.wav", "loop": true, "volume": 0.75, "exclusive": false, "maxPlayLength": 60000}}
{"command": "stopall"}
{"command": "fadeout", "message": {"time": 10000}}
{"command": "precache", "message": {"file": "http://example.com/loadme.wav"}}
File paths can be local or remote. All times in milliseconds.
Supported formats: WAV, OGG. MP3 and MOD may work but are untested
Tip: A 5.1 audio USB breakout box, combined with careful ALSA configuration that splits the output devices into single-channel PCM devices, can support up to six independent channels at once of output. Run a separate instance of mqttaudio for each target output device.
No validation is performed on local file paths, so do not connect to unsecured/untrusted MQTT servers; this tool is designed for closed-loop offline interactive entertainment control systems.
No option is currently available to authenticate against a secured MQTT server. (Pull requests cheerfully accepted!)
Files played are cached for performance. No cache eviction logic currently exists, so if you play a lot of different files (e.g. autogenerated files) you will eventually run out of resources. The current implementation is designed for a limited number of pre-determined sound and music files. (Pull requests cheerfully accepted!)
- SDL HTTP bindings: SDL_rwhttp - https://github.com/mgerhardy/SDL_rwhttp (@mgerhardy, zlib license)
- JSON parser: RapidJSON - https://github.com/Tencent/rapidjson (Tencent, MIT license)
Open an issue or send a pull request! Please abide by the Contributor Covenant (code_of_conduct.md).
MIT