微信小程序语音识别

看到微信有语音识别的插件试了下, 很nice ,识别率很高。
坐下笔记

首先在app.js中加入配置

"plugins": { "WechatSI": { "version": "0.3.0", "provider": "wx069ba97219f66d99" } },

新增页面a 代码`var plugin = requirePlugin(‘WechatSI’)
let manager = plugin.getRecordRecognitionManager()
Page({
data: {
loading:true
},
onLoad: function (options) {

},

onReady: function () {
manager.onRecognize = res => {
let text = res.result
console.log(text)
}
manager.onStop = res => {
let text = res.result
console.log(res)
if (!text) {
console.log(‘用户没有说话’)
} else {
console.log(text)
}
}
manager.onError = function (res) {
wx.showToast({
icon: ‘none’,
title: ‘报错了’,
})
}
},
onShow: function () {

},
touchStart() {
manager.start({
lang: ‘zh_CN’,
duration: 60000
})
this.setData({
loading: false
})
},
touchEnd() {
this.setData({
loading: true
})
console.log(999999999999999)
manager.stop()
}
})`

wxml文件中增加标签 {{loading?‘按住说话’:‘正在识别’}}

你可能感兴趣的:(JavaScript,微信小程序,语音识别)