Check audio's sample rate using python

ash picture ash · Apr 19, 2017 · Viewed 13.7k times · Source

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?

Answer

ehudk picture ehudk · Apr 19, 2017

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 ....