Reading expands the mind, but sometimes pulling a 600-page tome out of your pocket just isn’t practical. You can’t indulge in classic prose while driving a car, for example. This is where audiobooks come in, giving you the benefit of a narrated literary experience without forcing you to take your eyes off the road. With audiobooks, you can consume fantastic literature while driving, washing dishes, or even working.
While there are plenty of audiobook subscription services out there, it’s far more satisfying to build and host your own library on a Raspberry Pi.
What is an audio library?
Audiobookshelf is a self-hosted audiobook and podcast server. This means that you can deploy it yourself on a VPS (virtual private server) or on your own hardware at home and access it via the Internet, streaming and downloading stories via a phone or a dedicated app.
A Raspberry Pi is ideal for this project. You will need to know its local IP address, as well as a static IP address and domain name.
How to install Audiobookshelf on Raspberry Pi
Once you have installed an operating system on your Raspberry Pi, connect using SSH (Secure Shell).
ssh username@local.pi.ip.address
Replace username and local.ip.ip.address with details of your own Raspberry Pi. Now follow the next steps to install Audiobookshelf.
- Update and upgrade all installed packages:
sudo apt update
sudo apt upgrade - Install the Apache2 reverse proxy so you can access Audiobookshelf from outside your home:
sudo apt install apache2
- And certbot, which you will use later to generate security keys and certificates to secure your connection:
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt-get install python3-certbot-apache - Docker is a means by which developers can make it easier for the end user to create, run and update software packages:
sudo apt install docker.io
- Add your user to the docker group:
sudo usermod -aG docker your_user_name
- Start and activate Docker with:
sudo systemctl start docker
sudo systemctl enable docker - Docker-compose is a tool that simplifies the management of Docker containers:
sudo apt install docker-compose
- From your home directory, create a new directory called sound librarythen CD inside and create four more directories:
cd audiobookshelf
mkdir audiobooks
mkdir podcasts
mkdir config
mkdir metadata - Go back to your home directory and create a new docker-compose file:
cd ~
nano docker-compose.ymlAnd paste the following into it:
version: '3.5'
services:
audiobookshelf:
container_name: audiobookshelf
image: ghcr.io/advplyr/audiobookshelf:latest
environment:
- AUDIOBOOKSHELF_UID=99
- AUDIOBOOKSHELF_GID=100
ports:
- 13378:80
volumes:
- /home/your-user-name/audiobookshelf/audiobooks:/audiobooks
- /home/your-user-name/audiobookshelf/podcasts:/podcasts
- /home/your-user-name/audiobookshelf/config:/config
- /home/your-user-name/audiobookshelf/metadata:/metadataThe only parts you will need to modify are the directory paths. Save and exit nano with CTRL+O then CTRL+X.
- The command:
docker-compose pull
will pull all the necessary images to your Pi, and:
docker-compose up -d
will start the containers. Audiobookshelf is now running.
Setting up an audio library from your home network
Audiobookshelf is now accessible from your home network, but not from the Internet. It is recommended to perform initial setup before connecting to the internet and obtaining SSL certificates, as malicious actors monitor certificate logs to see when new sites come online, and they may be able to take control during this period.
Access the Audiobookshelf front-end by typing your.pi.ip.address:13378 in any browser. You will be prompted to configure a root user account and password.
Make sure to choose a strong password that cannot be easily guessed. You will then be prompted to log in with the credentials you just created.
At this point, Audiobookshelf will prompt you to Add your first library, and will ask you to select books or podcasts, give the library a name, and search for the library. As Audiobookshelf only has access to the specified directories in your docker-compose.ymlthe location for this is /audio books. Select this, then click Create a new library.
Audiobookshelf doesn’t have any audiobooks because at this point you haven’t added any. On the computer where your audiobooks are stored, use PuTTY or the terminal to transfer your library to the correct location on the Raspberry Pi.
scp -r /path/to/your/audiobook/directory
Depending on the size of your collection, this process can take several hours. Once it’s finished and you’ve returned to the prompt, return to Audiobookshelf in your browser and press green To analyse button.
Audiobookshelf will now attempt to identify your audiobooks using vendors such as Apple, Audible, and Google to determine chapter markers, author, narrator, synopsis, and whether the books are part of a series. Once complete, your library will be populated, categorized, and searchable.
You will be able to easily navigate between screens using buttons arranged vertically along the left edge of the screen. House is divided into sections showing what you are currently reading, the next book in the series, recently added audiobooks, and recently added series. At the very bottom, there are images of authors and narrators. You can click on it to see a potted biography.
Other screens include Librarywhich displays the individual covers of each book in your audio books phone book; series; collections; and authors. All of these will show exactly what you expect from them.
To start listening to an audiobook, click on the cover and press To play. Audiobookshelf will remember your location for you.
Access the audio library from outside your home
Listening to a good audiobook sitting in an armchair in front of the fireplace at home is a pleasant experience, but you probably want to access your stories from outside the house. To do this, you will need to direct requests for your domain name to port 13378 on your Raspberry Pi.
- In the terminal or SSH client:
cd /etc/apache2/sites-available
- Create a new file with nano:
sudo nano audiobookshelf.conf
- Enter the following:
<VirtualHost *:80> ServerName your-domain-name.tld ProxyPreserveHost On ProxyPass / http://your.local.pi.ip.address:13378/ RewriteEngine on RewriteCond %{HTTP:Upgrade} websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/?(.*) "ws://your.local.pi.ip.address:13378/$1" [P,L] </VirtualHost>
You will need to replace your.local.ip.pi.address with the real local IP address of your Pi and the value of Server name must be the domain name you want to use. Save and exit nano with CTRL+O then CTRL+X.
- Activate your new configuration file with:
sudo a2ensite audiobookshelf.conf
- Restart Apache2:
sudo service apache2 restart
- Your Audiobookshelf instance is now accessible on the Internet via an HTTP connection. It’s not secure, so use certbot to get certificates and keys from Let’s Encrypt:
sudo certbot
- Select your domain name from a list and choose redirect when asked.
- You will need to restart Apache one more time for the changes to take effect.
sudo service apache2 restart
All connection attempts made over HTTP will be automatically upgraded to HTTPS, making your connection more secure.
Where can you find books for Audiobookshelf?
Audiobookshelf can stream all audio formats on the fly, including popular MP3, M4A, and M4B formats. You can find DRM-free audiobooks at Downpour and LibriVox. A thorough web search will reveal more independent locations and retailers.
You have successfully deployed your own audiobook library to your Raspberry Pi!
You have access to a whole world of storytelling at your fingertips. Why not diversify your reading habits and start with a new genre? Mysteries, cozy romances and explosive thrillers are all here for the fun. You could even learn a new language and listen to your old favorites in another language.