script for making timelapse audio files
This file contains 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 | |
# | |
# timelapse_audio.sh | |
# | |
# | |
# take an input file, $1 | |
# find length on input file | |
# snip short pieces of length $2 | |
# spacing between snippet starts $3 | |
# put a crossfade between snippets $4 | |
# | |
# USAGE = timelapse_audio.sh filename 1.5 75 0.5 | |
# | |
#echo "this will work with mp3 files but it's much faster with .wav" | |
#echo "convert to wav first, then run this script" | |
# | |
if [ "$3" == "" ]; then | |
echo "Usage: timelapse_audio.sh filename 1.5 75 0.5" | |
exit 1 | |
fi | |
filename=$1 | |
snip_length=$2 | |
snip_spacing=$3 | |
crossfade_duration=$4 | |
# (| cut -d"." -f1) gets rid of the decimal value of seconds | |
length_seconds=`sox --info -D ${1} | cut -d"." -f1` | |
echo "original length=${length_seconds}" | |
echo "Pls enter anything:\c" | |
read name | |
echo "You entered $name." | |
number_snips=length_seconds/snip_spacing | |
# generate the snippets | |
for (( i = 0 ; i <=number_snips ; i++ )) | |
do | |
let "counter=10000+$i" | |
let "snip_start=${snip_spacing}*${i}" | |
sox $1 snip${counter:1}.wav trim $snip_start $2 | |
echo "sox $1 snip${counter:1}.wav trim $snip_start $2" | |
done | |
echo "${counter:1} snippets generated" | |
# create dummy file | |
#sox $1 mix2.wav trim 0 1 | |
mv snip0001.wav mix2.wav | |
# mix all the snips... | |
for f in snip*.wav; do | |
# add snip*.mov to file mix2.wav | |
./crossfade_cat.sh $crossfade_duration mix2.wav $f yes yes | |
# output of crossfade.cat is mix.wav | |
mv mix.wav mix2.wav | |
done | |
new_length=`sox --info -D mix2.wav | cut -d"." -f1` | |
# you can change this part of the code to name the file differently. | |
# just change tla_ to whatever you want. | |
mv mix2.wav tla_${1}_${2}_${3}_${4}.wav | |
echo "assembled snippets, output tla_${1}" | |
echo "old length = ${length_seconds}, new length =${new_length}" | |
let "shortening_ratio=${length_seconds}/${new_length}" | |
echo "shortening factor = ${shortening_ratio}" | |
rm snip*.wav | |
echo "deleted snippets" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment