arturmnt

TTSGO_PYTHON_FRANKLIN

Aug 17th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3.4
  2.  
  3. import requests
  4. import os
  5.  
  6. api_key = os.getenv('API_KEY_TTS')
  7. if not api_key: exit('Api key not found!')
  8.  
  9. url = 'https://admin.ttsgo.com.br/api/textToSpeech'
  10. texto = 'Obrigado'
  11. payload = {
  12.         'text': texto,
  13.         'api_key': api_key,
  14.         'voz': 'feminina'
  15.         }
  16.  
  17. def get_file_name(path):
  18.     return os.path.split(path)[1]
  19.    
  20. def download_file(url):
  21.    
  22.     file_name = get_file_name(url)
  23.     response = requests.get(url)
  24.    
  25.     with open(file_name, 'wb') as fd:
  26.         for chunk in response.iter_content(chunk_size=128):
  27.             fd.write(chunk)
  28.            
  29.     print('Download concluido do arquivo ', file_name)
  30.  
  31.  
  32. response = requests.get(url, params=payload)
  33. response_json = response.json()
  34. if response_json['status'] == 'OK':
  35.     #baixe e grave arquiv
  36.     print('Baixando arquivo..')
  37.     download_file(response_json['url'])
  38. else:
  39.     #teste outra palavra ou saia
  40.     print('Ocorreu um erro', response_json)
Add Comment
Please, Sign In to add comment