1、概述
通过微信小程序wx.startRecord()和wx.stopRecord()接口录音并上传silk录音文件至服务器,通过ffmpeg将silk录音文件转成wav录音文件,再通过百度语音识别 REST API 获取语音识别后的结果。
2、代码实现
录音和语音文件上传


node.js服务端接收语音文件代码
silk文件转wav文件
我使用的是silk-v3-decoder将silk文件转wav文件

silk-v3-decoder 使用方法

百度语音识别 REST API识别wav文件
1、通过API Key和Secret Key获取的access_token

通过API Key和Secret Key获取的access_token文档

2、通过token 调用百度语音识别 REST API识别接口

3、语音识别优化
通过上述操作后,发现识别的内容和实际内容差别很大

百度语音识别 REST API文档
查看文档可知:采样率:8000/16000 仅支持单通道
在ffmpeg里对应的设置方式分别是:
-ar rate 设置采样率
-ac channels 设置声道数
修改converter.sh文件,修改为下图所示

修改后的converter.sh文件