2022-07-16

converting raw bytearray into a .wav file

I have managed to get a live raw bytearray file containing just the data. I tried converting it into wave file using the following code:

import scipy.io.wavfile
import numpy as np
import soundfile as sf

def convert_bytes_to_audio():
    fi = open("receive_data.txt","r")
    for line in fi:
        scipy.io.wavfile.write('format.wav', 48000, np.frombuffer(str.encode(line),dtype = 'B'))
        fi.close()

def main():
    convert_bytes_to_audio()

if __name__ == '__main__':
    convert_bytes_to_audio()

The bytearray:

b'\x00Z\x15\x02\xf9\x15q\x9d1$\xd2\xde:\xb44\xaf\x8d_4\xbe\xe5\x02\x1f\x87\xe0,d\xa8YS\x02\xea\xdc\xf8\x85\xcc\x87p\x8be)Fi4FE\xeb\xf5\x10\xfbr\xd3-)\x02J\xd9\xebOo\xca\xd3\x04\xcaaG\xf2\x17\xe6\x04\xd3\xdds(R\x98\xf8\xe6\x80@b\xa3\x0e~h\xb1\x02\xf7"(%\x12y\xb6\x1e/wL\n\x9a\xb39\xd7\xb2&Mc\xca\xdc\x9f\xbb\xff\xa7\x81n\xe213\x85\xea\xc8p\x1c{\x19j\x1a\xdd\x0f\xdd\x9d\xde\x19s\x89]\xf8z\x11R\xed5\xd3g\xacy\x85\xa8\x8f\xca\xad\x91\xba\xbe\x07\xa5\xfa\xa0'
 b"\x01Z\x8c\xe3\xd9\xd82N8F\x1a\x9d\r\xdct\x97+\xdf\x7f8\x1dL\xb6\xae\xdb\xc2\xbc\xd4\x8b\x1f\xe7rZ\rI\x85\x7f\xb6F\x85\x15\xc6$\xea\x82&l\r8\x82Zu\x00#\x0b\x81\xe6ij\xeb\x02\xbf[\xb6\xfa\x83\x111\x86\xd0\xf2\xb6\x0f\x94\xedk\x81\x0c\x1b%\x16\xd9\xb31\x0c\x04:\x8c[O\xde'\xae[\xe0\x90W/\x9c\xea\xb4\xcf(}\x9e\x19\xa3\xdc\x16?\xc2\x01L[\x1d\x9c\xcc\x1bqP\x95g\xd2s\xbdNM\xe8p\x9c:rW\x01\xf8\xc9k\xf8V;\x9f\xe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xbb\xa0'
 b'\x06Z\x89\xef\xc9\x7f\x08\xc9\x0b\xac\xbd\x9a"?z\xb0\x002\xfb\xac\x8e\xeb\x89\x1b,\x89Ee>\x82\xad&\x8ft\xf8\x13y\x94\xcd\xd3\xe9\xa0\n\x16\xc0\xcc\x90\xc91%\xd4\xee\xd8\xcd_\xc9\x02\xd21\xf7\x13\xd4\xf7\xba]\x7f^\xcbuZ\x84\xdf%\xa3\x81\x1dw\xaf <^\x94Ng.\xf7\xae\x0f\xec\xbb\xc3\xb6\xbd\xf4\x0c\xea#7=\xba\x08>FZ\xa8%<\xce\xb8S\x8c\xa2\xee_\xc83}\xbb\xc5\x9d\x9f\x15\x14\xe0\xb8\xf9*0\xb8\x87\xca\xa1\x11Y\xde\x8b\xb5\x8e\x16\xb8\xc4rL\xc8&ut\x8e\x19\xf39)F\xcfR)\xe2\xa8\xff\x8b\xb4s\xc5}\xed%\x86\x13\xbc\x03\x12\xdcb\xa6\\E5\x98\x03\xe5%\x9f4\xb0\xac-\x8e\xac\x83\x17\x08\xb5\x0f\x18\xc3\x0e\xbf\xe5S\xa0\xeb9ni\xc9\xd6\r\xdd\x10\xcc&\'\xf5\xdbz\xcf\x1ac\xf0\xdb\xae\xe6D\x9f\x8cq\x14\xa0\xa7\xcfq!M\xc9\xe46\x19"\xbc=\x82\x18\x87\'\xe0>'

I managed to get the wav file but it is unclear and not exactly for the amount of time I recorded it. Also the format is u8 type, and encoding is pcm_f32le. But I am unsure how to change those.

Generated wav file:

generated wav file

Can anyone help me on this.



No comments:

Post a Comment