User Tools

Site Tools


squawk

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
squawk [2016-10-09 22:28] timsquawk [2023-11-25 23:45] (current) – Added playlist command jaso55555
Line 1: Line 1:
-====== Audio Alerts ======+====== Audio Alerts (squawk) ======
  
-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 a pi (original B) for the purpose and documents it thus:+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 a pi (original B), amplifier and speakers for the purpose and documents them thus:
  
 ===== Usage ===== ===== Usage =====
Line 9: Line 9:
 Examples for testing might be something like: Examples for testing might be something like:
  
 +Play a sound file:
 +<code>
 +mosquitto_pub -h mqtt -t 'sound/g1/play' -m canttouchthis.mp3
 +</code>
 +Play a list of sound files with no gap:
 +<code>
 +mosquitto_pub -h mqtt -t 'sound/g1/playlist' -m "long_long_man/long.mp3,long_long_man/loooong.mp3,long_long_man/maaaan.mp3"
 +</code>
 +Text-to-speech message (with a subtle notification bong):
 <code> <code>
-mosquitto_pub -h mqtt -t 'sound/g1/play' -m dong.mp3 
 mosquitto_pub -h mqtt -t 'sound/g1/speak' -m "All your base are belong to us" mosquitto_pub -h mqtt -t 'sound/g1/speak' -m "All your base are belong to us"
 </code> </code>
 +Text-to-speech message (with a clear airport/transit chiming sound):
 +<code>
 +mosquitto_pub -h mqtt -t 'sound/g1/announce' -m "Good evening, my sensors indicate that the laser cutter may be on fire."
 +</code>
 +
 +**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://squawk.hacklab:8080/.
  
 ===== Raspbian ===== ===== Raspbian =====
Line 46: Line 64:
  
 <code> <code>
-su -c "mpg123 /home/pi/sounds/indyboot.mp3" pi &+su -c "/home/pi/startup.sh" pi &
 su -c "/home/pi/respawn --syslog --max-backoff=10 /home/pi/squawk.py" pi & su -c "/home/pi/respawn --syslog --max-backoff=10 /home/pi/squawk.py" pi &
 </code> </code>
Line 122: Line 140:
                 candidates.append(f)                 candidates.append(f)
         if len(candidates) == 0:         if len(candidates) == 0:
-            raise Exception('No files matching %s' % (filename))+            logging.error('No files matching %s' % (filename)) 
 +            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:
-            raise Exception('File %s not found' % (filename)) +            logging.error('File %s not found' % (filename)) 
 +            return
     base, ext = os.path.splitext(filename)     base, ext = os.path.splitext(filename)
     if ext == '.mp3':     if ext == '.mp3':
-        command = ['mpg123', '-q', filename]+        command = ['mpg123', '-q', '-m', filename]
         call_with_timeout(command, timeout=timeout)         call_with_timeout(command, timeout=timeout)
     else:     else:
Line 140: Line 159:
     client.subscribe("sound/g1/play")     client.subscribe("sound/g1/play")
     client.subscribe("sound/g1/speak")     client.subscribe("sound/g1/speak")
 +    client.subscribe("sound/g1/announce")
 +    client.subscribe("display/doorbot/intercom")
 +    client.subscribe("labstatus")
  
 def on_message(client, userdata, msg): def on_message(client, userdata, msg):
Line 166: Line 188:
         speak(msg.payload)         speak(msg.payload)
  
-    if msg.topic == 'display/doorbot/intercom': +    if msg.topic == 'access/entrance/request': 
-        if msg.payload == '1' and status == 'closed':+        if status == 'closed':
             play('doorbell.mp3')             play('doorbell.mp3')
  
Line 326: Line 348:
 play -q /tmp/pico.wav play -q /tmp/pico.wav
 rm -f /tmp/pico.wav rm -f /tmp/pico.wav
 +</code>
 +
 +==== /home/pi/startup.sh ====
 +
 +<code bash>
 +#!/bin/bash
 +sleep 3
 +_IP4=$(hostname -I | cut -d ' ' -f 1) || true
 +
 +mpg123 -m -q /home/pi/sounds/indyboot.mp3
 +/home/pi/pico.sh "System boot complete. IP address is $_IP4"
 </code> </code>
  
 ===== Audio files ===== ===== Audio files =====
  
-These live in /home/pi/sounds and can be wav or mp3. SCP new ones into here.+These live in /home/pi/sounds and can be wav or mp3. Generally prefer mp3. SCP new ones into here.
  
 <code> <code>
Line 366: Line 399:
  
 ===== Hardware ===== ===== Hardware =====
 +{{ :photo_2016-10-10_16-35-17.jpg?direct&200|}}
 +The "squawk" unit lives above the IRC terminal, to the right of the main door in G1. It consists of a Raspberry Pi B and a TPA3116 based amplifier board.
 +
 +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.png?nolink|}}
 +==== 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 doorConnected to shit amp boardAmp board and speaker being replaced very soon will document this then.+{{:photo_2016-10-10_16-39-03.jpg?direct&200 |}} {{:photo_2016-10-10_16-39-09.jpg?direct&200 |}} {{:photo_2016-10-10_16-39-10.jpg?direct&200 |}} {{:photo_2016-10-10_16-39-12.jpg?direct&200 |}}
squawk.1476052089.txt.gz · Last modified: 2016-10-09 22:28 by tim

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki