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

  1. Flash 32-Bit Raspian OS Lite into the sd card

  2. Log into the device via ssh:

ssh pi@dcaudioplayer.local
  1. Configure the device to auto-login into the console at boot by entering
sudo raspi-config
  1. Navigate to System Options > Boot / Autologin > Console Autologin confirm, 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:

    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

    1. Upgrade the system
    sudo apt update
    sudo apt full-upgrade
    1. Remove any previous Alsa Bluetooth driver and install the PulseAudio BT profile loader
    sudo apt purge bluealsa
    sudo apt install pulseaudio pulseaudio-module-bluetooth
    1. Add user pi to bluetooth user group
    sudo usermod -a -G bluetooth pi
    1. Switch on bluetooth speaker and then enter the bluetoothctl prompt
    bluetoothctl
    
    # scan on
    
    1. Find the MAC address of your device, e.g 00:AA:22:BB:33
    2. Pair and trust the device
    pair 00:AA:22:BB:33
    trust 00:AA:22:BB:33
    quit
    
    1. Create a script that connects the computer to the device
    makedir -p ~/scripts
    nano ~/scripts/autopair
    1. 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
    1. Make the script executable
    chmod +x ~/scripts/autopair
    1. Open the /boot/config.txt file and comment the line that turns snd_bcm2835 on like shown below, press CTRL+Xthen save the script by pressing enter
    sudo nano /boot/config.txt
    #Enable audio (loads snd_bcm2835)
    #dtparam=audio=on
    1. Create a python script called on.py
    makedir -p ~/python
    nano ~/pyhton/on.py
    1. 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()
    1. Make the script executable
    chmod +x ~/python/on.py
    1. Change your .bashrc file to automatically start pulseaudio & run the python script.
    nano ~/.bashrc
    1. Go to the end of the file in the texteditor and add…
    pulseaudio --start
     
    wait
    ~/python/on.py
    1. Reboot and test. (I found it helpful to switch the speaker on after the computer had booted)
    Link to original

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 .bashrc file:

pulseaudio --start
amixer -D pulse sset Master 35%
 
wait
~/python/on.py
Link to original

Transfer files via ssh

To transfer fies from your computer to dcaudioplayeruse:

scp /path/to/file.wav pi@dcaudioplayer:~/file.wav

Looping 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 mplayer

Next, 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.py

That should be it! Reboot and test a couple of times to see if it works!