小程序IOS端,长按录音松开停止,真机松开停止无效,会持续录音14秒左右自动停怎么改正?安卓端无异常
这是WXML文件
recordingTimer:function(){
var that = this;
that.data.setInter = setInterval(
function(){
var time = that.data.recordingTimerqwe+1;
if(time>60){
wx.showToast({
title: 'The recording time is up to one minute',
duration:1500,
mask:true
})
clearInterval(that.data.setInter);
that.shutRecording();
return;
}
that.setData({
recordingTimerqwe:time
})
}
,1000);
},
//为录音文件生成随机数
randomNum(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10);
break;
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
break;
default:
return 0;
break;
}
},
openRecording:function(){
var that = this;
// wx.getSystemInfo({
// success:function(res){
// }
// })
recordManager.onStart(()=>{
console.log('[监听]....开始录音.....')
});
recordManager.onFrameRecorded((res) => {
const { frameBuffer } = res
console.log('frameBuffer.byteLength', frameBuffer.byteLength)
})
const options = {
duration: 60000, //录音的时长,之前最大值好像只有1分钟,现在最长可以录音10分钟
format: 'mp3', //录音的格式,有aac和mp3两种 // }
sampleRate:16000,
numberOfChannels:1,
encodeBitRate:96000,
frameSize:50,
}
//that.recordingTimer();
recordManager.start(options);
console.log('开始录音')
// recordManager.onError((res)=>{
// console.log(res);
// })
},
ontouchstart: function (e) {
wx.vibrateLong();//震动
wx.showToast({//按后效果
title:'按住录音',
duration:1000,
mask:true,
})
// 传到智聆,评测音频各参数,开始录音
this.openRecording();
app.globalData.manager.start({
content:this.data.content,
evalMode: this.data.evalMode,//选择智聆评测模式,evalMode: 0,//评测模式,1:句子模式 0:词模式
scoreCoeff: this.data.scoreCoeff,
serverType: this.data.serverType,
storageMode: this.data.storageMode,
soeAppId: this.data.soeAppId,
textMode: this.data.textMode,
duration: this.data.duration
});
this.setData({
view: 1,
});
// console.log('开始录音,view为',this.data.view);
},
shutRecording: function(){
// async shutRecording(){
var that = this;
// wx.getSystemInfo({
// })
recordManager.stop();
console.log('停止录音')
recordManager.onStop((res)=>{
console.log('[监听]..停止录音...',res.tempFilePath)
const{tempFilePath} =res;
clearInterval(that.data.setInter);
console.log(res)
let time = parseInt(res.duration/1000);
this.setData({
voice1:res,
voiceTime:time,
})
//上传临时录音文件进云存储
wx.cloud.uploadFile({
cloudPath:"studentvoice/"+app.globalData.username+"/"+that.randomNum(10000,99999)+'.mp3',
filePath:res.tempFilePath,
success: res => {
console.log('[上传录音] 成功: ', res)
this.setData({
voiceID: res._id,
voice: res,
});
let url = ""
console.log('[fileID]: ', res.fileID)
wx.cloud.getTempFileURL({
fileList: [res.fileID],
success: res => {
//console.log(fileID)
url = res.fileList[0].tempFileURL
this.setData({
voiceurl: url,
});
// this.onLoad();
console.log('[录音路径获取] 成功: ', url)
console.log('[用户ID获取] 成功: ', app.globalData.userid)
console.log('[用户姓名获取] 成功: ', app.globalData.name)
console.log('[用户学号获取] 成功: ', app.globalData.username)
console.log('[周数获取] 成功: ', app.globalData.weekid)
console.log('[句子id获取]成功',this.data.passageid)
console.log('[句子分数获取]成功',this.data.SuggestedScore)//该函数与测评函数不在同一进程,调试器测评函数运行更慢,所以获取不到数据,但是直接打开小程序可以正常使用
//抓取现在的时间
function formatDateTime(time) {
var date = new Date(time);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h = date.getHours();
h = h < 10 ? ('0' + h) : h;
var minute = date.getMinutes();
var second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute;
second = second < 10 ? ('0' + second) : second;
return y + '/' + m + '/' + d+' '+h+':'+minute+':'+second;
};
let nowtime = formatDateTime(new Date())
console.log(nowtime)
wx.cloud.database().collection("voice_data").add({
data: {
//voiceID: res.fileID,
//voice: res,
url: url,
downloadurl: url,
name: app.globalData.name,
username: app.globalData.username,
weekid: app.globalData.weekid,
passageid: this.data.passageid,
suggestedScore: this.data.SuggestedScore,//写一个选择判断,决定存进去的分是多少
pronAccuracyScore: this.data.PronAccuracy,
pronFluencyScore: this.data.PronFluency,
pronCompletionScore: this.data.PronCompletion,
maximumScore: this.data.maximumScore,
settime: nowtime,
},
success: function () {
console.log('[录音上传到数据库] 成功')
},
fail: function(){
console.log('[录音上传到数据库] 失败')
}
})
},
fail: res => {
console.log('[录音路径获取] 失败')
}
})
}
})
})
},
//测评结束
ontouchend:function(e){
console.log('结束')
let that = this;
that.shutRecording();
app.globalData.manager.stop();
that.setData({
practicetime:that.data.practicetime+1,
})
this.setData({
view: 0,
});
}, 这是录音部分的主要代码,用的是getRecorderManager. 调试视频如下: (手机端) [视频] (电脑端) [视频] 调试后发现,原因是调用了智聆的接口,整个过程比较慢,所以导致了这种情况,但是智聆是要调用的,请问大家我要如何解决这种问题?