I have a list of .wav files in binary format (they are coming from a websocket), which I want to join in a single binary .wav file to then do speech recognition with it. I have been able to make it work with the following code:
audio = [binary_wav1, binary_wav2,..., binary_wavN] # a list of .wav binary files coming from a socket
audio = [io.BytesIO(x) for x in audio]
# Join wav files
with wave.open('/tmp/input.wav', 'wb') as temp_input:
params_set = False
for audio_file in audio:
with wave.open(audio_file, 'rb') as w:
if not params_set:
temp_input.setparams(w.getparams())
params_set = True
temp_input.writeframes(w.readframes(w.getnframes()))
# Do speech recognition
binary_audio = open('/tmp/input.wav', 'rb').read())
ASR(binary_audio)
The problem is that I don't want to write the file '/tmp/input.wav'
in disk. Is there any way to do it without writing any file in the disk?
Thanks.
wavefile
to get the raw data. – Orniswave.open
accepts either a file path or a file like object. you've already importedBytesIO
so just use one of those as a file like buffer. Here's and example of someone doing basically just that withgzip
(note the slightly different argument names). – Portentous