How to convert text into audio file which can be played in browser via python/django views?
How can I do text-to-speech conversion in python? I want to convert a string to a .wav file, that will be played in a browser via python/django views.
For example:
text = "how are you?"
convert text to audio file (text.wav)
open text.wav file & play in browser via django view.
As Tichodroma says, you should always see if someone has already asked your question before asking it again. Google search for python text to speech
returns http://code.google.com/p/pyspeech/ and How to make Python speak, among others.
I have tried to do like following way & it works for me. Thanks.
#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