I am trying to sort through a bunch of audio samples where some of them are fully blank. Can someone help me figure out the best way to detect if a file is blank (silent) for its duration? I've found a bunch of ways of reading wav files, but thus far nothing on how to determine if a file is blank.
The code I have thus far:
import soundfile as sf
path = '/Users/InNov8/Desktop/Elektron_Octotrack_Chain_Maker_v2/Bar 25 -- High 303/'
file1 = 'Bar 25 --- [tr] --- 4-Kick 2.aif' # blank
file2 = 'Bar 25 --- [tr] --- 10 Shaker.aif' # not blank
file3 = 'Bar 25 --- [tr] --- 14 HARD SNARE.aif' # blank
f1 = path + file1
x, fs = sf.read(f1)
print x
print fs
f2 = path + file2
x, fs = sf.read(f2)
print x
print fs
Check that the data in the file contains only zeroes. The
soundfilemodule is based on NumPy, so you can do that using some functions which are a fair bit faster than just usingany(). See: Test if numpy array contains only zerosNote that just because a file sounds blank doesn't mean that it's actually all zeroes. It could just be very quiet, or contain a small amount of noise.