PDA

View Full Version : Howto: mp3 to wav script


Thund3rstruck
July 9th, 2006, 10:44 AM
I'm sure there is something out there that does this already but I make a lot of CDs and because of this a needed a very quick method for batch converting .mp3 files to .wavs, to be burned to CDR.

This script will loop through all the files in the folder you specify and convert them from .mp3 to .wav

copy the following code and save it in a file mp32wav.sh


#!/bin/bash
#Script: mp32wav script (requires mpg123 package)
#Purpose: Loops through a path and convert all the mp3s to wavs
#
#usage: mp32wav [Path]

count=0

Convert(){
mpg123 -b 10000 -s "$x" | sox -t raw -r 44100 -s -w -c2 - "`sed s/mp3/wav/ sedEdit`"
}

syntax_error(){
clear
echo "Mp32Wav - Convert Mp3 Files To Wav Files"
echo "script syntax: mp32Wav <path>"
echo ""
exit 0
}

if [ -n "$1" ]; then
cd "$1"
for x in *.mp3
do
let "count += 1"
echo "$x" > sedEdit
Convert
done
else
syntax_error
fi
echo "$count mp3s found and converted to wavs... [Baileysoft 2005]"
rm sedEdit
exit 0



1. install mpg123

sudo apt-get -y install mpg123

2. make the file executable

chmod +x mp32wav.sh

3. copy to /usr/bin

sudo cp mp32wav.sh /usr/bin/mp32wav


Usage:
mp32wav <path>

example: mp32wav /tmp/mp3
Converts all the mp3s in /tmp/mp3 to wavs

example: mp32wav `pwd`
converts all mp3s in your current directory to wavs

gorilla_king
July 9th, 2006, 01:17 PM
wow, thanks man, that's pretty cool. I usually make mp3 cd's because of my cd player in car can handle mp3's but that's great. Now i can use the normal cd writer for when i need to make real cd's. Thanks. And could i get permission to offer thie bash file on my site with your name and webaddress/email with it? Thanks. Keep up the awesome work.

chajuram
July 9th, 2006, 01:22 PM
Hi,

There is an app called audio-convert, which I think does similar things please see http://www.ubuntuforums.org/showthread.php?t=82806&highlight=audio-convert

Chajuram.

Thund3rstruck
July 9th, 2006, 01:26 PM
@gorilla_king,

Feel free to use it however you want, and/or improve on it. I was thinking of adding a segment in it as well to call cdrecord as well so it would convert the files and burn them automatically.

@chajuram,

As I said in the article, I'm sure there are a ton of ways to acheive this. I just wanted something small, simple, and fast.


I find myself, making CDs all the time so for me the easiest way is to copy the mp3s into a specific folder (albumName) and run the script against the folder. In a matter of seconds I have wav files ready to be burned to traditional CDs (the ones that will play in any car).

gorilla_king
July 9th, 2006, 11:07 PM
@gorilla_king,

Feel free to use it however you want, and/or improve on it. I was thinking of adding a segment in it as well to call cdrecord as well so it would convert the files and burn them automatically.


Alright i'll add it later, thank you.

Lucho77
August 8th, 2006, 11:49 PM
Hey, thanks for this nice 'How to' I followed all the steps and everything seems to be ok, but when I executed the script said;
/usr/bin/mp32wav: line 10: sox: command not found
Could you please tell me what should I do now?

agc
August 9th, 2006, 12:45 AM
Sox is a program that translates sound files
from one type to another.

Just type:

sudo apt-get install sox

and you will install sox.

Lucho77
August 9th, 2006, 10:50 AM
'agc' thank you so much, now it is working like a charm.

colourful-leaves
February 26th, 2009, 09:17 AM
hallo @ all

I use K3b on Ubuntu 8.10
i installt

apt-get install libk3b3-extracodecs

and?
it works

g.
richy
:guitar:
www.colourful-leaves.de