GCP文本到语音API Auth问题

发布于 2025-02-06 08:50:54 字数 1831 浏览 2 评论 0 原文

我在邮递员中尝试了上述API。这是请求JSON:

{
  "input":{
    "text":"Flutter is awesome!"
  },
  "voice":{
    "languageCode":"en-gb",
    "name":"en-GB-Standard-A",
    "ssmlGender":"FEMALE"
  },
  "audioConfig":{
    "audioEncoding":"MP3"
  }
}

对于Auth,我在Postman auth中选择了 Bearer ,并在我的终端中首先执行以下命令以获取令牌:

gcloud auth auth apply-deption-deppact-deffault frant-frint-access < /code>

我将这个令牌粘贴在Auth标题中,并且收到以下答复:

{
    "error": {
        "code": 403,
        "message": "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/. If you are getting this error with curl or similar tools, you may need to specify 'X-Goog-User-Project' HTTP header for quota and billing purposes. For more information regarding 'X-Goog-User-Project' header, please check https://cloud.google.com/apis/docs/system-parameters.",
        "status": "PERMISSION_DENIED",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.ErrorInfo",
                "reason": "SERVICE_DISABLED",
                "domain": "googleapis.com",
                "metadata": {
                    "consumer": "projects/12345678910",
                    "service": "texttospeech.googleapis.com"
                }
            }
        ]
    }
}

我对GCP非常陌生,并且不知道如何导航此问题。对于其他上下文,我正在尝试进行REST API调用,并在其中发送文本并获取Base64Coded String containig音频。任何帮助都将受到赞赏。

I was trying the above api in postman. Here is the request json:

{
  "input":{
    "text":"Flutter is awesome!"
  },
  "voice":{
    "languageCode":"en-gb",
    "name":"en-GB-Standard-A",
    "ssmlGender":"FEMALE"
  },
  "audioConfig":{
    "audioEncoding":"MP3"
  }
}

for auth, i chose Bearer in postman auth and first executed the following command in my terminal to get the token:

gcloud auth application-default print-access-token

i pasted this token in auth header, and i received the following response :

{
    "error": {
        "code": 403,
        "message": "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/. If you are getting this error with curl or similar tools, you may need to specify 'X-Goog-User-Project' HTTP header for quota and billing purposes. For more information regarding 'X-Goog-User-Project' header, please check https://cloud.google.com/apis/docs/system-parameters.",
        "status": "PERMISSION_DENIED",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.ErrorInfo",
                "reason": "SERVICE_DISABLED",
                "domain": "googleapis.com",
                "metadata": {
                    "consumer": "projects/12345678910",
                    "service": "texttospeech.googleapis.com"
                }
            }
        ]
    }
}

I am very new to GCP in general and don't know how to navigate this issue. For additional context, i am trying to make a REST API call where i send the text and get a base64encoded string containig audio back. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2025-02-13 08:50:54

这是令人困惑/复杂的,但错误是有帮助的:

您的应用程序已使用Google Cloud SDK或Google Cloud Cloud Shell的最终用户凭据进行了身份验证,而 texttospeech.googleapis.com 不支持这些应用程序。

注意您可以在此链接上使用Google的API Explorer尝试此方法
text.sext.sext.Synthesize

问题是 gcloud 是oauth2应用程序,由 gcloud 使用 gcloud auth auth print- [access | Identity] -token 和<代码> gcloud auth application-deffault print-access-token 是针对Google管理的项目(Google提供 gcloud >)和 - 重要的是 - not 您自己的项目之一。

Google希望为其用户提供 gcloud ,但不想为其用户免费提供任意API访问。因此,错误的“不支持”部分。

解决方案(如上所述)是您应该:

  1. 使用(或创建)自己的Google项目
  2. 启用本项目中的文本对语音服务(API)
  3. 创建一个服务帐户和键
  4. gcloud auth Activate-Service-Service-Account 提供服务帐户密钥
  5. gcloud auth print-access-token 获取访问令牌以调用API,

请参见以下步骤的链接:

https://cloud.google.com/text-to-speech/docs/libraries

This is confusing/complex but the error is helpful:

Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com.

NOTE You can try this method using Google's APIs Explorer at this link
text.synthesize.

The issue is that gcloud is an OAuth2 application and tokens issued by gcloud either using gcloud auth print-[access|identity]-token and gcloud auth application-default print-access-token are issued against a Google-managed project (that Google provides for gcloud) and -- importantly -- not one of your own projects.

Google wants to provide gcloud for its users but does not want to provide arbitrary API access (for free) to its users. Hence the "not supported" part of the error.

The solution (as described) is that you should:

  1. Use (or create) your own Google Project
  2. Enable the Text-to-Speech service (API) in this project
  3. Create a Service Account and key
  4. gcloud auth activate-service-account providing the Service Account key
  5. gcloud auth print-access-token to get an access token to invoke the API

See the following link for the steps:

https://cloud.google.com/text-to-speech/docs/libraries

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文