3

Does anyone know how to batch prepend one audio file to another audio file and create a separate output for each. E.g.

Files:

Static.wav
Audio1.wav
Audio2.wav
Audio3.wav

I need a script that can do the following:

Static.wav + Audio1.wav = Audio1out.wav
Static.wav + Audio2.wav = Audio2out.wav
Static.wav + Audio3.wav = Audio3out.wav
Static.wav + Audio*.wav = Audio*out.wav
(* = wildcard)

Thanks!

3 Answers3

5

Yet another update: This is similar to the solution provided here. This solution uses ffmpeg for conversion (which is something you don't need) and sox for combining the files.

You would only need to do download sox and use it. The script below will do what you want, but the output filenames would not be exactly how you want them to be. But you can handle the renaming part differently.

Create a shell script (combine.sh or some other name) with the following commands and run it whenever necessary:

for i in Audio*.wav
do
    sox -m Static.wav $i {$i}out.wav
done    

Please refer here for more information on using sox.

M K
  • 2,744
  • 2
  • 15
  • 20
  • Almost... I wanted to create a batch process where I don't need to define each input file, but where I can use a wildcard or something. Something like Static.wav *.wav > File1new.wav but instead of joining everything together, it outputs separate files for each input. – Matteo Cuellar Vega Oct 16 '12 at 13:12
  • @MatteoCuellarVega this code will still create separate output files. Please update the question with the exact requirement. – M K Oct 16 '12 at 13:15
  • Will do, just one question. Executing your shell script return errors... cat: inputfiles/inputfiles/song1.txt: No such file or directory -bash: Outputinputfiles/song1.txt: No such file or directory – Matteo Cuellar Vega Oct 16 '12 at 13:18
  • I did change the variable (File1) and created the right folder structure if you are wondering... – Matteo Cuellar Vega Oct 16 '12 at 13:20
  • +1 for M K. You have patience re-re-re-answering this :) –  Oct 16 '12 at 13:39
  • Yeah, thanks! Unfortunately I can't vote up yet :( Anyway, I'll manage to get it to work! Thanks to all! – Matteo Cuellar Vega Oct 16 '12 at 13:51
  • Since this is for music files, there are similar questions and answers on this site. I've pointed to one and edited the answer. – M K Oct 16 '12 at 15:54
  • Finally, a simplified script to do what you want. – M K Oct 16 '12 at 16:04
0

A fairly simple line would give you the output n.

echo $(cat file1)$(cat filen)
slhck
  • 223,558
  • 70
  • 607
  • 592
0
file="madonna.wav"

do_combine () {
    input_filename="$@"

    # Strip the path
    input_filename="${input_filename##*/}"

    # Parameter expansion with input_filename below strips the extension
    cat "$file" "$input_filename" > "newfile.${input_filename%.*}.wav"
}

So you can do this:

do_combine "metallica.wav"

and the resulting file is named "newfile.wav" and is a combination of Madonna and Metallica, starting with the material girl herself.

cat is a legitimate method of combining wav files.

So if you wanted to combine all files in a specific direcory:

for file in /path/to/dir/*.wav
do
    do_combine "$file"
done

Might be a bug in there, it was done off the cuff. Having a program to combine madonna files would be really awkward to explain.

UtahJarhead
  • 2,027
  • 2
  • 13
  • 15
  • Hey thanks, unfortunately it returns (-bash: newfile./input/*.txt: No such file or directory). No worries however, I'll play around with the script to see if I can get it to work. Thank you. – Matteo Cuellar Vega Oct 16 '12 at 13:59
  • Ah, I see. Please see the updated script. I'll have it fixed in 2 minutes. – UtahJarhead Oct 16 '12 at 14:11
  • The issue is that the input filename has a path and I didn't account for it. I added a line that will strip the path out. – UtahJarhead Oct 16 '12 at 14:13
  • 1
    cat is NOT a legit way to combine wav files. some aps might be able to read it but the results are not valid. Use sox or something like that instead! – Bjorn Roche Oct 17 '12 at 15:01