squawk
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
squawk [2016-10-05 11:34] – rob | squawk [2023-11-25 23:45] (current) – Added playlist command jaso55555 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Audio Alerts ====== | + | ====== Audio Alerts |
- | Traditionally this was handled by doorpi. However, that pi has too much stuff hanging off it, and was very out of date. There was an issue of a loud pop occurring before any sound played, this was fixed in later firmware updates. Rob has now dedicated | + | Traditionally this was handled by doorpi. However, that pi has too much stuff hanging off it, and was very out of date. There was an issue of a loud pop occurring before any sound played, this was fixed in later firmware updates. Rob has purchased |
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | Sounds and TTS messages are triggered via the [[mqtt# | ||
+ | |||
+ | Examples for testing might be something like: | ||
+ | |||
+ | Play a sound file: | ||
+ | < | ||
+ | mosquitto_pub -h mqtt -t ' | ||
+ | </ | ||
+ | Play a list of sound files with no gap: | ||
+ | < | ||
+ | mosquitto_pub -h mqtt -t ' | ||
+ | </ | ||
+ | Text-to-speech message (with a subtle notification bong): | ||
+ | < | ||
+ | mosquitto_pub -h mqtt -t ' | ||
+ | </ | ||
+ | Text-to-speech message (with a clear airport/ | ||
+ | < | ||
+ | mosquitto_pub -h mqtt -t ' | ||
+ | </ | ||
+ | |||
+ | **Theory:** You could direct sound two only two rooms at once by playing the left or right channel only. By default mpg123 is called with the -m option to ensure that the output is mono and thus the same sound comes out every speaker. | ||
+ | |||
+ | ===== Adding new sounds ===== | ||
+ | |||
+ | Use the web file browser at http:// | ||
===== Raspbian ===== | ===== Raspbian ===== | ||
Line 9: | Line 38: | ||
==== raspi-config ==== | ==== raspi-config ==== | ||
+ | * Expand filesystem | ||
* Medium overclock | * Medium overclock | ||
* Graphics mem reduced to 16M | * Graphics mem reduced to 16M | ||
* Audio output forced to 3.5mm | * Audio output forced to 3.5mm | ||
* Hostname set | * Hostname set | ||
+ | |||
+ | ==== RAM /tmp ==== | ||
+ | |||
+ | < | ||
+ | sudo systemctl enable tmp.mount | ||
+ | </ | ||
==== Packages ==== | ==== Packages ==== | ||
Line 19: | Line 55: | ||
sudo apt-get install mpg123 | sudo apt-get install mpg123 | ||
sudo apt-get install sox | sudo apt-get install sox | ||
- | sudo apt-get install espeak | ||
sudo apt-get install python-pip | sudo apt-get install python-pip | ||
sudo pip install paho-mqtt | sudo pip install paho-mqtt | ||
Line 29: | Line 64: | ||
< | < | ||
- | su -c "mpg123 | + | su -c "/ |
- | su -c "/ | + | su -c "/ |
</ | </ | ||
- | |||
- | ==== /etc/fstab ==== | ||
- | |||
- | Adding a ramdisk for temp speech file storage. | ||
- | |||
- | < | ||
- | proc /proc | ||
- | / | ||
- | / | ||
- | tmpfs /var/tmp tmpfs nodev, | ||
- | # a swapfile is not a swap partition, no line here | ||
- | # | ||
- | </ | ||
- | |||
===== Scripts ===== | ===== Scripts ===== | ||
Line 61: | Line 82: | ||
import signal | import signal | ||
import time | import time | ||
+ | import random | ||
- | + | logging.basicConfig(level=logging.INFO) | |
- | last_state | + | |
max_playtime | max_playtime | ||
+ | sounds_path = "/ | ||
- | sounds_path | + | status |
# runs a command and terminates it after a specified timeout | # runs a command and terminates it after a specified timeout | ||
Line 118: | Line 140: | ||
candidates.append(f) | candidates.append(f) | ||
if len(candidates) == 0: | if len(candidates) == 0: | ||
- | | + | |
+ | return | ||
filename = random.choice(candidates) | filename = random.choice(candidates) | ||
else: | else: | ||
# single file requested | # single file requested | ||
if filename not in allfiles: | if filename not in allfiles: | ||
- | | + | |
+ | | ||
base, ext = os.path.splitext(filename) | base, ext = os.path.splitext(filename) | ||
if ext == ' | if ext == ' | ||
- | command = [' | + | command = [' |
call_with_timeout(command, | call_with_timeout(command, | ||
else: | else: | ||
- | command = [' | + | command = ['play', '-q', filename] |
call_with_timeout(command, | call_with_timeout(command, | ||
Line 136: | Line 159: | ||
client.subscribe(" | client.subscribe(" | ||
client.subscribe(" | client.subscribe(" | ||
+ | client.subscribe(" | ||
+ | client.subscribe(" | ||
+ | client.subscribe(" | ||
def on_message(client, | def on_message(client, | ||
+ | |||
+ | global status | ||
+ | |||
+ | if msg.topic == ' | ||
+ | if msg.payload == ' | ||
+ | | ||
+ | else: | ||
+ | | ||
# ignore retained (non-realtime) messages | # ignore retained (non-realtime) messages | ||
Line 144: | Line 178: | ||
if msg.topic == ' | if msg.topic == ' | ||
- | play(msg.payload) | + | |
if msg.topic == ' | if msg.topic == ' | ||
- | play('dong.mp3') | + | |
speak(msg.payload) | speak(msg.payload) | ||
- | | + | |
+ | if msg.topic == ' | ||
+ | play(' | ||
+ | speak(msg.payload) | ||
+ | |||
+ | if msg.topic == ' | ||
+ | if status == ' | ||
+ | play(' | ||
m = mqtt.Client() | m = mqtt.Client() | ||
Line 304: | Line 345: | ||
<code bash> | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
- | pico2wave -l en-GB -w /var/ | + | pico2wave -l en-GB -w / |
- | play -q /var/ | + | play -q / |
- | rm -f /var/ | + | rm -f / |
+ | </ | ||
+ | |||
+ | ==== / | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | sleep 3 | ||
+ | _IP4=$(hostname -I | cut -d ' ' -f 1) || true | ||
+ | |||
+ | mpg123 -m -q / | ||
+ | / | ||
</ | </ | ||
===== Audio files ===== | ===== Audio files ===== | ||
- | These live in / | + | These live in / |
< | < | ||
Line 347: | Line 399: | ||
===== Hardware ===== | ===== Hardware ===== | ||
+ | {{ : | ||
+ | The " | ||
+ | |||
+ | There are four speakers connected, two per channel, located in each of the rooms on the ceiling. The speakers are 8 Ohm moisture resistant cheap ceiling speakers that have exceeded expectations and produce a surprisingly full sound. This opens up the potential for using them for background music in the future (e.g. via MPD). | ||
+ | |||
+ | ==== Raspberry Pi ==== | ||
+ | |||
+ | Standard pi other than having some wires soldered on the underside of the board to connect to the 3.5mm audio jack. Powered via the header rather than USB. | ||
+ | |||
+ | ==== Amplifier ==== | ||
+ | |||
+ | * TPA3116 | ||
+ | * "100 W" | ||
+ | * 12-24v (more volts = more power) | ||
+ | * Volume pot | ||
+ | * 3-pin header input or 3.5mm socket | ||
+ | |||
+ | Audio is input via the 3-pin header. | ||
+ | |||
+ | Power is input on the centre screw terminal, with left and right speaker outputs either side. | ||
+ | |||
+ | ==== Power Supply ==== | ||
+ | |||
+ | The system runs off a 19.5v laptop PSU located in the ceiling space. This is directly connected into the amplifier board, which is rated up to 24v. A spur from this connects to a DC-DC buck converter, supplying the Raspberry Pi with 5v. The original mini converter used was overheating and melting the heatshrink. It's now been replaced with a larger type which so far is running relatively cool. | ||
+ | |||
+ | Care should be taken when re-wiring as connecting the laptop PSU accidentally reverse polarity, to the speaker terminals, or to the speakers themselves will likely result in one or more of those being instantly destroyed. | ||
+ | |||
+ | {{ : | ||
+ | ==== Speakers ==== | ||
+ | |||
+ | * 8 Ohm | ||
+ | * 80 W | ||
+ | * Spade terminals | ||
+ | * Dual cone | ||
+ | |||
+ | Two wired in parallel to each channel, as per the following diagram. This roughly equates to 4 Ohm per channel, which is within the 4-8 Ohm spec of the amplifier. | ||
- | Pi lives above door. Connected to shit amp board. Amp board and speaker being replaced very soon - will document this then. | + | {{: |
squawk.1475667295.txt.gz · Last modified: 2016-10-05 11:34 by rob