I have to mix audio data for a machine learning task.
The setting is the following: I have two folders of tracks. One contains background files with background noise, the other contains files with a sound to recognise.
Now I have to mix them together to get all permutations between each file from the first folder and each file from the second folder.
To give an example:
Folder One: b1, b2, b3
Folder Two: s1, s2, s3
Mixed Folder: s1b1, s1b2, s1b3, s2b1, s2b2, s2b3, s3b1, s3b2, s3b3
I am currently using Audacity to do this manually, but my deadline is in 8 days and I still have to do this with a couple dozen files.
So my question is if there is some way to automate this?
Or to make this task somewhat less time-consuming?
I know that it would probably be possible with Matlab, but I am searching a faster and easier way, hence I thought to try it here.
Here is my solution. I have realized it in C#. Just in case someone stumbles upon this.
class Program
{
// contains noise file names
static List<string> noiseFilesDir = new List<string>();
// contains sound file names
static List<string> soundFilesDir = new List<string>();
static string soxRoot = @"C:\Program Files (x86)\sox-14-4-2";
static void Main(string[] args)
{
foreach (string s in Directory.GetFiles(soxRoot + "\\NoiseFiles", "*.wav").Select(Path.GetFileNameWithoutExtension))
{
noiseFilesDir.Add(s);
}
foreach (string s in Directory.GetFiles(soxRoot + "\\SoundFiles", "*.wav").Select(Path.GetFileNameWithoutExtension))
{
soundFilesDir.Add(s);
}
var processStartInfo = new ProcessStartInfo();
processStartInfo.WorkingDirectory = soxRoot;
processStartInfo.FileName = "cmd.exe";
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
Process proc = Process.Start(processStartInfo);
using (StreamWriter sw = proc.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
//sw.WriteLine();
for (int i = 0; i < soundFilesDir.Count; i++)
{
for (int j = 0; j < noiseFilesDir.Count; j++)
{
string cmdString = string.Format(@"sox -m SoundFiles\{0}.wav NoiseFiles\{1}.wav MixedFiles\{0}{1}.wav", soundFilesDir[i], noiseFilesDir[j]);
sw.WriteLine(cmdString);
}
}
}
}
}
}