Skip to content

Instantly share code, notes, and snippets.

@c80609a
Forked from samoshkin/convert2voice.sh
Created September 12, 2023 06:44
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 c80609a/f93af42150772ede7637cff137ec50da to your computer and use it in GitHub Desktop.
Save c80609a/f93af42150772ede7637cff137ec50da to your computer and use it in GitHub Desktop.
Google Text-to-Speech API example
#!/bin/bash
text=$(cat -)
request="{
'input':{
'ssml':'<speak>$text</speak>'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Wavenet-D',
'ssmlGender':'MALE'
},
'audioConfig':{
'speakingRate': 1.0,
'pitch': -2,
'audioEncoding':'MP3'
}
}"
token=$(gcloud auth application-default print-access-token)
echo $request | http -p b https://texttospeech.googleapis.com/v1/text:synthesize "Authorization: Bearer $token" | jq --raw-output ".audioContent" | base64 --decode
<s>On <say-as interpret-as=\"date\" format=\"yyyymmdd\" detail=\"1\">2019-03-31</say-as>, presidential elections in Ukraine took place.</s>
<s>In the first round, the current president, Petro Poroshenko, takes the <say-as interpret-as="ordinal">2</say-as> place, with 16.03 percent of votes.</s>
<s>The information is provided by <say-as interpret-as="characters">CVK</say-as>, <break time="0.4s"/>the Central Election Commission</s>
On 2019-03-31, presidential elections in Ukraine took place.
In the first round, the current president, Petro Poroshenko, takes the 2nd place, with 16.03 percent of votes.
The information is provided by CVK, the Central Election Commission
cat input_ssml.txt | ./convert2voice.sh > voice.mp3 && open voice.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment