Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
1  
Did you mean concatenate? Are these actually separate files or separate work sheets? –  Dave Oct 16 '12 at 11:36
    
Separate files. WAV audio files to be exact. –  Matteo Cuellar Vega Oct 16 '12 at 12:52
    
So you're looking to actually join 2 songs together programatically? So, you if song 1 was Madona and song 2 was Metallica, you'd end up with Madona and Metallica as 1 song? –  Dave Oct 16 '12 at 12:54
    
Yeah, exactly... Just that I want Madonna prepending all songs (well, not really, but you know!) –  Matteo Cuellar Vega Oct 16 '12 at 13:01
    
Please re-edit.. It still doesn't reflect what you want. –  Radoo Oct 16 '12 at 13:32

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
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 :) –  Radoo Oct 16 '12 at 13:39

A fairly simple line would give you the output n.

echo $(cat file1)$(cat filen)
share|improve this answer
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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.