In order to play some of the recordings in a loop, we chose a raspberry pi zero W and configured it to connect to a bluetooth speaker upon boot (more information on this can be found in Bluetooth speakers).
Setup
-
Flash 32-Bit Raspian OS Lite into the sd card
-
Log into the device via ssh:
ssh pi@dcaudioplayer.local- Configure the device to auto-login into the console at boot by entering
sudo raspi-config- Navigate to
System Options > Boot / Autologin > Console Autologinconfirm, select finish and reboot. For increased reliability of the standalone player, also configure it not to wait for network at boot by
- Follow the steps outlined below
Bluetooth speakers
A key challenge in setting up kiosk mode for our use case, is to set the computer up to automatically connect to the bluetooth speakers used in the Sound Showers.
Two helpful tutorials were used to set it up:
- https://raspberrypi.stackexchange.com/questions/53408/automatically-connect-trusted-bluetooth-speaker
- https://www.okdo.com/project/set-up-a-bluetooth-speaker-with-a-raspberry-pi/
After just going through the top-rated answer of the first one, the computer didn’t connect automatically, but the first steps of the second one seem to have fixed it. So, here’s the gist of the process
- Upgrade the system
sudo apt update sudo apt full-upgrade- Remove any previous Alsa Bluetooth driver and install the PulseAudio BT profile loader
sudo apt purge bluealsa sudo apt install pulseaudio pulseaudio-module-bluetooth- Add user
pito bluetooth user group
sudo usermod -a -G bluetooth pi- Switch on bluetooth speaker and then enter the
bluetoothctlprompt
bluetoothctl # scan on- Find the MAC address of your device, e.g 00:AA:22:BB:33
- Pair and trust the device
pair 00:AA:22:BB:33 trust 00:AA:22:BB:33 quit- Create a script that connects the computer to the device
makedir -p ~/scripts nano ~/scripts/autopair- Paste the following code into the text editor, press
CTRL+Xthen save the script by pressing enter
#!/bin/bash bluetoothctl << EOF connect 00:AA:22:BB:33 EOF- Make the script executable
chmod +x ~/scripts/autopair- Open the
/boot/config.txtfile and comment the line that turnssnd_bcm2835on like shown below, pressCTRL+Xthen save the script by pressing enter
sudo nano /boot/config.txt#Enable audio (loads snd_bcm2835) #dtparam=audio=on- Create a python script called
on.py
makedir -p ~/python nano ~/pyhton/on.py- Paste the following code into the text editor, press
CTRL+Xthen save the script by pressing enter
#!/usr/bin/python # # Monitor removal of bluetooth reciever import os import sys import subprocess import time def blue_it(): status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) while status == 0: print("Bluetooth UP") print(status) time.sleep(15) status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) else: waiting() def waiting(): subprocess.call('killall -9 pulseaudio', shell=True) time.sleep(3) subprocess.call('pulseaudio --start', shell=True) time.sleep(2) status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) while status == 2: print("Bluetooth DOWN") print(status) subprocess.call('~/scripts/autopair', shell=True) time.sleep(15) status = subprocess.call('ls /dev/input/event0 2>/dev/null', shell=True) else: blue_it() blue_it()- Make the script executable
chmod +x ~/python/on.py- Change your
.bashrcfile to automatically start pulseaudio & run the python script.
nano ~/.bashrc- Go to the end of the file in the texteditor and add…
pulseaudio --start wait ~/python/on.py- Reboot and test. (I found it helpful to switch the speaker on after the computer had booted)
Adjusting the volume
As we do not have interactive control of the volume of the speaker, we need to the volume via the terminal. This can be done via:
amixer -D pulse sset Master 50%When used in conjunction with the Sound Showers, we’ve found a level of 35% to be adequate.
To do this at startup, simply add it to the
.bashrcfile:Link to original pulseaudio --start amixer -D pulse sset Master 35% wait ~/python/on.py
Transfer files via ssh
To transfer fies from your computer to dcaudioplayeruse:
scp /path/to/file.wav pi@dcaudioplayer:~/file.wavLooping audio at boot
To play audio after startup, we can add a suitableshell command to the end of the .bashrc.
First, we need to install an audio player and the relevant codecs to play an mp3-file on loop. I’ll use mplayer.
sudo apt install mplayerNext, we add the command that starts the loop into our .bashrc file
pulseaudio --start
amixer -D pulse sset Master 35%
mplayer -loop 0 ~/test.mp3 </dev/null >/dev/null 2>&1 &
wait
~/python/on.pyThat should be it! Reboot and test a couple of times to see if it works!