GCP文本到语音API Auth问题
我在邮递员中尝试了上述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音频。任何帮助都将受到赞赏。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是令人困惑/复杂的,但错误是有帮助的:
您的应用程序已使用Google Cloud SDK或Google Cloud Cloud Shell的最终用户凭据进行了身份验证,而
texttospeech.googleapis.com
不支持这些应用程序。问题是
gcloud
是oauth2应用程序,由gcloud
使用gcloud auth auth print- [access | Identity] -token
和<代码> gcloud auth application-deffault print-access-token 是针对Google管理的项目(Google提供gcloud
>)和 - 重要的是 - not 您自己的项目之一。Google希望为其用户提供
gcloud
,但不想为其用户免费提供任意API访问。因此,错误的“不支持”部分。解决方案(如上所述)是您应该:
gcloud auth Activate-Service-Service-Account
提供服务帐户密钥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
.The issue is that
gcloud
is an OAuth2 application and tokens issued bygcloud
either usinggcloud auth print-[access|identity]-token
andgcloud auth application-default print-access-token
are issued against a Google-managed project (that Google provides forgcloud
) 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:
gcloud auth activate-service-account
providing the Service Account keygcloud auth print-access-token
to get an access token to invoke the APISee the following link for the steps:
https://cloud.google.com/text-to-speech/docs/libraries