node.js - 使用 Speech-to-Text API 无法解决 "Requested entity was not found"错误

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

我在 GCS 事件触发的云函数中调用云语音转文本 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 函数部署 getRecording --runtime nodejs10 --trigger-resource trigger-bucket-id --trigger-event google.storage.object.finalize --service-account my-service-account

我尝试过:

  1. 导出 GOOGLE_APPLICATION_CREDENTIALS=/path/to/file/keyfile.json
  2. 添加了一个 config.json 文件,其中包含 "GOOGLE_APPLICATION_CREDENTIALS":"./keyfile.json",以及根项目中的 key 文件和 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)

最佳答案

this code 中的任何一个吗帮助? 有一些 StackOverflow 帖子可能会有所帮助 here ,和here

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

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

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

关于node.js - 使用 Speech-to-Text API 无法解决 "Requested entity was not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56497171/

相关文章:

ios - 谷歌云语音 API 响应 : Parsing iOS

node.js - EJS 不渲染从 res.render 返回的值

postgresql - 在 Google Cloud SQL 中查看数据的 GUI

kubernetes - 从 k8s 入口动态添加/删除命名主机

nginx - 将我的Docker容器暴露于GCP上的外部IP

python - 使用 Tensorflow 服务的双向流

javascript - 使用 Google Cloud Speech-to-text 时出现空错误

javascript - Node 休息客户端获取局部变量

python - NodeJS stdout python 多次打印?

javascript - 使用 setInterval() 无限异步循环