Good day @jpd633 ,
Welcome to Google Cloud Community!
This may have happened due to the options you’ve used when using the curl command, you can try following the options I’ve used:
curl -X POST
-H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project:<INSERT-YOUR-PROJECT-ID>"
-H "Content-Type: application/json; charset=utf-8"
-d @request.json
"https://texttospeech.googleapis.com/v1/text:synthesize"
The request.json contains the sample request in the documentation you’ve sent: https://cloud.google.com/text-to-speech/docs/create-audio-text-command-line
{
"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"
}
}
To save the output to a file, you can use > at the end. See sample the below:
curl -X POST
-H "Authorization: Bearer $(gcloud auth print-access-token)"
-H "x-goog-user-project:<INSERT-YOUR-PROJECT-ID>"
-H "Content-Type: application/json; charset=utf-8"
-d @request.json
"https://texttospeech.googleapis.com/v1/text:synthesize" > synthesize-out.txt
After that you can decode the contents of synthesize-out.txt file to mp3 file, based from the documentation you have sent.
base64 SOURCE_BASE64_TEXT_FILE -d > DESTINATION_AUDIO_FILE
if you encountered an invalid input error, try including i in your options:
base64 SOURCE_BASE64_TEXT_FILE -di > DESTINATION_AUDIO_FILE
Since your goal is to synthesize batches of text files thru python scripts, you can use this guide on how to make a request using client libraries (Python) to Text-to-Speech: https://cloud.google.com/text-to-speech/docs/create-audio-text-client-libraries#client-libraries-install-python
Hope this helps!