Audio Streaming Raspberry Pi

How to stream audio (line-in) to icecast — Raspberry Pi 3

Hardware lists:

  • USB Sound Card (Sound BLASTER SBX)
  • Raspberry Pi 3

list usb sound card

pi@raspberrypi:~ $ aplay -L | grep CARD

sysdefault:CARD=ALSA
dmix:CARD=ALSA,DEV=0
dmix:CARD=ALSA,DEV=1
dsnoop:CARD=ALSA,DEV=0
dsnoop:CARD=ALSA,DEV=1
hw:CARD=ALSA,DEV=0
hw:CARD=ALSA,DEV=1
plughw:CARD=ALSA,DEV=0
plughw:CARD=ALSA,DEV=1
sysdefault:CARD=Pro
front:CARD=Pro,DEV=0
surround21:CARD=Pro,DEV=0
surround40:CARD=Pro,DEV=0

capture audio from line-in :

arecord –device=sysdefault:CARD=Pro  –format S16_LE –rate 44100 -c 2

test sound :

aplay -D sysdefault:CARD=Pro

mix command arecord (send to stdin/stdout) and aplay

arecord –device=sysdefault:CARD=Pro  –format S16_LE –rate 44100 -c 2 | aplay -D sysdefault:CARD=Pro

 

Stream audio to icecast

we adopt the solution from https://one-button.org/node/48

convert audio to mp3 : lame -r -s 44.1 -m s -b 128 –cbr – –

stream to icecast : ezstream -c /etc/ezstream.xml

ezstream configuration file :

ezstream.xml

<ezstream>
    <url>http://localhost:8002/stream</url&gt;
    <sourcepassword>hackme</sourcepassword>
    <format>MP3</format>
    <filename>stdin</filename>
    <stream_once>1</stream_once> <!– must do for stdin –>
<!– the rest are optional –>
    <svrinfoname>Raspberry Pi Station</svrinfoname>
    <svrinfourl>http://radio.ogonan.com</svrinfourl&gt;
    <svrinfogenre>geek</svrinfogenre>
    <svrinfodescription>Stream Audio from YouTube</svrinfodescription>
    <!– the following taken from mplayer. not sure if it’s right –>
    <svrinfobitrate>128</svrinfobitrate>
    <svrinfochannels>2</svrinfochannels>
    <svrinfosamplerate>44100</svrinfosamplerate>
    <svrinfopublic>1</svrinfopublic>
</ezstream>

combine command :

arecord –device=sysdefault:CARD=Pro  –format S16_LE –rate 44100 -c 2 | lame -r -s 44.1 -m s -b 128 –cbr – – | ezstream -c /etc/ezstream.xml

Audio monitoring :

mplayer -ao alsa:device=hw=1.0 http://localhost:8002/stream

Notes :

Generate a Playlist

$ cd /path/to/music/dir
$ find -type f -iname \*.mp3 > playlist.txt

$ mplayer -shuffle -playlist playlist.txt

;mplayer -ao alsa:device=hw=1.0 -shuffle -playlist playlist.txt

Control and Monitoring by supervisor

create shell script : capture.sh

#!/bin/bash
arecord –device=sysdefault:CARD=Pro  –format S16_LE –rate 44100 -c 2 | lame -r -s 44.1 -m s -b 128 –cbr – – | ezstream -c /etc/ezstream.xml

create configuration file : /etc/supervisor/conf.d/capturehooks.conf

[program:capturehook]
command=/home/pi/Music/capture.sh
directory=/home/pi/Music
autostart=true
autorestart=true
startretries=3
stderr_logfile=/home/pi/Music/log/capturehook.err.log
stdout_logfile=/home/pi/Music/log/capturehook.out.log
user=pi

see https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps

Record audio file every 1 minute

create shell script  local_record.sh

#!/bin/bash
adate=`date +”%Y%m%d_%H%M%S”`
FILE=”/home/pi/Music/files/radio_$adate.mp3″
arecord –device=sysdefault:CARD=Pro  –format S16_LE –rate 44100 -c 2 | lame -r -s 44.1 -m s -b 128 –cbr – “$FILE” &
sleep 61
kill %1

add to crontab :

* * * * * /home/pi/Music/local_record.sh >/dev/null 2>&1

 backup file to cloud :

rsync -avz -e “ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null” –progress /home/pi/Music/files/radio_20170329*.mp3 CATWEBCASTING @192.168.8.98:/Volumes/storagebkk01/media-cat/files/

Ref. https://www.digitalocean.com/community/tutorials/how-to-copy-files-with-rsync-over-ssh

Advertisements

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s