After playing around with a product-that-shall-remain-eye-queue-nameless today, I found a nice way to stream the audio coming out of an audio source online through Linux:
Firstly, if the device you’re getting audio from doesn’t have a 3.5mm stereo jack for output (commonly known as a headphone jack), you will need to connect a 3.5mm stereo to RCA cable from the audio output of the device to the Line in on your PC. Don’t use the microphone input (it typically is only mono and has a lower impedance)—stick with the line in.
emerge -a icecast ezstream soxIcecast is an open source alternative for Nullsoft’s proprietary SHOUTcast software which will be using to stream the audio online. The sox package includes a program called
recwhich is capable of capturing and encoding the input from line in. ezstream is the glue: it takes the encoded audio and pushes it to the Icecast server.alsamixer -V captureSwitch Input Source to Line (it defaults to Mic), and increase its volume to approximately 70%. After much testing this seems to be about the best setting (feel free to experiment, it won’t be the same on your PC).
alsamixer -V playbackIncrease the Line slider to approximately 70%.
Run
rec test.wavfor 10 seconds or so and^Cit. All going well, you should have just captured 10 seconds worth of audio from the source in 8-bit mono! Confirm this with your favourite media player (ormplayer test.wav). You can remove this file now, as we won’t be capturing to file for the real thing.
To configure Icecast, you will want to make a few changes to the default
configuration. Edit /etc/icecast/icecast.xml and change the following
settings:
The default maximum client count is a bit much (100), so drop it down to 10:
<clients>10</clients>Change the default passwords from
hackme(lulz) to a more meaningful (and secure) setting. There are a few different sections that need changing, so just/hackmein vim.The
<hostname>is set tolocalhostby default, which may not be useful if you intend to access the streaming server by its FQDN or IP. Change this as appropriate (it makes no difference unless you use the web interface).Start the server:
/etc/init.d/icecast start.
Next, we will configure ezstream. This is very easy as one of the provided
configuration files does exactly what we want (taking input from stdin in the
Vorbis format and send it to
Icecast). We’re using Vorbis (.ogg) because encoding as it is less
CPU-intensive than MPEG-2 (MP3).
Copy the example configuration to Icecast’s configuration directory (which isn’t strictly required but it’s a good a place as any to store it):
bzcat /usr/share/doc/ezstream-0.5.3/examples/ezstream_stdin_vorbis.xml.bz2 > /etc/icecast2/ezstream_stdin_vorbis.xmlEdit the newly created configuration and change hostname in
<url>to whatever you picked before (the default islocalhost). Replacevorbis.oggwith a more meaningful name. An example<url>value might be:<url>http://my-server:8000/ipod</url>Change each of the svr items at the bottom to your liking. This is all metadata for the server to add to the stream. Leave the sample/bitrate/etc settings as their defaults.
Start sending the audio to Icecast:
rec -c 2 -r 44k -t ogg - | ezstream -c /etc/icecast2/ezstream_stdin_vorbis.xmlThese commands tell
recto take the input from the default capture device (line in) and encode it using the Vorbis format, 2-channel, 44 kHz (standard for CD-quality audio) and write it to stdout.ezstreamtakes its input from stdout and sends it to Icecast as per its given configuration. This must stay running for as long as you want to capture/encode and push audio to Icecast.Test the stream by opening
http://my-server:8000/ipodinmplayer. You should hear the output from your audio device being played through your computer with a lag of approximately 3-4 seconds.
Congratulations, you can now stream the current audio to anyone in the world! Just make sure the source device’s volume is set to maximum for the best listening experience.