0

I have raw data of .wav format audio and I am trying to convert it to file object but it seems the decoding is not happening.

How do I decode .wav audio raw data format?

Python Code:

>>> import io
>>> audio_raw_data = b'RIFF\xe4\x99\x19\x00WAVEfmt \x10\x00\x00\x00'
>>> type(audio_raw_data)
<class 'bytes'>
>>> audio_file = io.StringIO(audio_raw_data.decode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 4-5: invalid continuation byte
user1990
  • 37
  • 4
  • your string is `encoded` in latin – Ajay Feb 27 '21 at 03:58
  • Does this answer your question? [UnicodeDecodeError, invalid continuation byte](https://stackoverflow.com/questions/5552555/unicodedecodeerror-invalid-continuation-byte) – Ajay Feb 27 '21 at 03:58
  • It doesn't works specially if the audio_raw_data is bytes format of .wav audio files. – user1990 Feb 27 '21 at 04:10
  • Nevermind, got it worked. .decode() was not required.This was required - audio_file = io.BytesIO(audio_raw_data) – user1990 Feb 27 '21 at 04:23

0 Answers0