Last active
July 27, 2017 21:04
-
-
Save zorix/d4fcc1c6af22881d8405872b1ab0ae2a to your computer and use it in GitHub Desktop.
Rozwiązanie do misji 9 - https://www.youtube.com/watch?v=wd3L04QNRHI
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 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