LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to automatically merge 2 wav files in 1 mp3 file (http://www.linuxquestions.org/questions/linux-newbie-8/script-to-automatically-merge-2-wav-files-in-1-mp3-file-772456/)

Jackuss 11-30-2009 09:12 AM

Script to automatically merge 2 wav files in 1 mp3 file
 
hello,

I'm not entirely new to Linux, but I am new to scripting in Bash. Can anybody help me with the following:

Short Question:

How can I automatically merge 2 wav-files into 1 mp3 file?

Explanation:

I play in a band and last saturday night we recorded some of our songs on a simple digital recording device. This device create two wav-files, 1 for the frontmicrophone and 1 for the backmicrophone.

I want to merge these files together, but since we recorded a lot of things, we got a lot of files to merge. I don't want to do all that work by hand. :)

Now I want to save the files in 1 directory, and I want to create a script which search for a particular pattern in a file name (eg. "MC0001F.wav" and "MC0001B.wav" so the script must search for "*F.wav" and "*B.wav"). When he found a match, he must merge those files into 1 mp3 (I guess I can use something like 'sox' for that).

Can anybody help me with this?

Thanks in advance.

Jackuss

David the H. 11-30-2009 12:20 PM

Assuming you want to process the current directory, and that the filenames are as you gave, identical except for F.wav/B.wav, something like this should work:

Code:

for f_file in ./*F.wav; do

b_file="${f_file/F.wav/B.wav}"  #replaces "F.wav" with "B.wav" in the filename

<put sox command here with input $f_file $b_file>

done

You'll have to work out your own command to actually combine the files though, as I'm not experienced in that. I'm not even sure exactly what you want the final output to be like.

Jackuss 12-01-2009 01:10 PM

<problem solved>
 
David The H.

Thanks for your reply, I tried it and it worked for me. For the record, This is what I did to make it work:
Code:

for f_file in ./*F.wav; do

b_file="${f_file/F.wav/R.wav}"  #replaces "F.wav" with "R.wav" in the filename

# <put sox command here with input $f_file $b_file>

soxmix $f_file $b_file -r 44100 /media/58E5-6EB7/mp3/$b_file.mp3
done

Note:The filenames didn' t end with a B but with an R. And the location where the files are places is my USBstick.

Thanks again.

Regards,

Jackuss

David the H. 12-01-2009 03:03 PM

Glad to hear it. Incidentally, you can use a similar parameter substitution to strip the original .wav extension off the name, before adding the .mp3.

Code:

soxmix $f_file $b_file -r 44100 /media/58E5-6EB7/mp3/${b_file%.wav}.mp3

cfriisha 12-01-2009 06:31 PM

In case you want to do a really good job in terms of start finish, sync, fading, volume, etc. then Ardour is really good, but with a steep learning curve if you are not used to mixing.

Jackuss 12-02-2009 01:32 AM

Quote:

Originally Posted by cfriisha (Post 3776345)
In case you want to do a really good job in terms of start finish, sync, fading, volume, etc. then Ardour is really good, but with a steep learning curve if you are not used to mixing.

Hello,cfriisha

I already use Ardour and it is indeed a great program, with some rough edges unfortunately.

The reason I wanted to create a script is that, last Saturday we recorded all our songs on an simple recording device (The "Zoom H 2" if you are interested), and recorded about 10 - 15 songs. We didn't want to mix it, just record so we could practice.

You can understand that I didn't want to manually import all the the *F.wav and *R.wav files, and then export them with a program like Ardour or Audacity.

When we want to mix our music, I think we are going to record on a multi-tracker. That way I can select all the instruments apart and mix them appropriately.

Thanks again.


All times are GMT -5. The time now is 09:34 PM.