Google Cloud Speech API 无法在 Raspberry Pi 上的命令行中进行身份验证 3 Raspbian OS

Google Cloud Speech API cannot auth in command-line on Raspberry Pi 3 Raspbian OS

我正在使用 gcloud SDK 在 Raspberry Pi 3 Raspbian OS 上测试 Google Cloud Speech API 命令行。 standard procedure Google 提供在我的 Mac OSX 上工作!在 Raspbian 中尝试失败。

我尝试设置 ENV 变量,如 "GOOGLE_APPLICATION_CREDENTIALS" 和 "GCLOUD_PROJECT",当这不起作用时,我取消设置这些变量并尝试 运行 "gcloud beta init" 而不是 "gcloud init"。没有这些作品的组合。

命令:

curl -v -k -s -H "Content-Type: application/json" -H "Authorization: Bearer `gcloud auth print-access-token`" "https://speech.googleapis.com/v1beta1/speech:syncrecognize" -d @sync-request.json

(注:'sync-request.json'内容请见quickstart guide example

我收到的错误消息如下所示。似乎选择了错误的项目:

输出:

    {
  "error": {
    "code": 403,
    "message": "Google Cloud Speech API has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console API activation",
            "url": "https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool"
          }
        ]
      }
    ]
  }
}

通过在 运行ning "gcloud auth" 命令时指定 "application-default" 解决了身份验证问题(这意味着登录和打印访问令牌时)

第一个运行:

gcloud auth application-default login

*** 或者您可以为服务帐户的 private_key_id.

设置 "GOOGLE_APPLICATION_CREDENTIALS" env var

下一个运行:

curl -v -k -s -H "Content-Type: application/json" -H "Authorization: Bearer `gcloud auth application-default print-access-token`" "https://speech.googleapis.com/v1beta1/speech:syncrecognize" -d @sync-request.json

你应该看到:

{
  "results": [
    {
      "alternatives": [
        {
          "transcript": "how old is the Brooklyn Bridge"
        }
      ]
    }
  ]
}