webcaster

big balls of mud killer
, in 05 September 2014

My helpful screenshot

Streaming to icecast/liquidsoap directly from the browser

Toots, one of the main liquidsoap developers, has been working on a very exciting tool that allows you to stream directly to liquid soap from a web browser. Imagine if your DJs could start broadcasting on your radio without needing to download any software!

Technologies at hand

Here is the flowchart from the webcast project itself. webcast flow

The main technologies that make this possible are websockets and emscripten. There is a websocket endpoint on liquidsoap that receives the mp3 data. Emscripten is used to compile the libshine fixed point encoding library to Javascript. Read more about how emscripten works here if you are interested.

Getting started

Toots has released the Javascript library here and has an example client application here.

I’ll show you how to set up liquidsoap to use the example application.

The webcast.js repository contains the simplest possible example.

Just run this liquid soap line:

liquidsoap "output.ao(fallible=true,audio_to_stereo(input.harbor('mount',port=8080)))"`

Toots also has an example client for testing: https://github.com/webcast/webcaster

There are a few git submodule dependencies in this repository you’ll need to checkout. Run git submodule init and git submodule update to fetch them.

Check it out and run make, then run make test to start the server. Access the client in your web browser on localhost:8000.

The easiest way to get some sound going is to upload some mp3s to this cute little web based mixer. You can try the microphone as well.

Click ‘Start Streaming’ to connect. You are able to set bitrate, samplerate, and stereo or mono output. You can change the stream destination URI if your liquidsoap harbor is on a different IP or port.

The webworker option is for performance reasons. MP3 encoding is CPU intensive to begin with, let alone in Javascript, so this option is recommended.

Check the output of liquidsoap and you should see that a client connected to the harbor. Since you’re using the libao output you should hear sound immediately!

gif action

You can use this setup with your usual icecast/shoutcast based liquidsoap configurations as well.

But wouldn’t it be nice if…

Now, the microphone input works well. For me, I’d like to stream directly from Traktor to this. If you’re looking to stream from audio software already running on your system, you might be out of luck as it looks like only microphone/line-in can be captured. You could use something like soundflower to route your computer’s output to input, but that’s another article.

Luckily Traktor and similar software already supports broadcasting to icecast anyway, so I guess its not really an issue.

I’m currently writing a book about liquidsoap!

Modern Online Radio with Liquidsoap Book - Free Sample

Need more help with liquidsoap? Can’t get your script to work?

I wrote a book to help you learn Liquidsoap. The book covers all aspects of liquidsoap, from getting started, to making dynamic streams, audio processing, video, customizing metadata, authentication, and more. The book is available for purchase now here!

You can get a free sample chapter of my book! Just enter your email address to subscribe to my mailing list and I'll send you a free PDF sample of the book in return.