js实现录音上传功能的方法是什么

js实现录音上传功能的方法是什么?很多人都不太了解,今天小编为了让大家更加了解js实现录音上传功能的方法,所以给大家总结了以下内容,一起往下看吧。

创新互联公司-专业网站定制、快速模板网站建设、高性价比五大连池网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式五大连池网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖五大连池地区。费用合理售后完善,10多年实体公司更值得信赖。

js实现录音上传功能的方法是什么

具体代码如下所示:

1、html页面




 
 




2、Recorder.js内容

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Recorder = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o

3、flask写法

...
@app.route("/")
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/")
def get_audio(filename):
 return send_file(os.path.join(BAISE_DIR, "data", filename))

...

注意:flask启动ip写成127.0.0.1,其他地址js可能会报错。

以上就是js实现录音上传功能的方法是什么的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注创新互联行业资讯频道哦!


分享文章:js实现录音上传功能的方法是什么
转载来源:http://pwwzsj.com/article/ppssss.html