Search code examples
pythonaudiosample-rate

Check audio's sample rate using python


I have over a thousand audio files, and I want to check if their sample rate is 16kHz. To do it manually would take me forever. Is there a way to check the sample rate using python?


Solution

  • Python has a builtin module dealing with WAV files.

    You can write a simple script that will iterate over all files in some directory. something along the general lines of:

    import os
    import wave
    for file_name in os.listdir(FOLDER_PATH):
        with wave.open(file_name, "rb") as wave_file:
            frame_rate = wave_file.getframerate()
            .... DO WHATEVER ....