在 npm @google-cloud/speech 中使用 API 键

use API key in npm @google-cloud/speech

这是来自https://www.npmjs.com/package/@google-cloud/speech

的代码
   var speech = require('@google-cloud/speech');

   var client = speech({
      // optional auth parameters. 
   });

如何在使用@google-cloud/speech 时传递我的 API 密钥进行身份验证?我阅读了文档并看到了示例,但他们没有谈论使用 API 键。有什么方法可以使用 API 密钥进行身份验证吗?

我发现要在你的 nodejs 中使用 @google-cloud/speech 模块,你必须在 Google Cloud Platform 上创建一个项目并且需要登录到你的 google帐户并将您的 projectid 作为参数提供给语音构造函数,以便成功登录。

const speechClient = Speech({
     projectId: projectId
});

这将验证您是否可以调用 Google 语音 API。我找不到可以使用 google API 密钥进行身份验证的文档。

您需要服务帐户密钥(它是 JSON 密钥文件)。转到

Google speech api dashboard  ->  credentials   ->  create credentials 
->  Service account key   ->  Compute engine default   ->  download json file.

最后将其添加到配置中作为keyFile,例如:

{ 
  projectId: 'my-project', 
  keyFile: './myKeyFile.json' 
};

来源: https://bloggerbrothers.com/2017/01/15/the-complete-guide-to-enabling-speech-recognition-on-an-rpi3-in-nodejs/