Skip to content

Instantly share code, notes, and snippets.

@gabriserra
Last active July 8, 2020 13:24
Show Gist options
  • Save gabriserra/c849eb626a48182b366b8b3c6a628017 to your computer and use it in GitHub Desktop.
Save gabriserra/c849eb626a48182b366b8b3c6a628017 to your computer and use it in GitHub Desktop.
Allows to generate an mp3 audio track of specified text. Uses Google Cloud service and need Google Cloud CLI
# export Google Credentials service account path
export GOOGLE_APPLICATION_CREDENTIALS=~/Keys/da-service-account.json
curl \
-vX POST https://texttospeech.googleapis.com/v1/text:synthesize \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @ttsbody.json > synthesize-text.txt # specify your json file
# get response and encode as mp3
cat synthesize-text.txt | grep 'audioContent' | \
sed 's|audioContent| |' | tr -d '\n ":{},' > tmp.txt && \
base64 tmp.txt --decode > synthesize-text-audio.mp3 && \
rm synthesize-text.txt \
rm tmp.txt
{
"audioConfig": {
"audioEncoding": "mp3",
"effectsProfileId": [
"small-bluetooth-speaker-class-device"
],
"pitch": 0,
"speakingRate": 1
},
"input": {
"text": "Benvenuto in Delivery Aggregator! Premi \"uno\" per ricevere assistenza tecnica, premi \"due\" per ricevere assistenza commerciale oppure premi \"tre\" per ricevere assistenza amministrativa."
},
"voice": {
"languageCode": "it-IT",
"name": "it-IT-Wavenet-A"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment