123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // components/speechRecognition/speechRecognition.js
- const plugin = requirePlugin("WechatSI")
- const manager = plugin.getRecordRecognitionManager()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- show: {
- type: Boolean,
- value: false
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- manager: null,
- start: false,
- resText: ""
- },
- /**
- * 组件的方法列表
- */
- methods: {
- start() {
- let that = this
- setTimeout(() => {
- manager.start()
- }, 10);
- manager.onError = function (res) {
- console.log(res)
- wx.showToast({
- title: '识别失败',
- icon: "none",
- duration: 3000
- })
- }
- manager.onStart = function (res) {
- console.log(1)
- }
- manager.onStop = function (res) {
- that.triggerEvent('result', res.result)
- }
- that.setData({
- start: true
- })
- },
- end() {
- let that = this
- manager.stop()
- that.setData({
- start: false
- })
- },
- result(e) {
- let that = this
- let text = e.currentTarget.dataset.text
- that.triggerEvent('result', text)
- },
- close() {
- let that = this
- that.triggerEvent('close', true)
- }
- }
- })
|