Google Cloud Text to Speech INVALID API KEY [英] Google Cloud Text to Speech INVALID API KEY

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

问题描述

我关注了这个页面:

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

我生成了一个访问令牌:

I generated an access token with:

gcloud auth application-default print-access-token

并在输入时:

curl -H "Authorization: Bearer "$(my_token_is_in_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/v1/text:synthesize" > synthesize-text.txt

我明白了:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   605    0   297  100   308    297    308  0:00:01 --:--:--  0:00:01  3517

然后我打开了 synthesize-text.txt 并找到了

Buth then I opened up synthesize-text.txt and found

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

显然 gcloud 给了我一个令牌,为什么文本转语音不能识别它?

Clearly gcloud is giving me a token, why doesnt text-to-speech recognize it?

推荐答案

[SOLVED]

1) 我在汉堡包"下拉菜单中转到了 API 和服务

1) I went to APIs and Services in the 'hamburger' drop down

2) 我转到左栏中的凭据"子菜单

2) I went to 'credentials' submenu in left column

3) 我做了创建凭据"并选择了 API 密钥然后在我的请求中,我将其表述为

3) I did 'create credentials' and selected API key then in my request I formulated as

Curl -H "X-Goog-Api-Key: my-newly-created-API-key" -H "Content-Type: application/json; charset=utf-8" --data "{'input':{'text':'Android 是由 Google 开发的移动操作系统,基于 Linux 内核,主要设计用于智能手机和平板电脑等触摸屏移动设备.'},'voice':{'languageCode':'en-gb','name':'en-GB-Standard-A','ssmlGender':'FEMALE'},'audioConfig':{'audioEncoding':'MP3'}}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > 合成文本.txt

Curl -H "X-Goog-Api-Key: my-newly-created-API-key" -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

现在可以了.

因此,将授权承载"与服务帐户密钥一起使用似乎不起作用.我使用的是 Windows 10.

So it seems the use of 'Authorization Bearer' with the service account key does not work. I am using Windows 10.

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

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