Created
June 24, 2019 01:04
-
-
Save vanjac/2557552cb43a6da4029c7522eceb91dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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