Network
From the ALSA wiki
[edit] Q: How can I instantly copy the sound output from this box to another box over network?
A: Here's what i did:
i used netcat to pipe the sound with arecord and aplay to another box. In this answer, the machine that generates the sound will be called lambda, the one that outputs the sound over its sound card will be called kappa.
- First install netcat (sometimes called nc).
- On lambda, set up recording:
* Set the control 'Capture Source' to "mixer". * Adjust the capture level. Make sure it isn't set too high.
- On kappa, set up a netcat process listening: (UDP is fine, not every bit is important)
- [kappa]# nc -u -l -p <portnum> | aplay
- whatever comes in on that port will be put through aplay as if it were a regular file.
- On lambda, record the sound and put it through network on the port you just opened on kappa:
- [lambda]# arecord -t wav -f cd | nc -u kappa <portnum>
done, whatever is put through mixer (the default device) on lambda should come out at the default device (usually your sound card) on kappa.
[edit] Automagical setup
- On kappa, run the listener process as usual:
- [kappa]# nc -u -l -p 8100 | aplay
- On lambda, run the following shell script (that is, paste it in a file, run 'chmod r+x ' on the file and execute it):
#!/bin/sh CONTROL="`amixer controls | grep 'Capture Source'`" VALUE="`amixer cget "$CONTROL" | grep "'Mix" | head -n 1 | sed -e 's/.*\#\([0-9]\).*/\1/'`" amixer cset "$CONTROL" $VALUE >/dev/null arecord -t wav -f cd | nc -u `cat /etc/alsa/network-sound`
[edit] Notes
NOTE: don't put this sound over network to yourself!!! (there is a feedback loop that doesn't end quickly and could destroy your speakers!)
NOTE2: this is very good for when you have set up thin clients. you write a script that requests sound_input from the server using this method. Remember that you need to set up multiple audio devices if you serve multiple clients.
NOTE3: this is probably not the best way, but it works...