VoiceRecognizer.onStart
解释: 引擎准备就绪,可以开始说话
方法参数
Function callback
示例
请使用百度APP扫码
图片示例
代码示例 1 :
短语音识别(与长语音使用方式一致) - 自动听音 在开发者工具中预览效果 -
<view class="result">{{result}}</view><button bindtap="voiceRecognizerStart">点击开始识别语音</button>
-
Page({ data: { result: '' }, voiceRecognizerStart() { // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误 let host = swan.getSystemInfoSync().host; if (host === 'baiduboxapp') { const voiceRecognizer = swan.ai.getVoiceRecognizer(); voiceRecognizer.onStart(res => { swan.showToast({ title: '开始识别', icon: 'none' }); }); voiceRecognizer.onRecognize(res => { console.log('voice recognize', res.result); this.setData('result', res.result); }); const options = { mode: 'dnn', // longSpeech: true longSpeech: false }; voiceRecognizer.start(options); } else { swan.showToast({ title: '此api目前仅可在百度App上使用', icon: 'none' }); } }})
代码示例 2 :
短语音识别 (与长语音使用方式一致)- 自动听音 在开发者工具中预览效果 -
<view class="result">{{result}}</view><button bindtap="voiceRecognizerStart">点击开始识别语音</button>
-
Page({ data: { result: '' }, voiceRecognizerStart() { // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误 let host = swan.getSystemInfoSync().host; if (host === 'baiduboxapp') { const voiceRecognizer = swan.ai.getVoiceRecognizer(); voiceRecognizer.onStart(res => { swan.showToast({ title: '开始识别', icon: 'none' }); }); voiceRecognizer.onFinish(res => { console.log('voice onFinish', res.result); this.setData('result', res.result); }); const options = { mode: 'dnn', // longSpeech: true longSpeech: false }; voiceRecognizer.start(options); } else { swan.showToast({ title: '此api目前仅可在百度App上使用', icon: 'none' }); } }})
代码示例 3 :
短语音识别 - 手动听音 在开发者工具中预览效果 -
<view class="result">{{result}}</view><button bindtap="voiceRecognizerStart">点击开始识别语音</button>
-
Page({ data: { result: '' }, voiceRecognizerStart() { // AI系列的api有宿主使用限制,只可在百度App中使用,建议使用时加一层判断防止代码报未知错误 let host = swan.getSystemInfoSync().host; if (host === 'baiduboxapp') { const voiceRecognizer = swan.ai.getVoiceRecognizer(); voiceRecognizer.onStart(res => { swan.showToast({ title: '开始识别', icon: 'none' }); }); voiceRecognizer.onRecognize(res => { console.log('voice recognize', res.result); this.setData('result', res.result); }); const options = { mode: 'touch', longSpeech: false }; voiceRecognizer.start(options); } else { swan.showToast({ title: '此api目前仅可在百度App上使用', icon: 'none' }); } }})
