Last active
December 3, 2016 05:12
-
-
Save qrkourier/09abb1a8dccc0f5ac7ec6345f7ed3053 to your computer and use it in GitHub Desktop.
Shuffle, pad with a random duration of silence, and concatenate a bunch of .mp3 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -u | |
# | |
# [this lives here now](https://github.com/qrkourier/shufflepad-sound-machine/blob/master/bin/shufflepad.sh) | |
donames(){ | |
find -mindepth 1 -maxdepth 1 -type f -iname '*.mp3' | egrep '\s' | \ | |
while read pad;do | |
mv -v "$pad" $(sed -r 's/[-)(_ ]+//g'<<<"${pad#./}") | |
done | |
} | |
purgepad(){ | |
printf '\npurging ./pad/\n' | |
rm -rf ./pad/; mkdir -p ./pad/ | |
} | |
dopad(){ | |
printf '\npadding\n' | |
find -mindepth 1 -maxdepth 1 -type f -iname '*.mp3' | \ | |
while read pad;do | |
echo $pad | |
sox $pad ./pad/${pad#./} pad 0 $(($RANDOM%66)); | |
done | |
printf 'padding produced %d files occupying %s\n' \ | |
$(ls -1 ./pad/|wc -l) "$(du -sh ./pad/)" | |
} | |
docat(){ | |
eval avconv -i concat:$(\ | |
ls ./pad/*.mp3|shuf|while read pad;do printf '%s\|' $pad;done|sed 's/\\|$//' \ | |
) -c copy ./pad/out.mp3 | |
} | |
read -sn1 -t9 -p 'ctrl-c to cancel: in 10s I will rename all files in pwd like\ | |
(s/ /-/g)' DONAMES | |
[[ "$DONAMES" == "n" ]] || donames | |
read -sn1 -t9 -p "ctrl-c to cancel: in 10s I will purge ./pad/" PURGEPAD | |
[[ "$PURGEPAD" == "n" ]] || purgepad | |
read -sn1 -t9 -p "ctrl-c to cancel: in 10s I will assume all files in pwd are\ | |
.mp3 and copy each to the same in ./pad after padding each with a \ | |
random amount silence averaging less than 60s" DOPAD | |
[[ "$DOPAD" == "n" ]] || dopad | |
read -sn1 -t9 -p "ctrl-c to cancel: in 10s this will proceed to cat all of the \ | |
padded sounds together in ./pad/out.mp3" DOCAT | |
[[ "$DOCAT" == "n" ]] || docat | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment