Skip to content

Instantly share code, notes, and snippets.

@zorix
Last active July 27, 2017 21:04
Show Gist options
  • Select an option

  • Save zorix/d4fcc1c6af22881d8405872b1ab0ae2a to your computer and use it in GitHub Desktop.

Select an option

Save zorix/d4fcc1c6af22881d8405872b1ab0ae2a to your computer and use it in GitHub Desktop.
import wave, struct, math
waveFile = wave.open('recording.wav', 'r')
_, _, rate, length, _, _ = waveFile.getparams()
print 'rate:', rate, 'length:', length
print 'seconds:', length/rate
bits = ''
for b in range(0, length/rate):
last = 0
dir = 0
count = 0
for i in range(0, rate):
waveData = waveFile.readframes(1)
data = int(struct.unpack("<h", waveData)[0])
if (data - last) > 100:
if dir == 0:
count += 1
dir = 1
else:
dir = 0
last = data
bits += '1' if count > 700 else '0'
#print bits
out = ''
while bits:
b = bits[:8]
bits = bits[8:]
out += chr(int(b[::-1], 2))
print out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment