Skip to content

Instantly share code, notes, and snippets.

@Yuffster
Created February 20, 2017 03:46
Show Gist options
  • Save Yuffster/de1386f386175b51d47e6b8b901e2cd8 to your computer and use it in GitHub Desktop.
Save Yuffster/de1386f386175b51d47e6b8b901e2cd8 to your computer and use it in GitHub Desktop.
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