Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = "how are you?"
- convert text to audio file (text.wav)
- open text.wav file & play in browser via django view.
- #Write text to file
- text_file_path = '/user/share/project/test.txt'
- audio_file_path = '/user/share/project/test.wav'
- text_file = open(text_file_path, "w")
- text_file.write('How are you?')
- text_file.close()
- #Convert file
- conv = 'flite -f "%s" -o "%s"' % (text_file_path, audio_file_path)
- response = commands.getoutput(conv)
- if os.path.isfile(audio_file_path):
- response = HttpResponse()
- f = open(audio_file_path, 'rb')
- response['Content-Type'] = 'audio/x-wav'
- response.write(f.read())
- f.close()
- return response
Add Comment
Please, Sign In to add comment