简体   繁体   English

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

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

I tried following the following advice:我尝试遵循以下建议:

Google Cloud Text To Speech API Quickstart example Google Cloud Text To Speech API 快速入门示例

Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?) Google Cloud Text-to-Speech 界面混乱(如何下载 mp3 文件?)

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

but I just can't get it to work, even with all this information.但即使有所有这些信息,我也无法让它工作。 Regarding the step-by-step-guides, I'm stuck at:关于分步指南,我被困在:

"And then you can use the curl command like so" or "3) They provided a sample request to general a file:" “然后你可以像这样使用 curl 命令”或“3)他们提供了一个通用文件的示例请求:”

Where does the code get entered?代码在哪里输入? Powershell only gives me errors, which are in German unfortunately, so I tried translating them. Powershell 只给我错误,不幸的是这些错误是德语,所以我尝试翻译它们。 I don't think it's intended to use the code there, since I'm doing nothing else than copy and paste the lines with my credentials.我不认为它打算在那里使用代码,因为我除了用我的凭据复制和粘贴行之外什么都不做。

Here's the error in question, when I paste the code of link #2, step 3) in the 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

I have tested with Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?) .我已经使用Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?) 进行了测试 I got this error in the step 3) and I guess it is what you see:我在步骤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"
  }
}

So my issue here is the authentication.所以我的问题是身份验证。 To solve this, I have followed the steps in this document :为了解决这个问题,我按照本文档中的步骤操作:

  1. Download Service Account key as JSON file将服务帐户密钥下载为 JSON 文件
  2. Run export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" (I'm using a Linux environment)运行export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" (我使用的是 Linux 环境)

In your case, you should have run $env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]" since you are using Powershell.在您的情况下,您应该运行$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"因为您使用的是 Powershell。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM