如何在 python 中将音频 blob 字节转换为 .wav

问题描述

我正在尝试使用来自语音识别的烧瓶开发 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...