Google Cloud Text To Speech REST API Authenticatio

2019-08-31 02:55发布

问题:

So I want to use the Google Cloud Text to Speech using a simple POST request from my C++ program, the problem is with their authentication. I did create a service account as they mentioned and I got the file containing my private key. But I don't know how can I use it in my POST request to be authenticated ?

POST Url: https://texttospeech.googleapis.com/v1beta1/text:synthesize and here is my POST body:

{ "audioConfig": { "audioEncoding": "LINEAR16", "pitch": "0.00", "speakingRate": "1.00" }, "input": { "text": "Hello World" }, "voice": { "languageCode": "en-US", "name": "en-US-Wavenet-E" } }

回答1:

You have to set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your service account key.



回答2:

I found out that I need to create an API Key Credential from the following link: https://console.developers.google.com/apis/credentials?project=[your-project-name]

and then append "?key=[API_KEY]" to my POST url and the authentication problem is fixed !