Create a gist now

Instantly share code, notes, and snippets.

import numpy
import scipy.io.wavfile
import sys
rate, inp = scipy.io.wavfile.read(sys.argv[1])
inp = [x[0] for x in inp]
print("Loaded...")
lowpass = numpy.convolve(inp, [1 / 20] * 20, mode="same")
thrs = numpy.array([0 if x < 13000 else 30000 for x in lowpass])
lasth = -1
fsth = -1
silence = 0
fcnt = 0
for i, x in enumerate(thrs):
if x:
silence = 0
if fsth == -1:
fsth = i
lasth = i
elif silence < 600:
silence += 1
elif fsth != -1 and lasth != -1:
fsth -= 20
lasth += 20
print("%d @ %d - %d" % (fcnt, fsth, lasth))
scipy.io.wavfile.write("packet-%d.wav" % fcnt, rate, thrs[fsth:lasth])
fcnt += 1
fsth = -1
lasth = -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment