Skip to content

Instantly share code, notes, and snippets.

@redspider
Created November 16, 2018 20:00
Show Gist options
  • Select an option

  • Save redspider/5548fdb1d8e1d8a78ce78ff196aace15 to your computer and use it in GitHub Desktop.

Select an option

Save redspider/5548fdb1d8e1d8a78ce78ff196aace15 to your computer and use it in GitHub Desktop.
import wave
from itertools import zip_longest
START = 1500
END = 1500 + 86 * 11
def grouper(n, iterable, fillvalue=None):
args = [iter(iterable)] * n
return zip_longest(fillvalue=fillvalue, *args)
def sequence_to_bin(s):
s = tuple(s)
if s == (64, 64, 192, 192) * 8:
return ' '
elif s == (64, 64, 64, 64, 192, 192, 192, 192) * 4:
return 'X'
else:
print(s)
raise Exception()
with wave.open('file.wav', 'r') as wfh:
raw = [n for n in wfh.readframes(wfh.getnframes())]
values = [sequence_to_bin(x) for x in grouper(32, raw)]
lines = list(grouper(11, values[START:END], '.'))
set_a = lines[:43]
set_b = lines[43:]
for a, b in zip_longest(set_a, set_b, fillvalue=['-']):
print(f"{''.join(a)} {''.join(b)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment