Inspiration

I got inspired to do this project for SUSE Hack Week because I'm an indie folk musician and have yet to release music due to the 'perfectionist complex,' where nothing ever seems polished enough to share online. I'm also a backend engineer and have been learning Go in 2022, and when I found out Go has popular audio libraries I decided to learn how to build an audio streaming server to self-host my song drafts at a public URL that I can update with new versions and share with friends and other musicians.

What it does

Audio Streaming Server is a small, cross platform project with a backend that can run on a local machine, watches a folder for new .wav files, converts those files into mp3 when they appear, and loads them onto the server and self-hosts the music at an HTTPS public endpoint for on-demand streaming.

How I built it

Components

  • Audio processing services: fswatch, ffmpeg
  • Backend: streaming server written in Go, bash scripts
  • Media client: Squarespace

How does it work?

The backend of my project runs fswatch, a file change monitor, to create and watch an EXPORTED_DIR folder for new .wav files. When .wav files appear (in my case, I'd be exporting a live set from Ableton Live to that directory), my script converts all files in that folder to mp3 using ffmpeg, moves them to a PROCESSED_DIR to save the mp3 files, then copies the mp3 files to the server.

The server hosts the mp3 files at an HTTPS endpoint. The server uses go routines to run the file change monitor and streaming server concurrently.

The Squarespace website uses Audio Blocks to embed audio from the externally hosted audio files. So, once a song is loaded onto the server, I can add an audio block to the site with the URL https://localhost:8080/song-file-name.mp3 and it will appear as a playable widget on the page.

Challenges I ran into

  1. Design

This design was really interesting! I had to do a lot of research to understand how the components would fit together before I started writing any code. I knew that the server could host files at http://localhost:8080 but not much else! I toyed with the ideas of storing my audio files in a CMS and writing a backend API, writing a streaming server to serve HLS files (I actually ended up using Lane Wagner's tutorial but not for HLS files), and what media client to use and would accept the audio format I wanted to stream. It was a fun challenge finding the right puzzle pieces.

  1. Embedding Audio into a Website

How do I get my music into the website? This probably took the longest to figure out. I had a few options here: embedded vlc player, html5 audio tag, etc. Even though HLS audio file formats are popular (it breaks a stream into tiny HTTP-download files), many media clients only support wav and mp3 but not HLS. After experimenting with a few frontend platforms, I hit upon Squarespace Audio Blocks. It was perfect for what I needed but only supported mp3 files at HTTPS URLs. Queue challenge 3...

  1. Securing the Server with HTTPS

To get Squarespace to trust the audio file links, I had to convert my server from an HTTP server to an HTTPS server. Well, through this BEAST of an article, and Tosbourn's Tutorial Video, I created and installed a self-signed cert on my local keychain, modified its trust parameters, added my cert and private key to my server directory... and wah la!! HTTPS audio streaming server with a trusted cert.

Accomplishments that I'm proud of

I'm proud that...

  • I was able to combine music/programming in a project
  • I was able to complete an end-to-end solution from exporting a .wav file from Ableton Live to having that audio self-hosted on my own website.
  • My server runs concurrent Go processes
  • My website is so stylish

What I learned

I learned a lot for this project! Namely about,

  • On-demand streaming servers, CMS, HLS audio formats
  • Go routines
  • HTTP/HTTPS and getting OSx to trust a local self-signed certificate
  • How to create a Squarespace website
  • How Ableton Live saves/exports audio files
  • Bash scripting

What's next for Audio Streaming Server

Build an audio processor/mixer in Go to programmatically mix audio files. Transcoding/decoding is also an option. I could use the nareix joy4 for inspiration.

Built With

Share this project:

Updates