为什么音频流识别的API响应时间如此之慢?

时间:2017-06-03 23:28:06

标签: node.js google-cloud-speech

我使用与Google's example非常相似的代码,使用Node.js客户端库在音频流上执行语音识别。

API正在正确解析我的音频,但我发现自己在等待30-45秒才得到回复。考虑到demo的速度如何,这看起来并不合适。我的配置是否有错误?

我尝试过写一个本地文件,只是为了确保音频清晰,录音似乎没问题。

感谢您提供任何帮助!

import record from 'node-record-lpcm16';
import Speech from '@google-cloud/speech';


function streamToParser(){
  const speech = Speech();
  const request = {
    config: {
      encoding: 'LINEAR16',
      sampleRateHertz: 16000,
      languageCode: 'en-US',
    },
    interimResults: true,
  };

  const recognizeStream = speech.createRecognizeStream(request)
  .on('error', console.error)
  .on('data', (data) => {
    console.log(data.results)
  });

  record
  .start({
    sampleRate: 16000,
    threshold: .6,
    verbose: true,
    silence: '5.0'
  })
  .on('error', console.error)
  .pipe(recognizeStream)

  console.log('Google is listening...')
};



streamToParser();

1 个答案:

答案 0 :(得分:0)

想出来 - 我没有使用auth凭据配置Speech,所以我的请求必须已经被优先级排序。这是修复它的配置,根据说明here

const speech = Speech({
    projectId: 'my project ID from the Google Cloud dev console',
    keyFilename: 'path/to/keyfile.json', // that I generated/downloaded from the Google Cloud dev console
});

要创建json密钥文件,请按照"在您自己的服务器上预览的步骤here"部分。