Find the answer to your Linux question:
Results 1 to 8 of 8
hi. i need a simple script to decode a set of mp3 files to wav to burn them after this. let's say i have the mp3 media mounted in in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    zyd
    zyd is offline
    Just Joined!
    Join Date
    Nov 2005
    Posts
    44

    simple scrip to decode audio


    hi. i need a simple script to decode a set of mp3 files to wav to burn them after this. let's say i have the mp3 media mounted in in the /media/cdrom folder .how could i decode all of them using a simple script?.
    i will use lame with de --decode option to do the job. i know i have to use a for loop but i haven't (yet) learnt to do scripts.
    if you could also tell me how to after all the decode stuff has been done burn it to a cd using cdrecord i would be very pleased.
    thanks in advance

  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    682
    There are a couple of ways of doing a loop like you need.

    Code:
    for i in /media/cdrom/* ; do echo $i ; done
    or

    Code:
    find /media/cdrom/ -name "*.mp3" -exec echo "{}" ";"
    Should show you how the loop works, replace echo with the right lame command and you should be set. (I don't know the exact lame command you need so I put something I knew would work)

    The magic of cdrecord should go something like this:

    Code:
    cdrecord -audio -v *.wav
    Let us know how you get on.

    Chris...
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    zyd
    zyd is offline
    Just Joined!
    Join Date
    Nov 2005
    Posts
    44
    well, it didn't result so well. i wasn't able to use the find command option since the lame command require the name of the infile and the outfile and i didn't know how to specify a unique name in every iteration.
    neither the for option resulted since lame threw an strange error.
    i used it like this:
    for i in /media/cdrom/* ; do lame --decode $i $i.wav ; done

    the error message told me that the argument was exceeded

  4. #4
    Linux Engineer
    Join Date
    Apr 2005
    Location
    Belgium
    Posts
    1,429
    Try doublequoting your variable? Dunno if that would help... But it's worth a try.
    ** Registered Linux User # 393717 and proud of it ** Check out www.zenwalk.org
    ** Zenwalk 2.8 - Xfce 4.4 beta 2- 2.6.17.6 kernel = Slack on steroids! **

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    If it were me, I'd do it as follows. Feel free to ask away if there are any syntactical details that you don't understand.
    Code:
    #!/bin/sh
    find /media/cdrom -iname '*.mp3' | while read name; do
        outname="$(basename "$name")"
        outname="${outname%.mp3}.wav"
        lame --decode "$name" "$outname"
    done
    The output files will be placed in the current directory.

  6. #6
    zyd
    zyd is offline
    Just Joined!
    Join Date
    Nov 2005
    Posts
    44
    it worked perfectly. the only part that i don't understand is the generation of the outputname, it would be great if you explained this to me.

  7. #7
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    That's a variable substitution syntax in bash, which is used for cutting in values. Basically, it takes the variable name from the left side of the % sign, and a pattern from the right side of the % sign. Then, if the rightmost part of the value of the variable matches the pattern, it is removed before the value is substituted.

    If you use a # sign instead of a % sign, you can cut the leftmost part of a variable's value instead. You can also use glob patterns (as in filename wildcards) to match stuff. For example, ${filename%.*} would cut any extension. When using wildcards like that, you can also choose to use %% instead of % and ## instead of # to make the wildcards match the longest possible string they can (when using % or #, it will match the shortest possible). For example:
    Code:
    $ filename=/some/file/somewhere.foo.bar
    $ echo "${filename#*/}"
    some/file/somewhere.foo.bar
    $ echo "${filename##*/}"          # Indeed, this has the same effect as basename
    somewhere.foo.bar
    $ echo "${filename%.*}"
    /some/file/somewhere.foo
    $ echo "${filename%%.*}"
    /some/file/somewhere
    Last edited by Dolda2000; 01-27-2006 at 02:04 PM.

  8. #8
    zyd
    zyd is offline
    Just Joined!
    Join Date
    Nov 2005
    Posts
    44
    ok, now everything is understood. thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •