Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

text-to-speech command line authentication issue

jcj
Bronze 1
Bronze 1

Hello,

I am trying to run the first example of text-to-speech using the command line described here : https://cloud.google.com/text-to-speech/docs/create-audio-text-command-line

For the prerequisites :
- the Cloud Text-to-Speech API is activated, I can see some requests on the dashboard
- at the beginning, I only had one project; billing of this project is linked to my billing account ; the Cloud Text-to-Speech API is activated

My Workstation : a Windows 11 PC, where I have installed the Google Cloud CLI, and I am using a DOS Windows

1) Trial with the global account I used to subscribe to Google Cloud

gcloud init (global account + 1st project)

the curl command :
curl -X POST ^
-H "Authorization: Bearer $(gcloud auth print-access-token)" ^
-H "x-goog-user-project: XXXXXXXXXXXX" ^
-H "Content-Type: application/json; charset=utf-8" ^
-d @request.json ^
"https://texttospeech.googleapis.com/v1/text:synthesize"
where XXXXXXXXXXXX is my 1st-project-id returns ACCESS_TOKEN_TYPE_UNSUPPORTED

2) Trial with a service account

I created the service account, then created a second project, then I granted owner + Cloud Speech Administrator roles on this project to the service account

gcloud init (service account + 2nd project)

the curl command
curl -X POST ^
-H "Authorization: Bearer $(gcloud auth print-access-token)" ^
-H "x-goog-user-project: YYYYYYYYYYYY" ^
-H "Content-Type: application/json; charset=utf-8" ^
-d @request.json ^
"https://texttospeech.googleapis.com/v1/text:synthesize"
where YYYYYYYYYYYY is my 2nd-project-id returns ACCESS_TOKEN_TYPE_UNSUPPORTED

Can anybody give me some advice to succeed to this basic test ?
Thank you in advance,
Jean-Claude

1 1 94
1 REPLY 1

Hi @jcj,

Thanks for the detailed breakdown. The issue comes from how Windows handles the $(...) syntax — it doesn’t work the same way in Command Prompt (cmd).

Here’s what you can try:

  1. Run this command first to get the token:
    gcloud auth print-access-token

    Copy the output (your access token).

    1. Then run the curl command manually like this (replace YOUR_ACCESS_TOKEN and YOUR_PROJECT_ID):

      curl -X POST ^
      -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ^
      -H "x-goog-user-project: YOUR_PROJECT_ID" ^
      -H "Content-Type: application/json; charset=utf-8" ^
      -d @request.json ^
      "https://texttospeech.googleapis.com/v1/text:synthesize"

      This avoids the ACCESS_TOKEN_TYPE_UNSUPPORTED error, which happens when the access token is not retrieved properly on Windows.