问题
I am all new to this forum. I am trying to get the Google Cloud TTS API to work but ran into some issues.
The page is: https://cloud.google.com/text-to-speech/docs/quickstart-protocol
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.
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?
Citation:
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.
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.
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
回答1:
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
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.
These are all the steps you need to get to the the API key
- Create a project (or use an existing one) in the Cloud Console.
- Make sure that billing is enabled for your project.
- Enable the Text-to-Speech API.
- Create an API key.
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
来源:https://stackoverflow.com/questions/50705976/google-cloud-text-to-speech-api-quickstart-example