Created
January 22, 2017 01:54
-
-
Save pR0Ps/d4191ce8f51a206680dc3d9c73ad1c23 to your computer and use it in GitHub Desktop.
Generates spectrogram and waveform images from flac 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/sh | |
# Requires: audiowaveform (https://github.com/bbc/audiowaveform), metaflac, sox | |
zoom_start=60 | |
zoom_duration=4 | |
zoom_end=$((zoom_start + zoom_duration)) | |
if [ $# -lt 1 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then | |
echo "Generates spectrogram and waveform images from flac files" | |
echo "" | |
echo "For each type, an image of the entire file will be made, as well as a" | |
echo "more detailed analysis of $zoom_duration seconds of audio starting $zoom_start seconds in." | |
echo "" | |
echo "The generated files will have the same name as the input files" | |
echo "with extra identifiers appended." | |
echo "" | |
echo "usage: `basename $0` file [file ..]" | |
echo "" | |
echo "positional arguments:" | |
echo " file The flac file(s) to process" | |
exit 0 | |
fi | |
# Check deps | |
for cmd in 'audiowaveform' 'metaflac' 'sox'; do | |
if ! command -v "$cmd" > /dev/null ; then | |
echo "Missing dependency '$cmd'" | |
exit 1 | |
fi | |
done | |
count=0 | |
success=0 | |
for x in "$@"; do | |
((count++)) | |
echo "Processing file $count/$#: '$x'" | |
# Generate spectrograms | |
sox "$x" -n remix 1 spectrogram -X 500 -y 1025 -z 120 -w Kaiser -S "$zoom_start" -d "$zoom_duration" -o "${x}_spectral_zoom.png" || continue | |
sox "$x" -n remix 1 spectrogram -x 3000 -y 513 -z 120 -w Kaiser -o "${x}_spectral.png" || continue | |
# Get audio length and generate waveforms | |
len=`metaflac --show-total-samples --show-sample-rate "$x" | tr '\n' ' ' | awk '{print int($1/$2)}'` || continue | |
audiowaveform -i "$x" -o "${x}_waveform_zoom.png" -w 2000 -h 1024 -s "$zoom_start" -e "$zoom_end" > /dev/null || continue | |
audiowaveform -i "$x" -o "${x}_waveform.png" -w 3000 -h 512 -s 0 -e "$len" > /dev/null || continue | |
((success++)) | |
done | |
echo "" | |
echo "Sucessfully generated images for $success/$count files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output images: http://imgur.com/a/Kv6KG