Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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
    There are a couple of ways of doing a loop like you need.

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

    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:

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

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

  3. #3
    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. $spacer_open
  5. #4
    Linux Engineer
    Join Date
    Apr 2005
    Try doublequoting your variable? Dunno if that would help... But it's worth a try.
    Debian Jessie x86_64 & armhf :: LibreELEC is the solution for your Linux-based HTPC setups.

  6. #5
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    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.
    find /media/cdrom -iname '*.mp3' | while read name; do
        outname="$(basename "$name")"
        lame --decode "$name" "$outname"
    The output files will be placed in the current directory.

  7. #6
    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.

  8. #7
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    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:
    $ filename=/some/file/
    $ echo "${filename#*/}"
    $ echo "${filename##*/}"          # Indeed, this has the same effect as basename
    $ echo "${filename%.*}"
    $ echo "${filename%%.*}"
    Last edited by Dolda2000; 01-27-2006 at 03:04 PM.

  9. #8
    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