Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process JavaScript blob in python?

I want to process an audio blob in python that is received via socketio from a javascript client.

I want the audio data as numpy array to process it, but I don't seem to be able to convert the blob properly.

The audio blob contains:

[Float32Array[32768], Float32Array[32768]]

In python, I tried:

@socketio.on('gotaudio')
def get_audio(blob):  
    //CONVERT THE BLOB
    data = blob[0]
    dat = np.array(json.loads(data));
    //DO SOME SIGNAL PROCESSING
    fftData=abs(np.fft.rfft(dat))**2;
    ....

But this throws the error:

TypeError: expected string or buffer

How can I transform the audio blob correctly so that it can be processed with np.fft?

like image 889
user2212461 Avatar asked Apr 21 '26 09:04

user2212461


1 Answers

Have you tried using base64.b64decode() on it first? (base64 is in the standard lib)

It would help to get an example blob.

like image 51
10se1ucgo Avatar answered Apr 22 '26 22:04

10se1ucgo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!