通过小程序获取录音并通过百度语音识别读取内容发现百度不识别。
经过跟百度确认原因是:采样率是48000,需要改成16000
代码的参数明明写的是16000,为什么生成pcm文件还是48000.请协助帮忙处理。
部分代码如下:
const options = {
sampleRate: 16000,
numberOfChannels: 1,
format: 'pcm',
};
this.data.recorderManager.start(options);
tt.getFileSystemManager().readFile({
filePath: res.tempFilePath,
success: (fileRes) => {
this.callRecognize(fileRes.data);
},
fail: (err) => {
this.setData({ recognizeResult: '读取音频失败:' + err.errMsg });
}
});
callRecognize(audioBase64: any) {
tt.request({
url: 'https://shudaosan.net/vop/api/recognize',
method: 'POST',
data: audioBase64,
header: {
'content-type': 'application/json',
},
success: (res) => {
console.log("识别结果:", res);
},
fail: (err) => {
tt.showToast({ title: '接口调用失败', icon: 'none' });
console.error('接口调用失败:', err);
}
});
}
