2

Scenario

With a simple tool I developed in C#, I extracted all the wav tracks contained in the BIK video files of a game using the binkconv.exe CLI tool from RAD Video Tools.

In total I have extracted 500 videos then I have 500 directories, each directory contains 4 tracks with this incremental filenaming:

  • VideoName_01.wav
  • VideoName_02.wav
  • VideoName_03.wav
  • VideoName_04.wav

Problem

Now I'm stuck with the procedure, because I need to fuse/mix the four wav files into a new unique wav file.

I could do this manually with applications as Audacity, but we are talking about +500 folders in which each one contains 4 wav files, its an insane manual job then I need to find a way to automate it.

I need to do this via commandline application. or with a .Net audio lib that can fuse Wave audio files.


Question

Which free command-line audio editing software could fuse wave files into a new one?.


Research

This is a list of Software that I have installed:

Please note that I'm only pointing that I have installed those apps, but I'm not sure if one of the mentioned apps could do this task via command-line.

I think SoX maybe could be the best approach to do this, but I don't know how to.

  • SoX will do this, as you've suggested. The man page shows: sox short.wav long.wav longer.wav concatenates two audio files. If you add more files on the invocation, they will be concatenated in order supplied. The last argument is the output file. – baitisj Oct 17 '15 at 7:23
  • @baitisj But I don't want merge/concatenate, I need to mix them. I found that the command to do it is -m (in lowercase. in uppercase -M is for merge) that mixes the supplied files. thanks a lot please feel free to post an answer to mark it as accepted. – ElektroStudios Oct 17 '15 at 7:34
4

You can use FFmpeg:

  • Free and open-source
  • Runs on Windows, OS X, Linux, Android
  • Is CLI so you can batch
  • Can overlay two audio files, e.g. ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex amerge -c:a libmp3lame -q:a 4 output.mp3
  • seems that ffmpeg is a better choice than SoX because at least in the exmaple you'd shown I can specify output encoding parameters to use mp3 or wav or whatever. thanks. – ElektroStudios Oct 18 '15 at 5:46
4

If you really would like to save some effort, install python, use pip install pydub to add pydub and then use os.walk something like:

import os
from pydub import AudioSegment

OUTNAME = "Mixed.wav"
def makemix(audiofiles, dirname):
    """ Mix a list of audio files to Mixed.wav """
    mix = AudioSegment.from_file(os.path.join(dirname, audofiles[0])
    for nextfile in audiofiles[1:]:
        layer = AudioSegment.from_file(os.path.join(dirname, nextfile)
        mix.overlay(layer)
    mix.export(os.path.join(dirname, OUTNAME),  format='wav')

for (root, dirs, files) in os.walk('.'):
    if OUTNAME not in files:
         wavefiles = [fn for fn in files if fn.endswith('.wav')]
         if len(wavefiles) > 1:
              makemix(wavefiles, root)

This will traverse your directories, from the current directory, creating a Mixed.wav anywhere there are two or more wave files and no Mixed.wav so your 500+ plus directories will all get done. You may have to install ffmpeg as well.

  • Free, Gratis & Open Source
  • Work on Windows, OS-X & Linux
  • You could vary the loudness of some of the files if desired, etc.
  • Automates the lot.
  • Can be adapted.
  • You can set it going and go out for a pint or something.
  • 1
    I really appreciate how using Python in conjunction with these libraries makes for implicit clarity. My knee-jerk reaction would have been to use SoX, but I like this solution so much more... – baitisj Oct 18 '15 at 8:28
2

You can use SoX (Sound eXchange):

  • free
  • open source
  • Windows / Linux / Mac
  • CLI
  • Can overlay two audio files, e.g. sox --combine {mix|merge|mix-power} track1.mp3 track2.mp3 output.mp3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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