1.manifest.json在mp-weixin目录下进行配置
"plugins" : {
"WechatSI" : {
"version" : "0.3.4", // 这是同声传译的版本(也可以在微信公众平台添加的同声传译查看最新版本)
"provider" : "wx069ba97219f66d99" // 这是同声传译的ID
}
},
2.vue页面如下
<template>
<view class="content">
<view class="cu-form-group">
<view class="title xrequired">事件描述</view>
<textarea v-model="myFormData.description" placeholder="请填写事件描述" rows="5"></textarea>
</view>
<view class="cu-form-group" style="border-top: none;">
<button @touchstart="touchStart" @touchend="touchEnd">语音录入</button>
</view>
</view>
</template>
<script>
var plugin = requirePlugin("WechatSI")
let manager = plugin.getRecordRecognitionManager()
export default {
data() {
return {
myFormData: {
description: ''
},
}
},
onLoad() {
this.initRecord();
},
methods: {
/**
* 初始化语音识别回调
* 绑定语音播放开始事件
*/
initRecord: function() {
manager.onStart = function(res) {
console.info("onStart",res)
};
//有新的识别内容返回,则会调用此事件
manager.onRecognize = (res) => {
console.info("onRecognize",res)
};
// 识别结束事件
manager.onStop =(res) => {
console.info("onStop",res)
this.myFormData.description += res.result;
};
// 识别错误事件
manager.onError = (res) => {
console.info("onError",res)
uni.showModal({
title: "提示",
content: "听不清楚,请重新说一遍!",
showCancel: false
})
}
},
touchStart: function() {
manager.start({
duration: 60000,
lang: "zh_CN"
});
uni.showToast({
title: '开始语音',
icon: 'success',
image: '../image/icon.png',
image: '../../static/microphone.png',
duration: 60000,
position: "top"
});
},
touchEnd: function() {
uni.hideToast()
manager.stop();
},
}
}
</script>
<style>
</style>