繁体   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