簡體   English   中英

使用 cURL 或 Python 使 Google Cloud Text to Speech 工作

[英]Getting Google Cloud Text to Speech to work using cURL or Python

我嘗試遵循以下建議:

Google Cloud Text To Speech API 快速入門示例

Google Cloud Text-to-Speech 界面混亂(如何下載 mp3 文件?)

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

但即使有所有這些信息,我也無法讓它工作。 關於分步指南,我被困在:

“然后你可以像這樣使用 curl 命令”或“3)他們提供了一個通用文件的示例請求:”

代碼在哪里輸入? Powershell 只給我錯誤,不幸的是這些錯誤是德語,所以我嘗試翻譯它們。 我不認為它打算在那里使用代碼,因為我除了用我的憑據復制和粘貼行之外什么都不做。

這是有問題的錯誤,當我在 Powershell 中粘貼鏈接 #2,步驟 3) 的代碼時:

In line: 3 characters: 5
+ --data "{
+ ~
Expression is missing after the unary operator "-".
In line: 3 characters: 5
+ --data "{
+ ~~~~
Unexpected token "data" in expression or statement.
In line: 3 characters: 9
+ --data "{
+ ~
In the section "Data" the associated statement block is missing.
In line: 17 characters: 6
+} "" https://texttospeech.googleapis.com/v1/text:synthesize "> synth ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
Unexpected Token "" https://texttospeech.googleapis.com/v1/text:synthesize "" in expression or statement.
    + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId: MissingExpressionAfterOperator

我已經使用Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?) 進行了測試 我在步驟3)遇到此錯誤,我想這就是您所看到的:

{
  "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 that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.",
    "status": "PERMISSION_DENIED"
  }
}

所以我的問題是身份驗證。 為了解決這個問題,我按照本文檔中的步驟操作:

  1. 將服務帳戶密鑰下載為 JSON 文件
  2. 運行export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" (我使用的是 Linux 環境)

在您的情況下,您應該運行$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"因為您使用的是 Powershell。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM