Skip to content

Instantly share code, notes, and snippets.

@samoshkin
Last active September 12, 2023 06:44
Show Gist options
  • Save samoshkin/3de88204f32f7e898fe2ed085723039e to your computer and use it in GitHub Desktop.
Save samoshkin/3de88204f32f7e898fe2ed085723039e 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