录音上传到mysql数据库_录音上传到数据库格式显示为mpeg

本文介绍了如何使用微信小程序的录音管理器(wx.getRecorderManager())进行录音,并设置录音参数如时长、采样率等。在录音结束后,将临时文件路径通过wx.uploadFile上传至服务器,再将文件发送到百度进行语音识别。识别成功后的文本存储到MySQL数据库中,文件格式为mpeg。
摘要由CSDN通过智能技术生成

// 录音对象

const recorderManager = wx.getRecorderManager();

/** 录音开始 */

function speechStart() {

const options = {

duration: 10000,

sampleRate: 16000,

numberOfChannels: 1,

encodeBitRate: 64000,

format: 'mp3',

frameSize: 50

}

recorderManager.start(options);

}

/** 语音识别 */

function speechRecognition( res) {

console.log("语音识别");

wx.uploadFile({

url: "http://bnwisdom.xicp.io/speechRecognition",

filePath: res.tempFilePath,

name: 'file',

formData: {

'user': 'test'

},

success: function (res) {

console.log(res);

// var data = JSON.parse(res);

console.log(res.data);

// msg 为最终语音识别的字符串

var msg = res.data;

// 获取当前页面对象

var page = getCurrentPages()[0];

page.setData({ msg: msg });

},

fail: function () {

console.log("语音识别失败");

page.setData({ msg: "语音识别失败,请重新录音" });

}

})

}

// 结束录音的时候触发

recorderManager.onStop((res) => {

// 获取文件路径-提交到后台-后台发送到百度

console.log("res.tempFilePath====" + res.tempFilePath);

speechRecognition(res);

})

recorderManager.onError((res) => {

console.log("error", res);

});

Page({

data: {

msg: "",

ldata: false,

errorNum: 0//无法匹配到设备的重试次数

},

// 按下按钮的时候触发

startrecorderHandel() {

speechStart()

},

// 松开按钮的时候触发-发送录音

sendrecorderHandel() {

// 结束录音

recorderManager.stop();

},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值