This is a hastily written script to create an announcement queue for the Raspberry Pi. The specific purpose was to use in conjunction with OpenHab to queue announcements to make throughout the house. This code is not polished at all, but is functional.
WARNING: this is not even close to being secure. The script runs as root and is almost guaranteed to be vulnerable to command injection I have my Raspberry Pi setup on a separate, firewalled VLAN, so only the automation controller can access it directly.
I have a 2 relay board with relay control on pins 24 and 25 for zones A and B. I have an amplifier plugged into the output of a USB audio adapter on the Pi. The left output of the amp is split and routed through both of the relays and then speakers are hooked up to the relay output to create the zones.
http://rpi-announce:8084/?type=sound&message=wx_alert×=1&volume=5&priority=200&id=wx&zone=B
Where:
- type is the set to "sound" to play a pre-recorded .wav file from /var/sounds/ (type is there with the idea that text to speech might be available in the future)
- message is the name of the .wav file to play from /var/sounds/ (in this case, wx_alert.wav)
- times is the amount of times to play the announcement (if times is 0, the announcement will loop until it is stopped with a stop command)
- volume is the volume to set the Pis volume to while playing the announcement
- priority defines the order the announcements will be played (lower numbers first) if there are multiple in queue
- id is only really used for times=0 announcements so that it can be referenced to stop it (but it is always required)
- zone is the zone to play it in. My relays are set to A is outside, B is inside, and C is all zones
http://rpi-announce:8084/?id=wx
This will stop a continuously looping (times=0) announcment with id of wx
I added
/usr/bin/python3 /home/pi/AnnouncementSystem.py &
to rc.local on the Pi right before the exit 0