使用cURL或Python将googlecloud文本转换为语音

使用cURL或Python将googlecloud文本转换为语音,python,curl,google-cloud-platform,gcloud,google-text-to-speech,Python,Curl,Google Cloud Platform,Gcloud,Google Text To Speech,我尝试了以下建议: 但我就是不能让它工作,即使有这些信息。 关于循序渐进的指南,我的重点是: 然后您可以使用curl命令,如“so”或“3)他们提供了一个示例请求,用于常规文件: 代码在哪里输入?Powershell只给我错误,不幸的是,这些错误是德语的,所以我尝试翻译它们。我不认为它打算在那里使用代码,因为我只是用我的凭证复制和粘贴行 下面是我在Powershell中粘贴链接#2,步骤3)的代码时遇到的错误: In line: 3 characters: 5 + --data "{ +

我尝试了以下建议:

但我就是不能让它工作,即使有这些信息。 关于循序渐进的指南,我的重点是:

然后您可以使用curl命令,如“so”或“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
我已经测试过了。我在步骤
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"
  }
}
所以我这里的问题是身份验证。为了解决这个问题,我遵循了以下步骤:

  • 将服务帐户密钥下载为JSON文件
  • 运行
    export GOOGLE\u APPLICATION\u CREDENTIALS=“[PATH]”
    (我正在使用Linux环境)

  • 在您的情况下,您应该运行
    $env:GOOGLE\u APPLICATION\u CREDENTIALS=“[PATH]”
    ,因为您正在使用Powershell。

    非常感谢您的帮助!!我应该澄清得更清楚些——对不起。认证过程似乎是成功的,至少现在它不是我问题的罪魁祸首。我翻译了错误代码并编辑了我的帖子。我在编程方面不是很有经验,但看起来我使用的语法是powershell无法使用的。由于没有进一步说明如何处理步骤3)中的代码,我只是将其粘贴到终端中,但效果不太好。。。你知道我做错了什么吗?我可以在Windows环境中重现同样的错误,我认为这里的问题是如何指定旋度。正如我所看到的,命令在PS中应该是不同的。然而,我不熟悉PS,你可以做进一步的研究。