多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 录入语音后识别成文字,比如搜索页里进行语音搜索或者聊天窗口里对好友发过来的语音进行识别 [TOC] ## 申请百度合成接口 > 地址:https://ai.baidu.com/tech/speech/asrpro > 找到语音技术 - 应用列表,创建应用,填写相应信息,语音包名选择不需要 ![](https://img.kancloud.cn/6d/34/6d34d6fa7988a33b438d9cd7d13b7d8b_690x865.png) > 创建完成后,可以看到AppID、API Key、Secret Key ## manifest.json 配置语音输入模块 > App模块配置 -> Speech(语音输入,只能选一个) -> 百度语音识别 ![](https://img.kancloud.cn/08/34/0834d398cbb17861f6a51c2f42d91f28_555x332.png) ## 客户端调用 > 参考资料:https://uniapp.dcloud.io/api/plugins/voice?id=voice ~~~ <template> <view> <button @tap="startRecord">开始录音</button> <button @tap="endRecord">停止录音</button> <button @tap="playVoice">播放录音</button> <button @tap="startRecognize">开始识别</button> </view> </template> <script> const recorderManager = uni.getRecorderManager(); const innerAudioContext = uni.createInnerAudioContext(); innerAudioContext.autoplay = true; var _this; export default { data(){ return { voicePath : '' } }, onLoad() { _this = this; recorderManager.onStop(function(res) { console.log(res) _this.voicePath = res.tempFilePath // 使用uni.uploadFile上传到服务器上,此时是mp3格式 }); }, methods: { startRecord() { console.log('开始录音'); recorderManager.start({ sampleRate: 16000 // 必须设置是后台设置的参数,不然百度语音识别不了 }); }, endRecord() { console.log('录音结束'); _this = this; recorderManager.stop(); }, playVoice() { console.log('播放录音'); if (this.voicePath) { innerAudioContext.src = this.voicePath; innerAudioContext.play(); } }, startRecognize() { var options = {}; options.engine = 'baidu'; console.log("开始语音识别:"); plus.speech.startRecognize(options, function(s){ console.log("识别结果:"+s) plus.speech.stopRecognize(); }, function(e){ console.log("语音识别失败:"+e.message); }); } } } </script> ~~~