0

我使用的代码与Google 的示例非常相似,用于使用 Node.js 客户端库对音频流执行语音识别。

API 正在正确解析我的音频,但我发现自己等待了 30-45 秒才能得到响应。考虑到演示有多快,这似乎不对。有什么我配置不正确的吗?

我尝试写入本地文件只是为了确保音频清晰通过,并且录音看起来很好。

谢谢你提供的所有帮助!

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();
4

1 回答 1

1

想通了 - 我没有配置Speech身份验证凭据,所以我的请求必须被取消优先级。根据此处的说明,这是修复它的配置:

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密钥文件,请按照“在您自己的服务器上”部分中列出的步骤进行操作。

于 2017-06-11T23:25:12.430 回答