Adventures in Networking

Main menu:

Archive for August, 2018

Real-time Audio Streaming with Raspberry Pi

References:

  • Basic Idea:
    • https://tech.lds.org/forum/viewtopic.php?t=4812&start=30
    • https://tech.lds.org/forum/viewtopic.php?t=18758
  • Raspberry Pi Setup:
    • https://www.zdnet.com/article/raspberry-pi-extending-the-life-of-the-sd-card/
    • https://www.raspberrypi.org/forums/viewtopic.php?p=462982#p462982
      • Not needed with Pi 3!
    • https://raymii.org/s/tutorials/Autossh_persistent_tunnels.html
    • https://ritsch.io/2017/08/02/execute-script-at-linux-startup.html
    • https://medium.com/@mikestreety/use-a-raspberry-pi-with-multiple-wifi-networks-2eda2d39fdd6
  • Sound adapter:
    • https://smile.amazon.com/gp/product/B016CU2PEU/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1
  • Darkice, Icecast, etc:
    • https://stmllr.net/blog/live-mp3-streaming-from-audio-in-with-darkice-and-icecast2-on-raspberry-pi/
    • https://github.com/tim273/weather_radio_scripts
    • https://w7apk.com/streaming-radio
    • http://icecast.org/docs/icecast-2.4.1/basic-setup.html
    • http://icecast.org/docs/icecast-2.4.1/auth.html
    • http://wiki.sunfounder.cc/index.php?title=To_use_USB_mini_microphone_on_Raspbian
    • https://wiki.radioreference.com/index.php/Live_Audio/Ubuntu_Darkice
    • http://www.hamblog.co.uk/top-10-amateur-radio-uses-for-raspberry-pi/
  • Internet hosting by:
    • Linode
    • Debian, UFW
  • Client:
    • VLC

rtl_fm.sh

rtl_fm -f 72.1M -s 48000 | play -q -r 48000 -t raw -e s -b 16 -c 1 -V1 -v 4 - sinc 125-3.2k

darkice.cfg

[general]
duration = 0 # duration in s, 0 forever
bufferSecs = 1 # buffer, in seconds
reconnect = yes # reconnect if disconnected

[input]
device = plughw:1,1 # or `pulse' for Pulseaudio
sampleRate = 22050 # sample rate 11025, 22050 or 44100
bitsPerSample = 16 # bits
channel = 1 # 2 = stereo

[icecast2-0]
bitrateMode = vbr # variable bit rate (`cbr' constant, `abr' average)
quality = 1.0 # 1.0 is best quality
format = mp3 # format. Choose `vorbis' for OGG Vorbis
bitrate = 128 # bitrate
server = xx.xx.xx.xx # IP address of the IceCast server
port = 8000 # port for IceCast2 access
password = snajd # source password to the IceCast2 server
mountPoint = lcw.mp3 # mount point on the IceCast2 server .mp3 or .ogg
name = Lewis Center Ward

darkice.service

[Unit]
Description=darkice
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/darkice -c /xxxxx/darkice.cfg

[Install]
WantedBy=multi-user.target

autossh.service

[Unit]
Description=autossh
Wants=network-online.target
After=network-online.target
# sshd.service

[Service]
Type=simple
User=root
ExecStart=/usr/bin/autossh -M 0 -N -q -o "ExitOnForwardFailure=yes" -M 1234 -i /home/xxxxxxxx/.ssh/id_rsa -R 3333:localhost:22 user@example.com
#Restart=always
#RestartSec=60
#ExecStop=/usr/bin/killall -s autossh

[Install]
WantedBy=multi-user.target