Skip to content

Instantly share code, notes, and snippets.

@florabtw
Created September 28, 2019 20:31
Show Gist options
  • Save florabtw/aebe4c5594e0737a9ad3990cb8b4f900 to your computer and use it in GitHub Desktop.
Save florabtw/aebe4c5594e0737a9ad3990cb8b4f900 to your computer and use it in GitHub Desktop.
Using Sound of Text API in Python 3
import time
import requests
data = { 'engine': 'Google', 'data': { 'voice': 'en-US', 'text': 'Hello, world!' } }
response = requests.post(
'https://api.soundoftext.com/sounds',
headers={'Content-Type':'application/json'},
json=data
)
sound_request = response.json()
print ("Sound Request:")
print (sound_request)
def get_sound(sound_id):
response = requests.get(f'https://api.soundoftext.com/sounds/{sound_id}')
sound_status = response.json()
if sound_status['status'] is 'Pending':
print ('Sleeping...')
time.sleep(2)
return get_sound(sound_id)
return sound_status['location']
sound_url = get_sound(sound_request['id'])
print ("Sound Url:")
print (sound_url)
file_request = requests.get(sound_url)
with open('hello-world.mp3', 'wb') as sound_file:
sound_file.write(file_request.content)
print ("Finished! Try opening 'hello-world.mp3'!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment