PyroPeter's homepage (PyroPeters Heimseite)

IPv6 ready since 2010

Shell two-liner for simple voice chats

The following two shell commands record sound from an ALSA capture device (aka. microphone), encode it using OPUS, send it to a second host as a raw UDP stream and decode and play it on that second host. Run two instances of this to achive real full-duplex communication! This is most probably how Richard Stallman does voice chats.

The first command (capturing, encoding, sending):

arecord - | opusenc --bitrate 16 --ignorelength --expect-loss 10 \
--max-delay 10 --framesize 10 - - | netcat -u <remote ip> <port>

The second command (receiving, decoding, playback):

netcat -vulp <port> | opusdec --force-wav - - | aplay

The arguments to opusenc were choosen by me out of the blue (My chain of thoughts was a bit like "The framesize should probably be low, to minimize delay, but not too low, or there will be a lot of overhead. How about ten?") and are probably all wrong. (But it worked fine, the one time I tested it!) Also, according to opusenc(1), bash pipes do buffering and are thus not really helping the whole low-latency idea of voice chatting. When I tested this, the round-trip-time (A speaks, B does not use headphones, A hears own echo) was about two seconds over two DSL-links. (ping measures the rtt as 73 ms) Audio stutters were quite infrequent and the quality was just great, especially considering the low bitrate of 16 kbit/s. (arecord used a sampling rate of 8000 Hz)