... @app.route("https://www.jb51.net/") def index(): return render_template("index.html") @app.route("/receive_audio", methods=["POST"]) def receive_audio(): file = request.files.get("audio") if file: filepath = os.path.join(BAISE_DIR, "data", "%s.m4a" % uuid4()) file.save(filepath) text = baidu.auido2text(filepath) answer = tuling.chat(text) res = baidu.text2audio(answer) if res.get("err_no") == 200: return {"code": 200, "filename": res.get("filename")} return {"code": 201, "msg": "上传失败"} @app.route("/get_audio/<filename>") def get_audio(filename): return send_file(os.path.join(BAISE_DIR, "data", filename)) ...
注意flask启动ip写成127.0.0.1 其他地址 js可能会报错