Skip to content
Advertisement

How to send audio blob from javascript to python?

I want to send a audio blob from JS to python script (which runs on server). My JS ajax .. looks something like this.

JavaScript

and my python script looks like this.

JavaScript

Right now, I am just testing, so it should get me the duration of the audio file. The blob is generated through record.js

This is not working, as the python is unable to identify the file. Any solutions?

PS: I am using Xampp Server, to run on local host.

In response to Wojtek Marczenko: The error is

JavaScript

Advertisement

Answer

It looks like you’re not properly sending the blob as form field. The proper way to attach blob to FormData would be formData.append(fileType, blob, fileName);. Also you should attach just the formData instead of nesting it in another object:

JavaScript

Sources: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append http://www.mattlunn.me.uk/blog/2012/05/sending-formdata-with-jquery-ajax/

On the python side, you need to use the CGI module according to the python docs (can’t post more links). I believe the proper way would be like this:

JavaScript
Advertisement