summaryrefslogtreecommitdiff
path: root/src/Streaming_Audio_Over_SSH.ascii
blob: aab6d050ea4cc19c970dd8cf32f23374a8a2822b (plain)
    1 Streaming Audio Over SSH
    2 ========================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 At home, I have a server/desktop running nearly 24/7
   10 (https://archlinux.org[Arch Linux] if anyone is wondering). I use this server
   11 for all kinds of experiments. My backups are there (well, it's one of my backup
   12 locations). My home dlna server is there. It's also hooked up to my sound
   13 system for http://musicpd.org[mpd] so I can have it play my music, controllable
   14 by any device on my home wifi. Recently however, I wanted to be able to stream
   15 my laptop's audio over my sound system, without having to plug it in directly.
   16 The reason being I wanted to stream Spotify over said sound system, but didn't
   17 want to go to the hassle of plugging in a keyboard and mouse, and installing a
   18 GUI and plugging my server in to a monitor, just so I can occasionally listen
   19 to music through not-so-bad speakers. Then I wondered, you can do just about
   20 anything with SSH, why not try to stream audio over it. Here's how I do it
   21 (there are many other ways).
   22 
   23 [[requirements]]
   24 == Requirements
   25 
   26 The server (the computer hooked up to the sound system) needs *mplayer*
   27 installed so it'll have something to play the audio with.
   28 
   29 The audio source system (my laptop in this case) needs alsa-utils installed,
   30 specifically for the *arecord* application.
   31 
   32 Obviously both the server and the audio source system need ssh installed (and
   33 the daemon running on the server).
   34 
   35 
   36 [[command]]
   37 == Command
   38 
   39 Not too much to say here.
   40 
   41 ----
   42 arecord -c 1 -r 32000 | ssh <user>@<server> 'mplayer -demuxer rawaudio -rawaudio channels=1:rate=32000:samplesize=1 -nocache -'
   43 ----
   44 
   45 So what that command does is...
   46 
   47 arecord::
   48   Is a command line program for recording from audio devices. If no output file
   49   is specified (like in this case), it writes what it records to stdout. For
   50   our purposes, we pipe stdout to ssh in the next command.
   51 
   52 ssh...mplayer::
   53   Here we send stdout from the previous command (hence the pipe) straight to
   54   the server over ssh. Mplayer on the server plays what it receives from stdin
   55   (the final - ). The rest of the mplayer flags are just for audio quality
   56   control (same for the flags on arecord). The -nocache reduces delay a bit,
   57   but in some cases can cause skipping, so you might want to remove that
   58   switch.
   59 
   60 
   61 There is one caveat to this. While it works fine for streaming internet radio
   62 or any other audio you want really, streaming audio for a video source doesn't
   63 work nearly as well. On my setup, there is about a .75 second delay, so YouTube
   64 videos don't sync up. Otherwise though this works swimmingly.
   65 
   66 
   67 Category:Linux
   68 Category:SSH
   69 
   70 
   71 // vim: set syntax=asciidoc:

Generated by cgit