问题描述
我正在尝试使用来自语音识别的烧瓶开发 api。我在哪里得到 request.data
作为 <class 'bytes'>
我想将字节转换为 .wav 文件,以便我可以在语音识别 api 中使用。
这是我的代码
@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)
数据类型格式就像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\
请帮我找出解决办法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)