14 Audio Streaming
Elliott Liggett edytuje tę stronę 2022-04-25 15:56:23 +00:00

Obsolete

For the most up to date information, please visit https://wfview.org/wfview-user-manual/

wfview has built-in audio streaming and network support now, so this page is entirely obsolete. I'm keeping it here because it may be useful for folks looking to set up a separate type of audio streaming.


OLD INFORMATION

Streaming Audio Overview

Obviously, remotely viewing wfview, either by using VNC, X11, or even by sending the serial data over a network connection, is pretty cool. But it's much better if you can hear the audio!

While it is possible to stream the audio with pulse, I had a lot of trouble getting the radio's audio (which is an output) to come out of the client (listening) machine. It kept showing up as an input from which I could record the audio in a program like audiacity or process the audio in fldigi... but not HEAR it from a speaker. This is because I have to learn how to use the loopback audio function in pulse, and it's a mess.

Therefore, I went with a different approach, which actually works great and provides a lot of additional utility. The approach is to use ffmpeg to create an encoded stream, and then to use an icecast2 server to make the stream easily accessible by anything that can play back an mp3 or ogg stream. There's more latency with this approach (just under two seconds in my experience, on my own network), but it is so simple.

I am hoping to figure out how to do this with pulse later, at least for making a microphone stream, which would be really something for remote operation!

Install the packages

First, install these packages:

sudo apt-get install ffmpeg icecast2

My machine actually walked me through the icecast2 setup process. Two things are important here. First, write down the passwords. These are only needed for the admin web page and for ffmpeg to act as a supplier to icecast. Second, when asked for a FQDN, you need to specify something -- an IP address or a real hostname -- that can be resolved and used by your clients. Do not specify 127.0.0.1, it won't work. Use your LAN IP address if you are only using it at home. If you want to use it externally, use your external IP address or a hostname (possibly via dynamic DNS).

Set up Icecast

Next, edit (as root) your /etc/icecast2/icecast.xml file, and change the <burst-on-connect> to a value of 0. Otherwise you will have double the latency. Now restart icecast: systemd restart icecast2 Surprisingly, you can leave the rest of the config file alone.

Find your audio device

Now turn on your IC-7300, plug in the USB cord, and run these commands to determine the correct audio card designation to use: sudo arecord -l

(You have to run as root unless you are logged in at the physical console. This is a consequence of modern linux audio, unfortunately, and is annoying.) Look for something like this:

card 1: CODEC [USB Audio CODEC], device 0: USB Audio [USB Audio]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

From this output, our 7300 is going to be audio device 1, subdevice 0, specified like this: hw:1,0

Script for ffmpeg

Now create a shell script to run ffmpeg. This is needed because the command is rather long and you might want a simple way to edit the command. My script is called ffmpeg_script.sh and I stored it in ~root/bin.

#!/bin/bash
# 22.05 KHz, Latency is 1.5 s
ffmpeg -ac 1 -f alsa -i hw:1,0  -ar 22050 -acodec libmp3lame -ab 256k -ac 1 -content_type audio/mpeg -flags low_delay -fflags nobuffer -f mp3 icecast://source:letmein@192.168.1.104:8000/icom

Replace letmein with your actual password (if you forgot it, the password is stored in plaintext in /etc/icecast2/icecast.xml), and use the IP address of your computer running icecast. If you run the sample rate (22.05 KHz) higher, you will have double the latency. Similarly, if you decrease the bitrate of the encoded stream (256k in this case), you can expect more latency. The audio quality is acceptable down to 32k, and the latency increases only a modest amount at 128k (1.7 seconds in my experience) but quickly increases to several seconds at lower bitrates. There's probably a work-around, but I can't figure it out.

Now try it out!

First run the script we made for ffmpeg as root. sudo ~root/bin/ffmpeg_script.sh will do. If there aren't any errors, proceed!

Next, open a streaming client on your laptop, such as VLC, iTunes, or even a web browser. In VLC, choose File, then Open URL... and paste this in: http://192.168.1.104:8000/icom. You can also specify the stream like this: http://192.168.1.104:8000/icom.m3u (that's a playlist file). You might also just want to go to the icecast page with your web browser and poke around (there isn't much there) at http://192.168.1.104:8000/. Use the password you specified in setup.

In VLC, you can adjust the latency, and you can safely run it quite low in my experience. The latency can be adjusted by using the advanced preferences, and going to Stream Output, and then adjusting the "Stream output muxer caching" down to 50ms.

Enjoy and please let me know if you know a better way to do this! Keep in mind that if you port forward through your router, you can probably support several listeners to the stream. This is fun, because your friends can hear themselves over HF if you just email them the URL.