Created
September 20, 2014 12:55
-
-
Save atx/d79bf0d114fb16a59e9d 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
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