Add README

This commit is contained in:
Dejvino 2020-12-14 14:20:54 +01:00
parent c93c5acc41
commit 22a3878e3c

161
README.md Normal file
View File

@ -0,0 +1,161 @@
# Announcement Box
Linux box with a loudspeaker and an emergency light to be used for announcements and notifications.
## Hardware
* SBC with GPIOs and sound output :: OrangePi Zero with an expansion board
* PA system
* speaker :: 30W, 4 Ohms horn loudspeaker
* sound amplifier :: mono 18W sound amplifier
* relay module :: 12V low trigger relay
* Warning Light system
* warning light :: 12V 10W rotary orange warning light
* relay module :: 12V low trigger relay
## Software
* Operating System - Linux :: Armbian Bullseye for the OrangePi Zero
* PA System
* Voice Synthesizer :: Festival / ESpeak
## Implementation Notes
### Armbian + OrangePi Zero Installation
#### Enable analog soundcard
```
sudo armbian-config
# System > Hardware > [*] analog-codec
```
#### Software Dependencies
##### OS Packages
```bash
apt install mplayer espeak-ng
```
##### GPIO toolkit
```bash
# upstream:
#git clone https://github.com/orangepi-xunlong/wiringOP
# enhanced:
git clone https://github.com/Dejvino/wiringOP
cd wiringOP
./build clean
./build
```
#### Initialize GPIOs
```bash
# System Activity Indicator
PIN_SALIGHT=11
gpio mode $PIN_SALIGHT output
# Emergency Light system
PIN_ELIGHT=7
gpio mode $PIN_ELIGHT output
# PA system
PIN_PASOUND=5
gpio mode $PIN_PASOUND output
```
### PA System
#### Text to Speech
```bash
## Festival
# reading
...
# to file
text2wave text.txt > wave.wav
## ESpeak
# voices:
ls /usr/lib/arm-linux-gnueabihf/espeak-data/voices/
# reading
espeak -f text.txt -p 40 -s 160 -v "en-us"
# to file
espeak -f text.txt -p 40 -s 160 -k15 -g 1 -w wave.wav
# using SSML (e.g.: https://www.xml.com/pub/a/2004/10/20/ssml.html)
espeak -f ssml.txt -m
```
#### Converting into a low-quality broadcast audio
```bash
sox infile.wav outfile.wav downsample echo 0.5 1 1 1
```
#### Playing a sound file
```bash
aplay file.wav
mplayer file.mp3
```
### Emergency Light
#### Control Script
```bash
cat /usr/local/bin/emergency-light
#!/bin/bash
PIN_ELIGHT=7
# init
gpio mode $PIN_ELIGHT output
# command
if [[ "$1" == "on" ]]; then
gpio write $PIN_ELIGHT 1
elif [[ "$1" == "off" ]]; then
gpio write $PIN_ELIGHT 0
elif [[ "$1" == "read" ]]; then
gpio read $PIN_ELIGHT
else
gpio toggle $PIN_ELIGHT
fi
```
### System Activity Light
#### System Usage
```bash
uptime | head -n 1 | cut -f3 -d, | cut -f2 -d:
```
#### Daemon
```bash
cat /etc/systemd/system/system-activity-light.service
[Unit]
Description=System Activity Light Daemon
[Service]
ExecStart=/usr/sbin/system-activity-light-daemon
[Install]
WantedBy=multi-user.target
```
```bash
cat /usr/sbin/system-activity-light-daemon
#!/bin/bash
DELAY=10000
while [[ true ]]; do
ACTIVITY=2000
TOP=`system-usage`
if (( $(echo "$TOP > 1.0" | bc -l) )); then
ACTIVITY=50
elif (( $(echo "$TOP > 0.75" | bc -l) )); then
ACTIVITY=100
elif (( $(echo "$TOP > 0.5" | bc -l) )); then
ACTIVITY=500
elif (( $(echo "$TOP > 0.2" | bc -l) )); then
ACTIVITY=1000
fi
echo $TOP
system-activity-light blink $ACTIVITY $DELAY
done
```
```bash
sudo systemctl enable --now system-activity-light.service
```