Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3.4
- import requests
- import os
- api_key = os.getenv('API_KEY_TTS')
- if not api_key: exit('Api key not found!')
- url = 'https://admin.ttsgo.com.br/api/textToSpeech'
- texto = 'Obrigado'
- payload = {
- 'text': texto,
- 'api_key': api_key,
- 'voz': 'feminina'
- }
- def get_file_name(path):
- return os.path.split(path)[1]
- def download_file(url):
- file_name = get_file_name(url)
- response = requests.get(url)
- with open(file_name, 'wb') as fd:
- for chunk in response.iter_content(chunk_size=128):
- fd.write(chunk)
- print('Download concluido do arquivo ', file_name)
- response = requests.get(url, params=payload)
- response_json = response.json()
- if response_json['status'] == 'OK':
- #baixe e grave arquiv
- print('Baixando arquivo..')
- download_file(response_json['url'])
- else:
- #teste outra palavra ou saia
- print('Ocorreu um erro', response_json)
Add Comment
Please, Sign In to add comment