您的位置:首页 > 新闻 > 热点要闻 > 微信公众号h5网页-调用录音评测

微信公众号h5网页-调用录音评测

2025/9/13 14:23:44 来源:https://blog.csdn.net/qq_33593958/article/details/141938132  浏览:    关键词:微信公众号h5网页-调用录音评测

一、全局引入jweixin-1.6.0.js微信能力插件;

二、初始化微信配置,开启音频相关能力;

initWxConfig() {let url = window.location.href.split('#')[0]let data = { url: url }this.$http.get(this.$api.getTicket, { params: data }).then((res) => {let data = res.data || {}if (data.flag) {this.$nextTick(() => {wx.config({debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。appId: data.appId,timestamp: data.timestamp,nonceStr: data.noncestr,signature: data.signature,jsApiList: ['startRecord', 'stopRecord', 'playVoice', 'stopVoice', 'uploadVoice', 'translateVoice']})})}})}, 

三、录音上传评测;

wx.startRecord();
let _this = thiswx.stopRecord({success: function (res) {_this.localId = res.localIdwx.uploadVoice({localId: res.localId, // 需要上传的音频的本地ID,由stopRecord接口获得isShowProgressTips: 1, // 默认为1,显示进度提示success: function (res) { _this.serverId = res.serverId // 返回音频的服务器端IDlet params = {questionId: _this.paper.id,mediaId: res.serverId,paperId: _this.paper.paperId}// loading_this.$http.post(_this.$api.audioCheck, params).then((res) => { _this.nextFlag = true //通过}).finally(() => {Toast.clear()})}})}})

四、应用置于后台,定时器、延时器由于浏览器性能机制有所沉睡;采用visibilitychange及时处理;

document.removeEventListener("visibilitychange", this.checkViChange);
checkViChange(){ if (document.hidden) { // 隐藏this.cacheHiddenTime = moment().unix();if(this.setInterval){clearInterval(this.setInterval); this.setInterval = null;};}else{let cur = moment().unix() - this.cacheHiddenTime;this.countdown = this.countdown>cur ? (this.countdown-cur) : 0; this.countDownUtil();}},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com