marl / pysox

Python wrapper around sox.
BSD 3-Clause "New" or "Revised" License
517 stars 80 forks source link

Convert an ulaw byte array to a wav array #141

Open r4nc0r opened 3 years ago

r4nc0r commented 3 years ago

Hi,

i'm trying to convert a raw 8k,8bit,mono ulaw byte array to a 16k,16bit,mono wav array. It works if i write the byte array to a .raw file and use pysox like this:

tfm = sox.Transformer()
tfm.set_input_format(rate=8000, channels=1, encoding="u-law",bits=8)
tfm.set_output_format(channels=1, rate=16000,bits=16)

def convert(data):
        f = open("randomfilename.raw", "wb")
        f.write(data)
        f.close()
        return (tfm.build_array(input_filepath="randomfilename.raw"))

But pysox has the capabilities to use build_array with an input_array parameter, but I dont know how to convert my byte array, so that it works.

Could you please help me?