Skip to content

Instantly share code, notes, and snippets.

@miczed
Created April 29, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miczed/37636bc5daf3efb68189ba8217a86a76 to your computer and use it in GitHub Desktop.
Save miczed/37636bc5daf3efb68189ba8217a86a76 to your computer and use it in GitHub Desktop.
Synthesize text to speech using google's cloud api and store it as MP3 file.
printf -e "This will use the google text to speech API to synthesize the text and save it in a file"
echo -e "What text should be synthesized?"
read text
echo -e "What file should the text be stored to (without extension)?"
read filename
export GOOGLE_APPLICATION_CREDENTIALS="google_credentials.json"
echo -e "Downloading audio from google cloud"
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d '{"input":{"text":"'"$text"'"},"voice":{"languageCode":"en-gb","name":"en-GB-Wavenet-A","ssmlGender":"FEMALE"},"audioConfig":{"audioEncoding":"MP3"}}' \
https://texttospeech.googleapis.com/v1/text:synthesize \
| jq -r '.audioContent' | base64 --decode > "$filename.mp3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment