cloud - Google Cloud Text To Speech API 快速入门示例
问题描述
我是这个论坛的新手。我正在尝试让 Google Cloud TTS API 工作,但遇到了一些问题。
该页面是:https ://cloud.google.com/text-to-speech/docs/quickstart-protocol
我设法浏览了所有页面,直到我在下面引用“从文本合成音频”。我的问题是我根本不明白谷歌希望我如何运行脚本。这似乎是一个 Nix 声明,我使用 Windows。
最初我试图让 Python 示例工作,但我从来没有让它工作。
有人试过这个并让它工作吗?
引文:
从文本合成音频您可以通过向https://texttospeech.googleapis.com/v1beta1/text:synthesize端点 发出 HTTP POST 请求将文本转换为音频。在 POST 命令的正文中,在语音配置部分指定要合成的语音类型,在输入部分的文本字段中指定要合成的文本,并在 audioConfig 部分中指定要创建的音频类型。
在命令行中运行以下行以使用 Text-to-Speech API 从文本合成音频。该命令使用gcloud auth application-default print-access-token命令检索请求的授权令牌。
响应被定向到输出文件 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
。如果您没有安装它,您可以按照此处的步骤操作
如果您的问题是返回的响应或缺少响应,我建议使用 API 密钥而不是服务帐户密钥。
这些是获取 API 密钥所需的所有步骤
- 在Cloud Console中创建一个项目(或使用现有项目)。
- 确保为您的项目启用计费。
- 启用文本转语音 API。
- 创建一个API 密钥。
然后你可以像这样使用 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
推荐阅读
- python - os 模块 python 正在工作,但输出不正确
- regex - 如何为文本字段实现正则表达式以在 Extjs 中一次允许一个逗号一个点
- laravel - Laravel - 试图获取非对象的属性“名称”
- java - Spring SAML:后退浏览器按钮导致验证 SAML 消息时出错
- ios - React Native 0.60.4 从 0.59.9 升级
- python - 在 TfidfVectorizer 中删除法语和英语中的停用词
- c# - ASP.NET Core Identity,如何覆盖 IdentityRole Name 唯一索引?我想存储关于租户的重复名称
- web-scraping - 基于页面内容的操作
- javascript - 为什么我的选择器无法读取“状态”?状态未定义
- c# - 将列表项从任务添加到组合框