0

我正在使用 gcloud SDK 在 Raspberry Pi 3 Raspbian OS 上测试 Google Cloud Speech API 命令行。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' 的内容,请参阅快速入门指南示例)。

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

输出:

    {
  "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"
          }
        ]
      }
    ]
  }
}
4

1 回答 1

1

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

首轮:

gcloud auth application-default login

*** 或者您可以为您的服务帐户的 private_key_id 设置“GOOGLE_APPLICATION_CREDENTIALS”环境变量。

下一次运行:

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"
        }
      ]
    }
  ]
}
于 2017-01-12T21:17:07.137 回答