Google Cloud Speech API 无法在 Raspberry Pi 3 Raspbian OS 上的命令行



我正在使用gcloud SDK在Raspberry Pi 3 Raspbian OS上测试Google Cloud Speech API命令行。谷歌提供的标准程序适用于我的Mac OSX!在 Raspbian 中尝试失败。

我尝试设置像"GOOGLE_APPLICATION_CREDENTIALS"和"GCLOUD_PROJECT"这样的 ENV var,当这不起作用时,我取消设置这些变量并尝试运行"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"
          }
        ]
      }
    ]
  }
}

通过在运行"gcloud auth"命令时指定"应用程序默认值"来解决身份验证问题(这意味着登录和打印访问令牌时)

首次运行:

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

最新更新