Google Cloud Text To Speech API快速入门示例 [英] Google Cloud Text To Speech API Quickstart example

查看:591
本文介绍了Google Cloud Text To Speech API快速入门示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am all new to this forum. I am trying to get the Google Cloud TTS API to work but ran into some issues.

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

我设法完成了所有直到从文本合成音频为止,如下所述。我的问题是我根本不了解Google如何让我运行脚本。好像是Nix语句,我使用Windows。

I manage to go through all the page until "Synthesize audio from text" as I quote below. My problem is that I simply do not understand how Google want me to run the script. It seems like a Nix statement and I use Windows.

最初,我试图使Python示例正常工作,但我从未尝试过。

Originally I tried to get the Python examples to work, but I never got it to work.

有人尝试过并使其正常工作吗?

Anybody tried this and got it to work?

引用:


从文本合成音频
您可以通过对<一个href = https://texttospeech.googleapis.com/v1beta1/text:synthesize rel = nofollow noreferrer> https://texttospeech.googleapis.com/v1beta1/text:synthesize 端点。在POST命令的主体中,在语音配置部分中指定要合成的语音类型,在输入部分的文本字段中指定要合成的文本,并在audioConfig部分中指定要创建的音频的类型。

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.

在命令行中运行以下行,以使用Text-to-Speech API从
文本中合成音频。
该命令使用 gcloud auth
application-default print-access-token
命令,用于检索请求的
授权令牌。

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.

响应将定向到输出文件synthesize-output.txt。

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 进行检查。
如果尚未安装,则可以按照以下步骤操作此处

Do you have cURL installed? You can check by doing curl -V. If you don't have it installed, you can follow the steps here

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

If your problem is with the response returned, or the lack thereof, I would recommend using the API key instead of the service account key.

这些都是获取API密钥所需的所有步骤

These are all the steps you need to get to the the API key


  1. 云$ b $中创建一个项目(或使用现有项目) b控制台

  2. 确保计费为为您的项目启用。

  3. 启用文本-to-Speech API

  4. 创建一个 API密钥

  1. Create a project (or use an existing one) in the Cloud Console.
  2. Make sure that billing is enabled for your project.
  3. Enable the Text-to-Speech API.
  4. Create an API key.

然后您可以像这样使用curl命令

And then you can use the curl command like so

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

这篇关于Google Cloud Text To Speech API快速入门示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆