Automation: Using Audacity commands in python to compare two audio files to see if they're the same

Hello peeps! I’m relatively new to python, and want to create an automated test that compares 2 signals, and tries to determine if they’re the same.

My rough plan is to:

  1. Create a new track
  2. Record some baseline audio onto track
  3. Invert that track
  4. Import audio with similar/same information on to a new track
  5. Open the “Contrast Analyzer” tool in the analyze section
  6. Measure the RMS of both waveforms
    Result: Output the difference between the 2 signals

In this test, I don’t necessarily care about the “Contrast result” section in the tool. I really only want the output of the “Difference” section. Alternatively, there is a “Measure RMS” tool which outputs the RMS of each track in a dialogue box, but there doesn’t seem to be a scriptingID for it. Is the plan above the best way to go about this? Or is there a better way?

For extra clarity, the 2 waveforms when compared don’t have to be exactly the same, but I may have to do some manual testing to figure out an acceptable tolerance level. For now I just want to be able to implement the functionality as described in the above test steps, then iterate to figure out how to accurately report the success/failure conditions. Any tips?

I’ve never used Python but you might be able to make a macro (which I also have never done). :wink:

Be aware that there’s a “weakness” with this method - The “sound of the difference” isn’t the same as “the difference in the sound”.

If the subtraction gives you silence, or a “quiet” result, you can be 100% sure that there is no difference or that the difference is small.

But its not reliable the other way around. You can get a big difference file when they both sound identical…

On obvious example is if you delay one copy by a few milliseconds. The sound doesn’t change at all but the difference will be “louder” than either file alone.

Or, inverting doesn’t change the sound. So if “B” happens to be an inverted copy of “A” there will be no difference in sound. But when you invert it again it’s back in-phase and you’ll be “subtracting a negative” (adding) and you’ll get a result with double the volume (+6dB).

MP3 introduces phase shifts which also mess-up the subtraction and the “difference” doesn’t usually sound like an actual compression artifact (if you can hear any compression artifacts.)

1 Like

Spectral subtraction rather than inversion method.

I think you may be there for a while.

As DVDDoug, above, you can have two or more performances that sound the same, but are electrically (or digitally) very different.

In real world, import an MP3 into Audacity and immediately export a WAV (Microsoft) file and save an Audacity Project. Those three will be wildly different in size and crazy different digitally, but sound exactly the same.

This is even beyond having one slightly louder in volume or one slightly later than the other…or both.

This may be a good time to find out what the actual job is. All we know is your interpretation of the job. There may be an AI tool that can handle this before lunch.

Koz

This topic was automatically closed after 30 days. New replies are no longer allowed.