#next_bytes = byte_reader.read(MAX_LENGTH)
buffer_samples = None
- with AudioFile(filename).resampled_to(target_sample_rate=SAMPLE_RATE) as f:
- # we're reading in the whole file at once, maybe don't want to later for better responsiveness?
- buffer_samples = f.read(f.frames)
- #log.debug('samples length: {}'.format(len(buffer_samples)))
+ args = ['ffmpeg', '-i', '{}'.format(filename)]
+ args += ['-f', 's16le', '-acodec', 'pcm_s16le', '-ac', '1', '-ar', '48000', '-']
+ p = await asyncio.create_subprocess_exec(*args, stdin=None, stderr=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE)
+ stdout, stderr = await p.communicate()
+ log.debug(stderr)
+ return_bytes = stdout
+ await p.wait()
+ byte_length = len(return_bytes)
+ buffer_samples = numpy.array([x[0] for x in struct.iter_unpack('<h', return_bytes)])
+ buffer_samples = buffer_samples.astype('float32')
+ buffer_samples /= 32768.0
+ log.debug(buffer_samples)
+ # we're reading in the whole file at once, maybe don't want to later for better responsiveness?
+ #log.debug('samples length: {}'.format(len(buffer_samples)))
# process here with pedalboard
shift_tones = random.randint(-10, 10)
board = pedalboard.Pedalboard([
buffer_samples = board(buffer_samples, SAMPLE_RATE)
index = 0
- next_samples = buffer_samples[0][index:index+MAX_SAMPLES]
+ next_samples = buffer_samples[index:index+MAX_SAMPLES]
while len(next_samples) > 0:
channels = len(next_samples.shape)
while len(next_samples) > 0:
# this is to format the samples in the style opus wants
#log.debug('channels are {}'.format(channels))
- if channels == 2:
- # interleave the samples L/R to form a bytestream eventually
- next_samples = numpy.squeeze(numpy.dstack((next_samples[0], next_samples[1])).reshape(1, -1))
+ #if channels == 2:
+ # # interleave the samples L/R to form a bytestream eventually
+ # next_samples = numpy.squeeze(numpy.dstack((next_samples[0], next_samples[1])).reshape(1, -1))
# right now, this is the only path taken (because we discard the other channel)
- else:
- next_samples = numpy.repeat(next_samples, 2)
+ #else:
+ next_samples = numpy.repeat(next_samples, 2)
# for the downcast to int16
next_samples *= 32768.0
next_bytes = next_samples.astype('int16')
chunks_to_append.append(chunk)
# get next chunk
index += MAX_SAMPLES
- next_samples = buffer_samples[0][index:index+MAX_SAMPLES]
+ next_samples = buffer_samples[index:index+MAX_SAMPLES]
# chunk append/insertion (along with mixing)