Saif Ali
Saif Ali

Reputation: 427

How to convert ByteArray[] to int16 in Python?

I'm working on a python project I'm strangled in converting a ByteArray having audio data to int16 in python.

Can someone give a heads-up?

I have used libraries such as jep (python).

Can someone shed some light on this?

Upvotes: 1

Views: 1630

Answers (2)

Charnel
Charnel

Reputation: 4432

If you need to go forward to deal with int16 dtype for something custom, I guess you'll need to use something like numpy.array like this (not checked):

import numpy as np
# read file or stream in binary mode into a bin_array list
...
# convert binary input values to numpy array with container type int16
np.array([v for v in bin_array], dtype=np.int16)

Upvotes: 2

Nick
Nick

Reputation: 3845

Try the PyAudio library. It's a very good library for working with all things audio and is cross platform.

The links here on the pyadio documentation and here from an example on programcreek should get you started with your problem.

Upvotes: 1

Related Questions