我在郵遞員中嘗試了上面的api。這是請求json:
{
"input":{
"text":"Flutter is awesome!"
},
"voice":{
"languageCode":"en-gb",
"name":"en-GB-Standard-A",
"ssmlGender":"FEMALE"
},
"audioConfig":{
"audioEncoding":"MP3"
}
}
對于身份驗證,我選擇Bearer了郵遞員身份驗證并首先在我的終端中執行以下命令來獲取令牌:
gcloud auth application-default print-access-token
我將此令牌粘貼到 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 呼叫,在其中發送文本并獲取包含音頻的 base64 編碼字串。任何幫助表示贊賞。
uj5u.com熱心網友回復:
這令人困惑/復雜,但錯誤很有幫助:
您的應用程式已使用來自 Google Cloud SDK 或 Google Cloud Shell 的最終用戶憑據進行身份驗證,而texttospeech.googleapis.com.
注意您可以在此鏈接上使用 Google 的 APIs Explorer 嘗試此方法
text.synthesize。
問題在于,這gcloud是一個 OAuth2 應用程式和令牌,它們gcloud使用gcloud auth print-[access|identity]-token和gcloud auth application-default print-access-token針對 Google 管理的專案(Google 提供gcloud)和 - 重要的是 -不是您自己的專案之一。
Google 希望gcloud為其用戶提供服務,但不希望向其用戶提供任意 API 訪問(免費)。因此,錯誤的“不支持”部分。
解決方案(如所述)是您應該:
- 使用(或創建)您自己的 Google 專案
- 在此專案中啟用 Text-to-Speech 服務 (API)
- 創建服務帳戶和密鑰
gcloud auth activate-service-account提供服務帳戶密鑰gcloud auth print-access-token獲取訪問令牌以呼叫 API
有關步驟,請參閱以下鏈接:
https://cloud.google.com/text-to-speech/docs/libraries
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/491115.html
