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?
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 ....
For .wav files the solution might be:
from scipy.io.wavfile import read as read_wav
import os
os.chdir('path') # change to the file directory
sampling_rate, data=read_wav("filename.wav") # enter your filename
print sampling_rate
I end up getting unknow file format error with the wave package from python. wave-error
Alternatively the sox wrapper in python works for me. pysox
!pip install sox
import sox
sox.file_info.sample_rate("file1.wav")
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With