I have created a blob object of type .wav using the media recorder. I am trying to send the data as .wav to flask to get processed but I can't seem to change the blob type to a .wav type, or is there a way to save as wav file using the blob in python? I'm new to blob so my question might be stupid.
Here is the code :
function makeLink(){
let blob = new Blob(chunks, {type: media.type })
, Url = URL.createObjectURL(blob)
, li = document.createElement('li')
, mt = document.createElement(media.tag)
, hf = document.createElement('a');
mt.controls = true;
mt.src = Url;
hf.href = Url;
hf.download = `${counter++}${media.ext}`;
hf.innerHTML = `donwload ${hf.download}`;
//processing data
jQuery(document).ready(function(){
let x='test'
$.ajax({
type:'GET',
url:'/answer/voice',
data:{
audio: window.btoa(blob)
},
success:function(result) {
$("#chatbox").append('<p class ="userText"><audio style="background-color:white;" controls> <source src="' + Url+ '" type="audio/wav"></audio></p>');
$("#chatbox").append('<p class ="botText"><span>' + result.emotion+ '</span></p>');
$("#textInput").val("")
},
error:function(result){
alert('sorry an error occured');
}
})
}); }
and the flask part :
@app.route('/answer/voice', methods=['GET'])
def answer_voice():
blob=request.args.get("audio")
print(blob)
blob =base64.b64decode(blob)
print(" decoded : ")
print(blob)
result=get_audio_sentiments(blob)
return jsonify({'emotion':result })
The get audio sentiment function is a function that accept filetype wav type, so I need to convert that blob to a real wav file. I tried decoding it again sending the data before putting it to blob sending it using formdata but I got no expertise there.