Collections of scripts etc.

Over the times we wrote a bunch of scripts to help with audio / video broadcasting:

https://git.puscii.nl/sms/streaming-media-stuff

https://git.puscii.nl/admradio/nixradio (FIXME: this one needs to be published)

https://wiki.pinknoise.puscii.nl/

Jack over the network

with 1 soundcard (just processing happening on other machines)

https://github.com/jackaudio/jackaudio.github.com/wiki/WalkThrough_User_NetJack2

netjack at LAG

with soundcard on each machine (zita is a resampler)

Sender:

#!/bin/bash zita-j2n --jname tx-network --chan 2 --mtu 1500 10.205.12.123 9923

Receiver:

#!/bin/bash zita-n2j --jname "rx-network" --chan 2 --buff 40 0.0.0.0 9923

Streaming to icecast

Liquidsoap works pretty good, and is stable:

streams.liq

#!/usr/bin/liquidsoap
vorbis_encoding = %vorbis( quality=0.5, samplerate=48000, channels=2)
#mp3_encoding = %mp3(bitrate=256, channels=2)
mp3_encoding = %mp3()
opus_encoding = %ogg(%opus(bitrate=32))

icecast_ogg = output.icecast(
vorbis_encoding,
connection_timeout=1.0,
fallible=true,
url="https://adm.amsterdam/radio",
genre="papillon archive / not live", 
name="papillon", 
description="lalalal"
)

icecast_mp3 = output.icecast(
mp3_encoding,
connection_timeout=1.0,
fallible=true,
url="https://adm.amsterdam/radio",
genre="papillon archive / not live mp3 stream", 
name="papillon", 
description="lalalal"
)

icecast_flac = output.icecast(
%ogg(%flac),
connection_timeout=1.0,
fallible=true,
url="https://adm.amsterdam/radio",
genre="papillon archive / not live flac stream", 
name="papillon", 
description="lalalal"
)

icecast_opus = output.icecast(
%ogg(%opus),
connection_timeout=1.0,
fallible=true,
url="https://adm.amsterdam/radio",
genre="papillon archive / not live opus stream", 
name="papillon", 
description="lalalal"
)

icecast__ogg = output.icecast(
vorbis_encoding,
mount="papillon-archive.ogg",
url="https://adm.amsterdam/radio",
genre="papillon archive / not live", 
name="papillon", 
description="lalalal"
)

startstream.liq

#!/usr/bin/liquidsoap
set("frame.audio.samplerate",48000)

set("server.telnet.port", 2023)
set("server.telnet", true)

set("frame.duration",0.16)

set("log.file.path","/dev/null")
set("log.stdout",true)

live = mksafe(input.jack(id="liquidsoap-icecast", buffer_size=8, clock_safe=false))

%include "streams.liq"

icecast_ogg(live, mount="testje", host="icecastserver", port=8000, password="thepassword")

setting up pulse to output to jack

https://github.com/jackaudio/jackaudio.github.com/wiki/WalkThrough_User_PulseOnJack

apulse

Alternative pulseaudio implementation that does not require a pulseaudio daemon

You could get that to work with jack with the alsa jack plugin: https://alsa.opensrc.org/Jack_(plugin)

Jack plumbing

Nice tool to autoconnect (and disconnect) jack clients

/etc/jack-plumbing


(disconnect "moc:output(.*)" "system:playback_(.*)")
#(connect-exclusive "moc:output0" "ardour:MOC/audio_in 1")
#(connect-exclusive "moc:output1" "ardour:MOC/audio_in 2")
(connect "moc:output0" "ardour:MOC/audio_in 1")
(connect "moc:output1" "ardour:MOC/audio_in 2")
(connect "mpv:out_0" "ardour:MOC/audio_in 1")
(connect "mpv:out_1" "ardour:MOC/audio_in 2")
(disconnect "mpv:out_0" "system:playback_1")
(disconnect "mpv:out_1" "system:playback_2")
            
            
(connect "Music Player Daemon:left" "ardour:MPD/audio_in 1")
(connect "Music Player Daemon:right" "ardour:MPD/audio_in 2")
(disconnect "Music Player Daemon:left" "system:playback_1")
(disconnect "Music Player Daemon:right" "system:playback_2")
            
(connect "mumble:output" "ardour:mumble/audio_in 1")
(connect "ardour:Master/audio_out 1" "mumble:input")

(connect "ardour:Master/audio_out 1" "darkice:left")
(connect "ardour:Master/audio_out 2" "darkice:right")

(connect "ardour:Master/audio_out 1" "liquidsoap-ls1ls2:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-ls1ls2:in_1")
(connect "ardour:Master/audio_out 1" "liquidsoap-ls1ls2-low:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-ls1ls2-low:in_1")
(connect "ardour:Master/audio_out 1" "liquidsoap-ls1ls2-verylow:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-ls1ls2-verylow:in_1")
(connect "ardour:Master/audio_out 1" "liquidsoap-location:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-location:in_1")

(connect "ardour:Master/audio_out 1" "liquidsoap-location-low:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-location-low:in_1")
(connect "ardour:Master/audio_out 1" "liquidsoap-location-verylow:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-location-verylow:in_1")

(connect "ardour:Master/audio_out 1" "liquidsoap-papillon-studio:in_0")
(connect "ardour:Master/audio_out 2" "liquidsoap-papillon-studio:in_1")
(disconnect "Mixxx:out_0" "system:playback_1"
(disconnect "Mixxx:out_1" "system:playback_2")

(connect "Mixxx:out_0" "ardour:mixxx/audio_in 1")
(connect "Mixxx:out_1" "ardour:mixxx/audio_in 2")
(connect "system:capture_1" "jack-scope-*:in_1")
(connect "system:capture_2" "jack-scope-*:in_2")

intercept hls segments with apache_mod_ext_filter

Will insert snippets in hls segments (and store the intercepted audio in a wav file), it has some issues with timestamp continuity, but seems to work kinda ok.

spoken.txt is a file with path's to audio files outdir is where the clean audio will be stored

#!/bin/bash

date=date +%s outdir=/var/www/html/audiotest

readarray spoken < /var/www/spoken.txt spokensize=${#array[@]} spokenindex=$(($RANDOM % $spokensize))

ffmpeg \ -thread_queue_size 512 -f mpegts \ -copyts -copytb 1 \ -i - \ -i ${spoken[$spokenindex]} \ -muxdelay 0 \ -max_delay 0 \ -map_metadata 0 \ -filter_complex "[0:a]asplit=2[in1][in2]\;[in1]amix=inputs=2:duration=first:dropout_transition=0[out1]\;[in2]acopy[out2]" \ -map '[out1]' -codec:a libmp3lame -f mpegts - \ -map '[out2]' -acodec pcm_s16le -ac 1 -ar 16000 -f wav $outdir/tst$date.wav.writing