Created
February 20, 2017 03:46
-
-
Save Yuffster/de1386f386175b51d47e6b8b901e2cd8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from pydub import AudioSegment | |
def chunks(l, n): | |
for i in range(0, len(l), n): | |
yield l[i:i + n] | |
def convertAudio(f): | |
sound = AudioSegment.from_mp3(f) | |
volumes = [ c.max for c in chunks(sound, 20) ] # 20ms chunks | |
ts = [] | |
last = None | |
i = 0 | |
for v in volumes: | |
b = v > 3000 | |
if last is None and b is False: | |
continue | |
if last == b: | |
i += 1 | |
else: | |
last = b | |
ts.append(i) | |
i = 0 | |
return ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment