Skip to content

Instantly share code, notes, and snippets.

@atx
Created September 20, 2014 12:55
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 atx/d79bf0d114fb16a59e9d to your computer and use it in GitHub Desktop.
Save atx/d79bf0d114fb16a59e9d to your computer and use it in GitHub Desktop.
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