Stream audio to web with pulseaudio in Ubuntu 10.10

The other day I wanted to stream my new KORG Electribe MX online so that one of my friends could hear me play around with it. I looked everywhere for a solution but all the solutions out there seem to want to use Jack control which is low latency sound driver that a lot of people use for better sound quality. I just wanted to stream pulseaudio to the web because Ubuntu comes with pulseaudio installed and setup by default so it would be easiest for me. I figured out how to do it and just wanted to share it with all of you guys. I setup my Line in to stream on the web but any one of your sound devices can be used for these. You can even do multiple ones if you want to.

Here are the packages you will need for this. You can install these packages directly through the Ubuntu package manager so anyone can use these to set up and stream their sound. You do not have to be an expert.

These are the commands you have to run to install the required pacakges:
$ sudo apt-get install icecast2
$ sudo apt-get install gstreamer-tools
$ sudo apt-get install padevchooser
$ sudo apt-get install paman
$ sudo apt-get install pavucontrol

Icecast is the streaming server, gstreamer we use to stream to our icecast server and the last 3 packages are just interfaces to the pulseaudio soundcard which we will use to make our life easier.

Once you have these items installed you will have to edit the icecast2 configuration file which is at /etc/icecast2/icecast.xml and make sure you change the passwords under the section. Search in the file for them there is a lot of documentation in the file for that.
If you would like to change the port this server is running on go ahead and scroll down in this file and change it under . By default the port is 8000.

Once you do that you can start the icecast2 server by typing this command in the terminal:
$ /etc/init.d/icecast2 start
Congratulations you have a working streaming server!!! But we are not done. You need to stream something to it or it will just be sitting there doing nothing. How do we do this? This is a little more complicated but we do it using gstreamer. Gstreamer allows us to connect to this icecast2 server and forward any audio device we want.

Here is the command:
gst-launch pulsesrc device=alsa_input.pci-0000_00_10.1.analog-stereo ! audioconvert ! vorbisenc ! oggmux ! shout2send mount=/stream.ogg port=8000 password=password ip=localhost

I saved this into a script that i run anytime i want to stream my lineout. This command creates a recording device in the pulseaudio which takes whatever is in the linein and streams it to the icecast2 server.

Lets look at this command.
device=alsa_input.pci-0000_00_10.1.analog-stereo
This specifies what device I want to stream to the web. In my case this is my linein device. This information is coming from the PulseAudio Manager. You can open this by typing in paman at command prompt. On the devices tab you will see all your device names there. If you look at the description on the right, one of them will say Loopback to Internal Audio Analog Stereo.

mount=/stream.ogg
This is the stream path where your audio device will be streaming. If you leave it to stream.ogg, your stream address will be http://youraddress:8000/stream.ogg
port=8000
This is the port where your icecast2 server is running on. If you changed that port from the default of 8000 you have to change it here also. If you have a different port the link to the streaming server will be http://youraddress:yourport
password=password
This is the password you setup in your icecast2 server. This is how you authenticate to the stream server.
ip=localhost
This is the ip address for your stream server. If you are running it on the same machine as gstreamer then you can leave it to localhost.

And that is all folks!! If you have any questions about this post them below in a comment. I will answer them. It took me a while to get this going since a lot of people use different solutions including VLC and jack audio. I just wanted to keep it simple.

If you need to setup your line in which is not turned on by default in Ubuntu look at my article on setting up line in here.

  • Ted

    what do these parts represent? “audioconvert ! vorbisenc ! oggmux”

    • adriancoroian

      Those encode the audio stream as ogg vorbis

  • Stu

    Unfortunately this doesn’t seem to work any more in oneric I think the pulseaudio related packages are different … any chance of an update??