July 11

Linux: Batch convert mp3 to wav

Install mpg123
sudo apt-get install mpg123

Make certain all of your mp3 audio files are in the same directory.

Put the following code into a file:
vi mp3towav.sh

###Start of script###
for i in *.mp3 ; do
echo $i
b=`basename $i .mp3`
mpg123 -w $b.wav input $i
done
###End of script###

Put the conversion script into the same directory as your mp3s
chmod +x mp3towav.sh

Simply run ./mp3towav.sh

 

* Note – If there are spaces in your file names you will get errors and the conversion process will fail.
The easiest way to fix this is to replace the spaces with another character like a dash

Here is a script to remove the spaces in a file and replace them with dashes:
vi spacetodashconvert.sh

###Start of script###
#!/bin/bash

ls | while read -r FILE
do
mv -v “$FILE” `echo $FILE | tr ‘ ‘ ‘-‘ `
done
###End of script###

Run this in the same directory that contains your mp3 files, then re-run the mp3towav script


Copyright 2021. All rights reserved.

Posted July 11, 2013 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B