You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.0 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # Announcement Box
  2. Linux box with a loudspeaker and an emergency light to be used for announcements and notifications.
  3. ## Hardware
  4. * SBC with GPIOs and sound output :: OrangePi Zero with an expansion board
  5. * PA system
  6. * speaker :: 30W, 4 Ohms horn loudspeaker
  7. * sound amplifier :: mono 18W sound amplifier
  8. * relay module :: 12V low trigger relay
  9. * Warning Light system
  10. * warning light :: 12V 10W rotary orange warning light
  11. * relay module :: 12V low trigger relay
  12. ## Software
  13. * Operating System - Linux :: Armbian Bullseye for the OrangePi Zero
  14. * PA System
  15. * Voice Synthesizer :: Festival / ESpeak
  16. ## Implementation Notes
  17. ### Armbian + OrangePi Zero Installation
  18. #### Enable analog soundcard
  19. ```
  20. sudo armbian-config
  21. # System > Hardware > [*] analog-codec
  22. ```
  23. #### Software Dependencies
  24. ##### OS Packages
  25. ```bash
  26. apt install mplayer espeak-ng
  27. ```
  28. ##### GPIO toolkit
  29. ```bash
  30. # upstream:
  31. #git clone https://github.com/orangepi-xunlong/wiringOP
  32. # enhanced:
  33. git clone https://github.com/Dejvino/wiringOP
  34. cd wiringOP
  35. ./build clean
  36. ./build
  37. ```
  38. #### Initialize GPIOs
  39. ```bash
  40. # System Activity Indicator
  41. PIN_SALIGHT=11
  42. gpio mode $PIN_SALIGHT output
  43. # Emergency Light system
  44. PIN_ELIGHT=7
  45. gpio mode $PIN_ELIGHT output
  46. # PA system
  47. PIN_PASOUND=5
  48. gpio mode $PIN_PASOUND output
  49. ```
  50. ### PA System
  51. #### Text to Speech
  52. ```bash
  53. ## Festival
  54. # reading
  55. ...
  56. # to file
  57. text2wave text.txt > wave.wav
  58. ## ESpeak
  59. # voices:
  60. ls /usr/lib/arm-linux-gnueabihf/espeak-data/voices/
  61. # reading
  62. espeak -f text.txt -p 40 -s 160 -v "en-us"
  63. # to file
  64. espeak -f text.txt -p 40 -s 160 -k15 -g 1 -w wave.wav
  65. # using SSML (e.g.: https://www.xml.com/pub/a/2004/10/20/ssml.html)
  66. espeak -f ssml.txt -m
  67. ```
  68. #### Converting into a low-quality broadcast audio
  69. ```bash
  70. sox infile.wav outfile.wav downsample echo 0.5 1 1 1
  71. ```
  72. #### Playing a sound file
  73. ```bash
  74. aplay file.wav
  75. mplayer file.mp3
  76. ```
  77. ### Emergency Light
  78. #### Control Script
  79. ```bash
  80. cat /usr/local/bin/emergency-light
  81. #!/bin/bash
  82. PIN_ELIGHT=7
  83. # init
  84. gpio mode $PIN_ELIGHT output
  85. # command
  86. if [[ "$1" == "on" ]]; then
  87. gpio write $PIN_ELIGHT 1
  88. elif [[ "$1" == "off" ]]; then
  89. gpio write $PIN_ELIGHT 0
  90. elif [[ "$1" == "read" ]]; then
  91. gpio read $PIN_ELIGHT
  92. else
  93. gpio toggle $PIN_ELIGHT
  94. fi
  95. ```
  96. ### System Activity Light
  97. #### System Usage
  98. ```bash
  99. uptime | head -n 1 | cut -f3 -d, | cut -f2 -d:
  100. ```
  101. #### Daemon
  102. ```bash
  103. cat /etc/systemd/system/system-activity-light.service
  104. [Unit]
  105. Description=System Activity Light Daemon
  106. [Service]
  107. ExecStart=/usr/sbin/system-activity-light-daemon
  108. [Install]
  109. WantedBy=multi-user.target
  110. ```
  111. ```bash
  112. cat /usr/sbin/system-activity-light-daemon
  113. #!/bin/bash
  114. DELAY=10000
  115. while [[ true ]]; do
  116. ACTIVITY=2000
  117. TOP=`system-usage`
  118. if (( $(echo "$TOP > 1.0" | bc -l) )); then
  119. ACTIVITY=50
  120. elif (( $(echo "$TOP > 0.75" | bc -l) )); then
  121. ACTIVITY=100
  122. elif (( $(echo "$TOP > 0.5" | bc -l) )); then
  123. ACTIVITY=500
  124. elif (( $(echo "$TOP > 0.2" | bc -l) )); then
  125. ACTIVITY=1000
  126. fi
  127. echo $TOP
  128. system-activity-light blink $ACTIVITY $DELAY
  129. done
  130. ```
  131. ```bash
  132. sudo systemctl enable --now system-activity-light.service
  133. ```