1

我正在尝试使用语音识别中的烧瓶开发 api。我 想将字节转换为 .wav 文件,所以我可以在语音识别 api 中使用request.data<class 'bytes'>

这是我的代码

@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\

请帮助我找到解决方案。

4

0 回答 0