Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import sys
import os
import numpy as np
import scipy.io.wavfile
if not len(sys.argv) == 3:
print('Incorrect # of arguments')
sys.exit(1)
sample_file = sys.argv[1]
sample_rate = int(sys.argv[2])
print('Using sample rate of {} Hz'.format(sample_rate))
samples = []
with open(sample_file, 'r') as soundfile:
for line in soundfile.readlines()[1:]:
time, _, mosi, miso = line.split(',')
sample = int(miso, 16)
samples.append(sample)
sound_filename = '{}.wav'.format(os.path.splitext(os.path.basename(sample_file))[0])
scipy.io.wavfile.write(sound_filename, sample_rate, np.array(samples, dtype=np.uint8))
print('Generated {}'.format(sound_filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.