Create Audio Streaming

master
Elliott Liggett 2020-09-16 18:47:46 +00:00
rodzic 51fdb7c2dd
commit 038cfd09ac
1 zmienionych plików z 39 dodań i 0 usunięć

39
Audio-Streaming.md 100644

@ -0,0 +1,39 @@
**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.
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. 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).
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`
Now turn on your IC-7300, 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`
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.
`#!/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, 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.
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!