DEV Community

Cover image for Bringing Web Radios Back to FM
Douxx
Douxx

Posted on

Bringing Web Radios Back to FM

When going on vacation, I listen to local radios stations using a small portable radio that I bring with me. I absolutely love doing this as the music often changes of what I'm used to, and it makes me discover new things.

One of those radios I love listening to is the RTL 102.5, an italian radio. I always listen to it when I go on a trip in Italy. However, it only is a national station and doesn't broadcast in other countries such as Switzerland.

A good way of continuing to listen to programs that aren't broadcasted on FM are web radios, and you'll ask me, why don't I want to listen to them ? They're near perfection, they're live, have a good audio quality, and much more !

And the answer is in the question. They're perfect. I find that this perfection breaks the charm of FM. Having lossless 96kHz in your headset doesn't have the same vibe at all than getting a signal from a tower being at hundreds of kilometers from your tiny 15 bucks portable radio.

So in this article, I'll try to take a live stream from the RTL 102.5 web radio, and broadcast it in my house, on FM.

As always, here is an overview of what I'll be doing:

  • ☐ Finding a way of broadcasting FM on a short range
  • ☐ Getting the audio source for the web radio stream
  • ☐ Putting both together
  • ☐ Automate everything
  • ☐ Enjoy !

Figuring Out What I Even Need

As I just said, I only need two things:

  • A device being able to broadcast FM radio
  • A stream from where I can get the live radio feed

And great news, I already have an idea on how to get them !

1: The broadcaster

This is the easiest part of this article, since I literally made a software being able to do that, and I won't hesitate to use it !

For those who don't know it, it's BotWave, a software that lets you easily play files and live feeds on FM using a Raspberry Pi.

2: The source

What I initially wanted to do was simple: Go to radio-browser.info, a library of almost every "big" web radios that documents a lot of information about them, but more importantly, the stream url.

So I went on the website, searched for RTL 102.5, found it, and got this stream url:

https://dd782ed59e2a4e86aabf6fc508674b59.msvdn.net/live/S97044836/tbbP8T1ZRPBL/playlist_audio.m3u8

Sadly, once I opened it up in my browser, I saw that it was a dead link and that nothing was served anymore :/

So it's time for the fallback plan ! Find the stream url directly on the website !

It sounds like an epic thing, but it's really not much, I just went on the website player, and then checked for any m3u files in the network tab of the devtools.

The network tab

And I found it:

https://streamcdnb1-dd782ed59e2a4e86aabf6fc508674b59.msvdn.net/live/S97044836/WjpMtPyNjHwj/playlist_audio.m3u8

And this one actually works !

Ok so just like that, we got the first two points:

  • Finding a way of broadcasting FM on a short range
  • Getting the audio source for the web radio stream

Getting That Stream on FM

I already had an idea on how to do that, but I'll have to check if it works. I'm planning on using FFmpeg, basically the swiss-knife of audio, video, and image editing.

Step 1: Test it

I'll start by trying to record 5 seconds of the stream, and put them in a .wav file.

And, surprisingly, I succeeded first try, which is pretty unusual :]

Here is the command:

ffmpeg -i "https://streamcdnb1-dd782ed59e2a4e86aabf6fc508674b59.msvdn.net/live/S97044836/WjpMtPyNjHwj/playlist_audio.m3u8" -t 5 test.wav
Enter fullscreen mode Exit fullscreen mode

It takes the stream in input, and converts 5 seconds of it in the wave format to save it !

Step 2: Put it Into Practice

BotWave exposes a sound card in which we can input audio, and it will play it live. So all we have to do is, instead of outputting the audio into a wave file, we output it directly in the sound card !

ffmpeg -i "https://streamcdnb1-dd782ed59e2a4e86aabf6fc508674b59.msvdn.net/live/S97044836/WjpMtPyNjHwj/playlist_audio.m3u8" -f alsa plughw:BotWave
Enter fullscreen mode Exit fullscreen mode

I removed the time limit so it plays indefinitely, and the other stuff redirects the sound to the sound card.

Step 3: Broadcasting it

The last step is actually telling the software to take the card output and broadcast it.

sudo bw-local
botwave> live 102.5 "RTL 102.5" "aka.dbo.one/webtofm"
botwave> # This plays at 102.5 FM, with the name and desc
Enter fullscreen mode Exit fullscreen mode

Now let's check if we got anything on radio !

And yes ! We can see the broadcast on the spectrum, and if we stop the broadcast, it disappears:

  • Putting both together

Automating Everything

It works, but currently it's kinda painful to setup, we need to get into the pi shell, two times actually, run ffmpeg and then BotWave, and leave it open.

So what I'll do is automating it, and it's surprisingly simple !

First, I'll create a file that will execute at the moment where BotWave starts.

sudo bw-nandl l_onready_webtofm.hdl
Enter fullscreen mode Exit fullscreen mode

nano editor

Inside, I put the ffmpeg command and the live instruction, so this will run ffmpeg in the background, and then start the broadcast automatically.

Now, when we run bw-local, the broadcast will automatically start. This removed one step of the process, but we still have to open a shell and run the command. So let's also automate this.

sudo bw-autorun local --ws 9939
Enter fullscreen mode Exit fullscreen mode

This will make a systemd service that automatically starts BotWave on boot. It also opens a remote connection on port 9939 so I can still manually send commands if needed.

And we're done !

  • Automate everything

And now, I'm able again to take my 15 bucks radio, tune it to 102.5MHz, and listen to it with a less perfect, but more charming audio quality, where and when I want :D

picture of the Raspberry Pi and the radio

Picture taken with my circuit bent camera, btw

  • Enjoy !

Top comments (0)