gpt4 book ai didi

python - 使用 cURL 或 Python 使 Google Cloud Text to Speech 正常工作

转载 作者:行者123 更新时间:2023-12-01 08:10:21 24 4
gpt4 key购买 nike

我尝试遵循以下建议:

Google Cloud Text To Speech API Quickstart example

Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?)

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

但即使有了所有这些信息,我还是无法让它工作。关于分步指南,我陷入困境:

“然后你可以像这样使用curl命令”或“3)他们提供了一个通用文件的示例请求:”

代码在哪里输入? Powershell 只给我错误,不幸的是,这些错误是德语的,所以我尝试翻译它们。我不认为它打算使用那里的代码,因为我除了复制并粘贴带有我的凭据的行之外什么也没做。

当我将链接 #2、步骤 3) 的代码粘贴到 Powershell 中时,出现了相关错误:

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"
}
}

所以我的问题是身份验证。为了解决这个问题,我按照 this document 中的步骤操作。 :

  1. 下载 JSON 文件形式的服务帐户 key
  2. 运行 export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"(我使用的是 Linux 环境)

就您而言,由于您使用的是 Powershell,因此应该运行 $env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

关于python - 使用 cURL 或 Python 使 Google Cloud Text to Speech 正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55293588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com