Last active
November 14, 2018 10:54
-
-
Save megaherz/f2bf3095c7cb02e351871a1f881b291e to your computer and use it in GitHub Desktop.
Google text-to-speech from file in terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# jq and gcloud are prerequisites | |
# voices: https://cloud.google.com/text-to-speech/docs/voices | |
export GOOGLE_APPLICATION_CREDENTIALS="gcloud.json" # Create your own | |
accessToken=$(gcloud auth application-default print-access-token) | |
translate() { | |
curl --silent -H "Authorization: Bearer "${accessToken} \ | |
-H "Content-Type: application/json; charset=utf-8" \ | |
--data "{ | |
'input':{ | |
'text':'$2' | |
}, | |
'voice':{ | |
'languageCode':'en-gb', | |
'name':'en-GB-Standard-A', | |
'ssmlGender':'FEMALE' | |
}, | |
'audioConfig':{ | |
'audioEncoding':'MP3' | |
} | |
}" "https://texttospeech.googleapis.com/v1/text:synthesize" | jq '.audioContent' -r | base64 --decode > audio/$1.mp3 | |
} | |
while IFS=' ' read -r id text | |
do | |
echo ${id} | |
translate ${id} ${text} | |
done < vocab.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id1 tea | |
id2 apple | |
id3 banana | |
id4 beer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment