Skip to content

Instantly share code, notes, and snippets.

@briansorahan
Last active August 29, 2015 13:59
Show Gist options
  • Save briansorahan/10669324 to your computer and use it in GitHub Desktop.
Save briansorahan/10669324 to your computer and use it in GitHub Desktop.
Convert sound files to wav with mpg123 and sndfile-convert
#!/bin/bash
#
# Convert all soundfiles of a particular type located in the
# current directory to wav.
#
function convertToWav {
local ext="$1"; shift
for f in *.${ext}; do
# mp3 can't be converted by sndfile-convert
# use mpg123 instead
if [[ -n $(echo "$f" | grep mp3) ]]; then
mpg123 -w "${f/%.mp3/.wav}" "$f"
else
sndfile-convert "$f" "${f/%.${ext}/.wav}"
fi
done
}
convertToWav mp3
convertToWav flac
# add more extensions as appropriate
# see output of sndfile-convert for supported file types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment