LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   combine multiple wav files together with different sample rates / channels / bits (https://www.linuxquestions.org/questions/programming-9/combine-multiple-wav-files-together-with-different-sample-rates-channels-bits-721493/)

PiNPOiNT 04-24-2009 04:54 PM

combine multiple wav files together with different sample rates / channels / bits
 
I have a folder with lots of wav files, all different samples/ rates/ bits

Most of them are just a mix of mono or stereo

is there a way using sox and bash, or another built in app that can convert them all to a uniform format?

paulsm4 04-24-2009 05:32 PM

Yes, of course ;-)

This page might give you some additional tips:

http://dsl.org/cookbook/cookbook_29.html

But my guess is you're going to have to figure out the "right" settings on a file-by-file basis, by trial and error...

IMHO .. PSM

ilikejam 04-24-2009 07:02 PM

Hi.

Not 'built in', but if you've got a copy of mplayer...
Code:

#!/bin/bash

if ! [ -e "$1" ]
then
    echo "$1 does not exist."
    echo "Exiting."
    exit 1
fi

INFILE="$1"

if file -L "$INFILE" | grep RIFF | grep PCM | grep "16 bit" | grep stereo | grep 44100 &> /dev/null
    then
    echo "$INFILE is already a 44100Hz 16bit LE file."
    echo "Exiting."
    exit 0
fi
if [ -e "$INFILE".wav ]
    then
    echo "Decode output file: $INFILE.wav already exists."
    echo "Exiting."
    exit 1
fi

if ! mplayer -vo null -vc null -af lavcresample=44100,channels=2,format=s16le -ao pcm:file="$INFILE".wav "$INFILE"
    then
    echo "Couldn't decode $INFILE"
    echo "Exiting."
    exit 1
fi

I called it 'any2wav' - run as:
$ for file in *; do any2wav "$file"; done
and it'll convert anything (even video audio tracks) to CD style .wav

I've got slightly different versions that do the same thing, but output mp3s or FLACs, if you're interested:

http://www.ilikejam.org/blog/unix/scripts.html

Dave


All times are GMT -5. The time now is 05:30 AM.