Skip to content

Instantly share code, notes, and snippets.

@vanjac
Created June 24, 2019 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanjac/2557552cb43a6da4029c7522eceb91dc to your computer and use it in GitHub Desktop.
Save vanjac/2557552cb43a6da4029c7522eceb91dc to your computer and use it in GitHub Desktop.
import wave
import sys
import os
import array
if len(sys.argv) != 2:
print("please specify the name of the folder")
exit()
FILE_PATH = sys.argv[1]
for file in os.listdir(FILE_PATH):
if file.endswith(".wav"):
wav = wave.open(os.path.join(FILE_PATH, file))
sample_width = wav.getsampwidth()
if not sample_width in [1, 2]:
print("{} format not supported sorry".format(file))
continue
frames = wav.readframes(wav.getnframes())
if sample_width == 1:
values = array.array('B', frames)
else: # sample width 2
values = array.array('h', frames)
silent = True
for v in values:
if sample_width == 1:
v -= 128
if abs(v) >= 12:
silent = False
break
wav.close()
if silent:
print("{} is silent, deleting!".format(file))
os.remove(os.path.join(FILE_PATH, file))
else:
print("{} is not silent".format(file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment