uniapp实现小程序添加百度语音识别功能
2023-08-07 本文已影响0人
Morbid_D
1.需要在百度云注册开通 https://cloud.baidu.com/?from=console,
购买语音识别

2.创建完成后,可以免费领取条数

3.查看百度文档
https://console.bce.baidu.com/tools/#/api?product=AI&project=%E8%AF%AD%E9%9F%B3%E6%8A%80%E6%9C%AF&parent=%E8%AF%AD%E9%9F%B3%E8%AF%86%E5%88%AB&api=%2Fserver_api%20&method=post
4.先获取acctoken在进行

5.请求对应的语音接口(注意需要先获取麦克风权限,其次,文件需要解码为base64)
uni.authorize({
scope: 'scope.record',
success() {
console.log('开始录音');
recorderManager.start()
}
})
文件中引入 具体文档 https://uniapp.dcloud.net.cn/api/media/record-manager.html#getrecordermanager
6.解码的方法
readFile(voiceFilepath) {
uni.getFileSystemManager().readFile({
filePath: voiceFilepath,
encoding: 'base64',
success: (res) => {
console.log(res.data)
this.main(res.data)
},
fail: (res) => {
console.log('编码失败:' + res)
}
})
},