Google语音API使用SOX时语音识别不好

我正尝试用节点js创build非常简单的语音识别软件。 我已经连接谷歌语音API,并可以发送正确的录制的.wav文件,并获得转录和识别是非常好的(用Audacity录制)

但我有问题得到“即时”的语音识别,如直接从麦克风发送到Gooegle语音API的audiostream。

这是我logging语音并发送到谷歌的主要方法。

function recognize(encoding, sampleRateHertz, languageCode) { const request = { config: { encoding: encoding, sampleRateHertz: sampleRateHertz, languageCode: languageCode }, interimResults: true // If you want interim results, set this to true }; // Imports the Google Cloud client library const Speech = require('@google-cloud/speech'); // Instantiates a client const speech = Speech(); // Create a recognize stream const recognizeStream = speech.createRecognizeStream(request) .on('error', console.error) .on('data', (data) => process.stdout.write(data.results + ', ')) let fs = require('fs'); let Mic = require('node-microphone'); let mic = new Mic({ 'rate': '16000', 'channels': '1', 'debug': true, 'exitOnSilence': 6, 'bitwidth' : '16' }); let micStream = mic.startRecording(); micStream.pipe(recognizeStream); micStream.pipe(fs.createWriteStream('test.wav') ) setTimeout(() => { //logger.info('stopped recording'); console.log('stopped writing') mic.stopRecording(); }, 10000); mic.on('info', (info) => { console.log('INFO ' + info); }); mic.on('error', (error) => { console.log(error); }); } 

和我传递给方法的configuration数据

 options({ encoding: { alias: 'e', default: 'LINEAR16', global: true, requiresArg: true, type: 'string' }, sampleRateHertz: { alias: 'r', default: 16000, global: true, requiresArg: true, type: 'number' }, languageCode: { alias: 'l', default: 'en-US', global: true, requiresArg: true, type: 'string' } }) 

所以我使用'节点麦克风'进行录音,我安装了Windows和SOX。 通过谷歌发送。 我没有得到错误,但承认是非常糟糕的。 我用非常简单的词语或短语(如“谁”,“食物”,“呼叫”)来获得转录。 大多数情况下,如果我通常说话没有返回。

我有一种感觉,那就是用encodng写的东西是错误的,或者是logging速度(比如,logging是“太快了”,google不明白),但是我没有看到我的错误。

我也加了文件保存。 当我打开文件并收听时,听起来很正常。 当我发送这个文件recongition我几乎没有回来。 所以,录制audiostream的方式是有问题的

编辑:我几乎可以肯定的问题是在SOX。 用其他程序logging的所有文件效果更好。