I am trying to develop a api using flask from speech recoginition. Where i am getting request.data
as <class 'bytes'>
I want to convert Bytes to as a .wav file so, i can use in speech recognition api.
here is my code
@app.route('/stt',methods=['GET','POST'])
def STT():
print(request.get_data("audio-blob"))
app.logger.warning("request.files: {0}".format(type(request.data)))
f = request.get_data("audio-blob")
print(type(f))
file_obj = io.BytesIO() # create file-object
file_obj.write(f) # write in file-object
file_obj.seek(0) # move to beginning so it will read from beginning
r = sr.Recognizer()
mic = sr.AudioFile(f) # use file-object
with mic as source:
audio = r.record(source)
result = r.recognize_google(audio_data=audio, language="en-US", show_all=True)
print(result)
return jsonify(text=result)
Data type formate is like b'\x1aE\xdf\xa3\x9fB\x86\x81\x01B\xf7\x81\x01B\xf2\x81\x04B\xf3\x81\x08B\x82\x84webmB\x87\x81\x04B\x85\x81\x02\x18S\x80g\x01\xff\xff\xff\xff\xff\xff\xff\x15I\xa9f\ x99*\xd7\xb1\x83\x0fB@M\x80\x86ChromeWA\x86Chrome\x16T\
Please help me out to find the solution.