Commit 6500a7ef authored by fred's avatar fred

commands: create a second waveform with higher sample rate

parent 45ce1ecc
......@@ -47,14 +47,15 @@ class Command(BaseCommand):
self.create(soundfile)
def create(self, soundfile):
file_path = soundfile.get_format_path('waveform.json')
# create a raw output, with a single channel and 4000Hz samples of 8bits
cmd = ['sox', soundfile.get_format_path('ogg'), '-t', 'raw', '-c', '1', '-r', '4000',
'-e' 'unsigned-integer', '-b', '8', '-']
wave_array = subprocess.check_output(cmd)
# reduce to 200 samples of max positive value
if six.PY3:
wave_reduced = [int(max(x)) for x in np.array_split(np.array([max(0, x-128) for x in wave_array]), 200)]
else:
wave_reduced = [max(x) for x in np.array_split(np.array([max(0, ord(x)-128) for x in wave_array]), 200)]
json.dump(wave_reduced, open(file_path, 'w'))
for filename, n_samples in (('waveform.json', 200), ('waveform-500.json', 500)):
# reduce to $n_samples$ samples of max positive value
if six.PY3:
wave_reduced = [int(max(x)) for x in np.array_split(np.array([max(0, x-128) for x in wave_array]), n_samples)]
else:
wave_reduced = [max(x) for x in np.array_split(np.array([max(0, ord(x)-128) for x in wave_array]), n_samples)]
file_path = soundfile.get_format_path(filename)
json.dump(wave_reduced, open(file_path, 'w'))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment