Guest User

Untitled

a guest
Jan 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. text = "how are you?"
  2. convert text to audio file (text.wav)
  3. open text.wav file & play in browser via django view.
  4.  
  5. #Write text to file
  6. text_file_path = '/user/share/project/test.txt'
  7. audio_file_path = '/user/share/project/test.wav'
  8. text_file = open(text_file_path, "w")
  9. text_file.write('How are you?')
  10. text_file.close()
  11.  
  12. #Convert file
  13. conv = 'flite -f "%s" -o "%s"' % (text_file_path, audio_file_path)
  14. response = commands.getoutput(conv)
  15.  
  16. if os.path.isfile(audio_file_path):
  17. response = HttpResponse()
  18. f = open(audio_file_path, 'rb')
  19. response['Content-Type'] = 'audio/x-wav'
  20. response.write(f.read())
  21. f.close()
  22. return response
Add Comment
Please, Sign In to add comment