Git Repos / dotfiles / bin / sox_spectrogram.sh
Last update to this file was on 2024-01-02 at 05:12.
Show sox_spectrogram.sh
#!/bin/sh
#
# Copyright (c) 2016-2022, Cameron Vanderzanden. Available under the
# terms of the 2-clause BSD license. Please see the file "LICENSE" in
# the root dir of this repository for more information.
#
#- sox_spectrogram.sh 2016/07/14 cev, last updated 2022/01/29
## Usage: sox_spectrogram.sh [-hV] [-o outputfile] <audiofile>
##
## Frontend for sox -n spectrogram. By default, generate a temporary
## spectrogram of <audiofile> using sox and display it to the screen
## with an image viewer. If -o outputfile is specified, then instead
## generate a spectrogram image file of name outputfile and exit.
##
## -h Show help
## -o Output file name
## -V Print version info
# TODO: implement option to choose image viewer; currently xdg-open
[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh
self="${0##*'/'}"
comment=""
outfile=""
shortname=""
tmpfile=""
cleanup() {
if [ "$tmpfile" -a -r "$tmpfile" ]; then rm "$tmpfile"; fi
}
die_nofile() {
print_nofile
exit 1
}
die_filenotfound() {
print_filenotfound "$*"
exit 1
}
x_spectrogram() {
sox "$1" -n spectrogram -h -m -t "$shortname" -c "$comment" -o "$2"
}
while getopts "ho:V?" option; do
case $option in
h) print_help && exit ;;
o) outfile="$OPTARG" ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done
[ $# -lt 1 ] && die_nofile
[ ! -f "$*" ] && die_filenotfound "$*"
# TODO: third option: auto-generate output file name based on input file name.
# something like:
# for i in *mp3; do
# sox "$i" -n spectrogram -c "$i" -o "$(basename "$i" ".mp3") [spec].png"
# done
shortname="$(basename "$*")"
comment="$(file -b "$*")"
if [ "$outfile" ]; then
x_spectrogram "$*" "$outfile"
else
trap cleanup EXIT
tmpfile=$(mktemp ${TMPDIR:-/tmp}/${self}.1.XXXXXXXX)
x_spectrogram "$*" "$tmpfile"
xdg-open "$tmpfile"
fi
Return to the top of this page or return to the overview of this repo.
Log sox_spectrogram.sh
Date | Commit Message | Author | + | - |
---|---|---|---|---|
2024-01-02 | Change from FreeBSD to Linux, other minor changes | cev | +1 | -1 |
2022-01-29 | Adding first batch of audio file handling scripts. | cev | +75 |
Return to the top of this page or return to the overview of this repo.