【问题标题】:Can't go through "Requested entity was not found" error with Speech-to-Text APISpeech-to-Text API 无法通过“未找到请求的实体”错误
【发布时间】:2019-06-07 15:21:22
【问题描述】:

我在 GCS 事件触发的 Cloud Function 中调用 Cloud Speech-to-Text API。 在云函数(运行node index.js)之外执行此操作非常好,但我的错误随后出现。

使用this doc,我认为错误是由于身份验证问题造成的,但我尝试了几件事,现在不太确定。

我的代码是:

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const nl = require('@google-cloud/language');
const client_nl = new nl.LanguageServiceClient();
const speech = require('@google-cloud/speech');
const client_speech = new speech.SpeechClient();

exports.getRecording = (data,context) => {
  const file = data;
  if (file.resourceState === 'not_exists') {
    // Ignore file deletions
    return true;
  } else if (!new RegExp(/\.(wav|mp3)/g).test(file.name)) {
    // Ignore changes to non-audio files
    return true;
  }

  console.log(`Analyzing gs://${file.bucket}/${file.name}`);

  const bucket = storage.bucket(file.bucket);
  const audio = {
    uri: 'gs://${file.bucket}/${file.name}'
  };

  // Configure audio settings for BoF recordings
  const audioConfig = {
    encoding: 'LINEAR16',
    sampleRateHertz: 44100,
    languageCode: 'fr-FR'
  };

  const request = {
    audio: audio,
    config: audioConfig,
  };

  return client_speech.recognize(request)
    .then(([transcription]) => {
      const filename = `analysis.json`;
      console.log(`Saving gs://${file.bucket}/${filename}`);

      return bucket
        .file(filename)
        .save(JSON.stringify(transcription, null, 2));
  });

然后我部署: gcloud functions deploy getRecording --runtime nodejs10 --trigger-resource trigger-bucket-id --trigger-event google.storage.object.finalize --service-account my-service-account

我尝试了什么:

  1. export GOOGLE_APPLICATION_CREDENTIALS=/path/to/file/keyfile.json
  2. 添加了一个带有"GOOGLE_APPLICATION_CREDENTIALS":"./keyfile.json"config.json 文件,以及根项目中的密钥文件和index.js 中的require('./config.json')
  3. 添加了一个选项 json
const options = {
    projectId: 'my-project-id',
    keyFilename: './key-file.json'
  };
const client_speech = new speech.SpeechClient(options);

我不断收到此错误,需要一些帮助

D      getRecording  573287126069013  2019-06-07 15:03:09.609  Function execution started
       getRecording  573287126069013  2019-06-07 15:03:09.789  Analyzing gs://my-bucket/audio_trimed.wav
D      getRecording  573287126069013  2019-06-07 15:03:10.979  Function execution took 1372 ms, finished with status: 'error'
E      getRecording  573291408785013  2019-06-07 15:03:11.990  Error: Requested entity was not found.
                                                                   at Http2CallStream.call.on (/srv/functions/node_modules/@grpc/grpc-js/build/src/client.js:101:45)
                                                                   at Http2CallStream.emit (events.js:194:15)
                                                                   at Http2CallStream.EventEmitter.emit (domain.js:459:23)
                                                                   at Http2CallStream.endCall (/srv/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:63:18)
                                                                   at handlingTrailers (/srv/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:152:18)
                                                                   at process._tickCallback (internal/process/next_tick.js:68:7)

【问题讨论】:

    标签: node.js google-cloud-platform google-cloud-speech


    【解决方案1】:

    this code 有帮助吗? 有一些 StackOverflow 帖子可能对 herehere 有帮助

    我建议更详细的日志记录/调试。 例如,你能证明这两行符合你的预期吗?字符串是否产生格式良好的 uri?

    const bucket = storage.bucket(file.bucket);
      const audio = {
        uri: 'gs://${file.bucket}/${file.name}'
      };
    

    如果您找到解决方案,请告诉我们

    【讨论】:

    • 嘿@Bruce 谢谢你的回答。我的问题是,在本地运行您提供给我的快速入门时我没有遇到任何问题。当我在 Cloud Function 中使用相同的代码时,我的问题就出现了。在我的代码中,你可以看到console.log('Analyzing gs://${file.bucket}/${file.name}');这行打印了预期的值,而下一行没有改变文件变量
    【解决方案2】:

    @Bruce 是对的,我终于发现了错误。 我只是看不到它是写的 uri:'gs://${file.bucket}/${file.name}'

    而不是

    uri: `gs://${file.bucket}/${file.name}`
    

    (是的,这个错误很小,但可以通过更多测试来避免......

    【讨论】:

      猜你喜欢
      • 2012-10-04
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多