Senior (sensory impaired) adapted HW audio book player with radio and auto-generated daily update (Raspberry Pi Zero)
My dad is practically blind and at 80 years has trouble hearing and operating tiny or more complicated electronics controls. Touch screens, smart phones, keyboards, and small mp3 players are completely out of the picture. I have tried using small dummy MP3 player (Sencor) with 5 buttons (prev, next, play|pause, volume up/down) as an initial assessment whether audio book player is something he would be able to control. Even though he used it, he was struggling with controlling it and the small player with 2-3x overloaded button controlls was too much. Also it lacked a fundamental option of remote book update. So I've decided to build custom player with following requirements:
run raspi-config and set the system up Install some system packages.
sudo apt-get install python3 evtest mpd mpc ntp vim screen git pigpiod libasound2-dev ffmpeg
Create data dir
sudo mkdir /data && sudo chown pi /data && chmod 755 /data
Edit /etc/mpd.conf and change directory to /data
music_directory "/data"
Add audio device definition
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:1,0" # optional
}
Set the rotary encoder overlay and disable Bluetooth and onboard audio adding to /boot/config.txt
# add rotary encoder
dtoverlay=rotary-encoder,pin_a=19,pin_b=26,relative_axis=1
# disable builtin audio - we are using external usb card
dtparam=audio=off
# disable BT
dtoverlay=disable-bt
# Disable arm boost
arm_boost=0
# Disable vc4-kms-v3d audio
dtoverlay=vc4-kms-v3d,audio=off
Edit /usr/share/alsa/alsa.conf
defaults.ctl.card 1
defaults.pcm.card 1
Set static address and resolvers in /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.1.30/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
Crontab under user to fetch into /data/.news.mp3
crontab -e
*/5 * * * * /usr/bin/curl -L -f -s -o /data/tmp/.news.mp3 https://www.uid0.sk/users/adino/dl/news.mp3
* * * * * /home/pi/Pi0AudioBook/time_and_newsgen.sh > /dev/null 2>&1
*/5 * * * /home/pi/Pi0AudioBook/zurnal.sh > /dev/null 2>&1
Due to the system using flash, it might happen that the SD card eventually wears out. There are couple of things we can do to prevent this. Disable swap and frequent writers.
apt-get remove --purge wolfram-engine triggerhappy anacron logrotate xserver-common lightdm
apt-get autoremove --purge
Edit /etc/dphys-swapfile
and set CONF_SWAPSIZE=0
Verify with free
, swap should be 0.
Edit /etc/mpd.conf
and make log_file
log to /var/lib/mpd
rather than /var/log/mpd
.
log_file /var/lib/mpd/mpd.log"
In mpd.conf add entry for audio card:
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:1,0" # optional
}
Modify /etc/fstab
and add:
tmpfs /tmp tmpfs defaults,noatime,nosuid,size=100m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/lib/mpd tmpfs defaults,noatime,nosuid,size=30m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
tmpfs /data/tmp tmpfs defaults,noatime,nosuid,mode=0777,size=100m 0 0
/var/log
is optional. It should not be very busy with mpd now logging to /var/lib/mpd. Use iotop -o -b -d 10
to check what is writing to the flash.
Add ~/.bash_aliases
with two helpers:
alias knihaeject='sudo service mpd stop; sudo service knihaui stop; rm -fr /data/*.mp3'
alias knihaload='sudo service mpd start && sudo service knihaui start'
Use venv for managing dependencies
sudo apt-get install python3-venv
python3 -mvenv env
activate env with `source env/bin/activate`
pip3 install gpiozero
pip3 install pigpio
pip3 install python-mpd2
pip3 install evdev
pip3 install pyalsaaudio
pip3 install --upgrade google-api-python-client
pip3 install google-cloud-texttospeech
pip3 install beautifulsoup4
Service setup
sudo cp *.service /etc/system.d/system # or create symlinks
sudo systemctl daemon-reload
sudo systemctl enable wifi-restart
sudo systemctl enable knihaui
systemctl enable kniha-newsinit.service
/data
on the root writable by pi user./etc/rc.local
is modified to disable video output, set PCM volume to 100, set IO pins and set permissions on /data
source /home/pi/Pi0AudioBook/knihaui-init.sh
wifi_restart.sh
and related service definition to automatically ping and restart wifi./etc/systemd/system/knihaui.service
takes care of running the UI.systemctl enable knihaui
./data
for media directory.export GOOGLE_APPLICATION_CREDENTIALS=env/newsgen-credentials.json
source env/bin/activate
python3 newsgen.py
creates /tmp/news.mp3
if successfulListen to Example brief in Slovak here
Automate with crontab.
V0 was the set of scripts to slice larger audio books into manageable small files suitable for dumb players. This also allowed to prepend "chapter X" voice at the start of each slice.
V1 is the physical build with buttons that my dad is using right now.