Possible to run RMS analysis on batches of tract files?

I would like to generate RMS values for hundreds of sound files for a research project. I hope there is a way to do so - otherwise I have to open each one, select the whole track, generate the RMS value, then transcribe the value to a spreadsheet.

Have you considered using Python?

Thanks Steve, It is likely a great suggestion. I am not familiar with Python. I think I need to find a research collaborator who does! Jim

It could also be done with Audacity’s built-in scripting language “Nyquist”, but it is just as easy with Python, and I’d expect that it’ll be easier to find a collaborator that knows a bit of Python. A Python solution will also be more flexible, and probably a lot quicker / more efficient.

If your sound files are in WAV format, then a Python solution is even easier as Python has the built-in ability to read WAV files (using the wave module).

Here’s the basic approach that I would take for measuring the RMS of 16-bit mono WAV files:

import wave
import numpy as np

def calculate_rms(file_path):
    """Return RMS of a mono WAV file."""
    with wave.open(file_path, 'rb') as wav_file:
        samples = wav_file.getnframes()
        audio_data = wav_file.readframes(samples)
        # Convert the audio data to a NumPy array
        audio_array = np.frombuffer(audio_data, dtype=np.int16) / 2 ** 15
        return np.sqrt(np.mean(np.square(audio_array)))

# Example usage.
# (You will probably want to iterate through a
# list of files rather than one by one.)
file = "/path/to/mono_file.wav"  # Replace with actual path.

rms_value = calculate_rms(file)

# You will probably want to write to a file  rather than just
# printing the value.
print(f'RMS value: {rms_value} linear, {20 * np.log10(rms_value)} dB.')

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