首页 > 解决方案 > 错误:5 NOT_FOUND:在 LongRunningRecognize 上找不到请求的实体

问题描述

我正在尝试使用 node.js 客户端 Google Speech to Text 和 Google Cloud Function 转录音频文件。不幸的是,我收到了这个错误:

错误:5 NOT_FOUND:未找到请求的实体

我想它来自身份验证问题,但我不确定。

首先,我尝试不使用凭据,假设 GCF 将使用 ADC(应用程序默认凭据)。之后,我将服务帐户中的 client_email 和 private_key 添加到 SpeechClient 选项参数,但它不起作用。我添加了 projectId 和 keyFilename ......不是更好。

也许这不是好方法......我不知道!

这是我的代码。谢谢你的帮助。

const audioFilename = 'gs://' + outputBucket.name + '/' + event.data.name;

const request = {
  "config": {
      "enableWordTimeOffsets": false, 
      "languageCode": "fr-FR",
      "encoding":"FLAC"
  }, 
  "audio": {
      "uri": audioFilename
  }
}
const options = {
  credentials :{
    projectId: 'xxxxxx',
    keyFilename: './xxxxx.json',
    client_email:'xxxx@xxxxx',
    private_key:'xxxxxxxxx'
  }
};
const client = new speech.SpeechClient(options);
client
  .longRunningRecognize(request)
  .then(data => {
    const response = data[0];
    const operation = response;
    operation.on('progress', (metadata, apiResponse) => {
      console.log(JSON.stringify(metadata))
    });
    // Get a Promise representation of the final result of the job
    return operation.promise();
  })
  .then(data => {
    const [response] = data[0];
    const content = response.results
      .map(result => result.alternatives[0].transcript)
      .join('\n');
    console.log(`Transcription: ${content}`);
    resolve(content);
  })
  .catch(err => {
    reject(err);
  });

标签: node.jsgoogle-cloud-functionsgoogle-cloud-speech

解决方案


推荐阅读