gpt4 book ai didi

cloud - Google Cloud Text To Speech API 快速入门示例

转载 作者:行者123 更新时间:2023-12-05 08:54:14 25 4
gpt4 key购买 nike

我是这个论坛的新手。我正在尝试让 Google Cloud TTS API 正常工作,但遇到了一些问题。

页面是:https://cloud.google.com/text-to-speech/docs/quickstart-protocol

我设法浏览了所有页面,直到“从文本合成音频”,正如我在下面引用的那样。我的问题是我根本不明白谷歌要我如何运行脚本。这似乎是 Nix 语句,而我使用的是 Windows。

最初我试图让 Python 示例运行,但我从来没有让它运行。

有人试过并让它工作吗?

引文:

Synthesize audio from text You can convert text to audio by making an HTTP POST request to the https://texttospeech.googleapis.com/v1beta1/text:synthesize endpoint. In the body of your POST command, specify the type of voice to synthesize in the voice configuration section, specify the text to synthesize in the text field of the input section, and specify the type of audio to create in the audioConfig section.

Run the following line at the command line to synthesize audio from text using the Text-to-Speech API. The command uses the gcloud auth application-default print-access-token command to retrieve an authorization token for the request.

The response is directed to the output file, synthesize-output.txt.

Curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > synthesize-text.txt

最佳答案

您是否安装了 cURL?您可以通过执行 curl -V 来检查。如果没有安装,可以按照步骤here

如果您的问题是返回的响应或缺少响应,我建议您使用 API key 而不是服务帐户 key 。

这些是获取 API key 所需的所有步骤

  1. CloudConsole 中创建一个项目(或使用现有项目) .
  2. 确保 billing为您的项目启用。
  3. 启用Text-to-Speech API .
  4. 创建一个 API key .

然后你就可以像这样使用curl命令了

Curl -H "X-Goog-Api-Key: PUT_YOUR_API_KEY_HERE" \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > synthesize-text.txt

关于cloud - Google Cloud Text To Speech API 快速入门示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50705976/

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