Last active
March 22, 2016 23:05
-
-
Save michaellindman/5385cae1bf2a66a69741 to your computer and use it in GitHub Desktop.
Convert sound files to mp3 using lame
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 | |
# loop through files in the currently active directory | |
for f in *.$1 | |
do | |
# case statement for arguments (you can convert wav, flac, and ogg to mp3) | |
case $1 in | |
wav) | |
# converts wav files to mp3 using lame | |
lame -b320 "$f" "${f%.*}".mp3 | |
;; | |
flac) | |
# converts flac files to mp3 using flac/lame | |
flac -cd "$f" | lame -b320 - "${f%.*}".mp3 | |
;; | |
ogg) | |
# converts ogg to mp3 using oggdec/lame | |
oggdec "$f" -o - | lame -b320 - "${f%.*}".mp3 | |
;; | |
*) | |
echo "Usage: $0 {wav|flac|ogg}" | |
esac | |
shopt -s nullglob | |
# check for mp3 files in current directory | |
if [[ -n $(echo *.mp3) ]]; then | |
# check if mp3 directory exists | |
if [ ! -d "mp3" ]; then | |
# creates mp3 directory if it doesn't already exist | |
mkdir mp3 | |
fi | |
# move all mp3 files to the mp3 directory | |
mv *.mp3 mp3/ | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment