SOX and BASH

Bruno torso shell script.

Using SOX to generate random audio video using its spectrogram


#!/bin/bash

n=1;
baseone=$(shuf -i 500-3000 -n 1)
basetwo=$(shuf -i 100-3000 -n 1)

type=$(( $RANDOM % 10 + 1 ))

#type=10

rate=$(shuf -i 1024-192000 -n 1)

wavs=$(shuf -i 4-75 -n 1)

#wavs=10

while [ $n -le $wavs ]
do

filename=note$n.wav
spectroname=spectro$n.png

noteone=$(($baseone + $n * 2))
notetwo=$(($basetwo * $n))

if [ "$type" -gt "5" ]
then
sox -r $rate -n $filename synth 0.5 sine $noteone-$notetwo sawtooth $baseone-$basetwo sin $noteone sin 50-120 spectrogram -o $spectroname
else
reverb=$(shuf -i 1-40 -n 1)
sox -r $rate -n $filename synth 0.5 sine $noteone-$notetwo trapezium $noteone sawtooth $noteone sin $notetwo tremolo 30 reverb $reverb flanger triangle spectrogram -o $spectroname
fi

n=$((n+1))

done

sox /var/www/html/uploads/*.wav out.wav

#create a =nother single wav and mix it with out.wav
otherwavlength=`awk 'BEGIN{printf("%0.2f", '$wavs' * '0.5')}'`
sox -r $rate -n other.wav synth $otherwavlength sawtooth $baseone-$basetwo flanger 0.9 0.9 4.0 0.23 1.3 chorus 0.7 0.9 55.0 0.4 0.25 2.0 -t
sox -m other.wav out.wav new.wav fade p 0 0 2

#rename the png files (0001, 0002, etc)
a=1
for i in *.png; do
new=$(printf "%04d.png" ${a})
mv ${i} ${new}
a=$((a+1))
done

#each image will display for a rate of 2 per second

avconv -y -i new.wav -r 2 -i %4d.png -c:v libvpx -b:v 1M -vf crop=900:585:0:0 -c:a libvorbis bruno.webm

Leave a comment