This tip is similar to this hint but after experimenting with that technique and various other options I think I've hit on an improved setup.
Steps to perform on your Mac:
- Download and install Soundflower. This will allow you to redirect all audio played on your Mac over the network.
- Install MacPorts as well; this will make it easy to install esound and ffmpeg which are needed later.
- Install esound with the command sudo port install esound in Terminal.
- Similarly install ffmpeg with sudo port install ffmpeg.
- In System Preferences » Sound, select Soundflower (2ch) as the Input and Output devices.
- Run Soundflowerbed that came with Soundflower, found in the Flower menu item, and select None (OFF) under Soundflower (2ch). This turns off your built in speakers so only the network sound will play.
- Start esd with the Terminal command: esd. Note we are not actually using esd to transfer the audio over the network, just for recording local audio.
- Record the audio captured by Soundflower and stream it over the network using the rtp protocol with
Here myIP is the IP address of the box you want to stream to.
esdrec | ffmpeg -f s16le -ac 2 -i - -acodec libmp3lame -ab 320k -f rtp rtp://myIP:1234
- Install VLC. On an ubuntu/debian box you can use sudo apt-get install vlc-nox for a console version.
- Run VLC to stream your audio from your mac with: vlc rtp://myOtherIP:1234 where myOtherIP is the address of the box you are running VLC on.
How it works:
- Soundflower captures any output going to the speakers and redirects it to the microphone input (this is all done digitally, so there is no loss in quality).
- The program esd opens the sound device and makes it available to other local programs.
- Then esdrec connects to esd and records input to the microphone and passes it on to ffmpeg.
- After that ffmpeg takes the raw audio and encodes it as mp3 then publishes it on the network as an rtp stream.
- The other computer connects to the rtp stream and plays the audio.
- There is about a two second delay between playing on the Mac and hearing on the receiving machine. This makes watching videos with network audio a bit rubbish, but using VLC or MPlayer you can adjust the audio sync to compensate for this.
- The program esound isnt really needed, as we are only using it to record audio rather than using its network audio abilities. Whenever I've tried using esd to stream audio I've experienced a big delay and garbled audio, hence using ffmpeg/vlc instead. In this setup esound/esdrec can be replaced with any commandline tool that records audio and streams to stdout. The only tool I could find to do this is esdrec.
- Some CPU time is used on the Mac transcoding and streaming the audio, but it is fairly small (about 5 percent on my MacBook Pro).
- The audio is transcoded as mp3, which is lossy so there will be a slight degradation in sound quality. I tried using lossless codecs (e.g. flac) with ffmpeg streaming but couldn't get it to work.
- This same ffmpeg technique can be used to stream video as well as audio, which would let you make your cupboard machine act more like an Apple TV.
[crarko adds: I haven't tested this one, but I might try it at some point in the future. It sounds like a lot of hoops to jump through, but I'm always looking for new ways to stream content to my iPad. Also note that using MacPorts requires having the Developer Tools installed.]

