简体   繁体   中英

Getting Google Cloud Text to Speech to work using cURL or Python

I tried following the following advice:

Google Cloud Text To Speech API Quickstart example

Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?)

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

but I just can't get it to work, even with all this information. Regarding the step-by-step-guides, I'm stuck at:

"And then you can use the curl command like so" or "3) They provided a sample request to general a file:"

Where does the code get entered? Powershell only gives me errors, which are in German unfortunately, so I tried translating them. I don't think it's intended to use the code there, since I'm doing nothing else than copy and paste the lines with my credentials.

Here's the error in question, when I paste the code of link #2, step 3) in the Powershell:

In line: 3 characters: 5
+ --data "{
+ ~
Expression is missing after the unary operator "-".
In line: 3 characters: 5
+ --data "{
+ ~~~~
Unexpected token "data" in expression or statement.
In line: 3 characters: 9
+ --data "{
+ ~
In the section "Data" the associated statement block is missing.
In line: 17 characters: 6
+} "" https://texttospeech.googleapis.com/v1/text:synthesize "> synth ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
Unexpected Token "" https://texttospeech.googleapis.com/v1/text:synthesize "" in expression or statement.
    + CategoryInfo: ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId: MissingExpressionAfterOperator

I have tested with Google Cloud Text-to-Speech Interface Confusion (How do I download the mp3 files?) . I got this error in the step 3) and I guess it is what you see:

{
  "error": {
    "code": 403,
    "message": "Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the texttospeech.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/.",
    "status": "PERMISSION_DENIED"
  }
}

So my issue here is the authentication. To solve this, I have followed the steps in this document :

  1. Download Service Account key as JSON file
  2. Run export GOOGLE_APPLICATION_CREDENTIALS="[PATH]" (I'm using a Linux environment)

In your case, you should have run $env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]" since you are using Powershell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM