2

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. 
meshy
  • 8,470
  • 9
  • 51
  • 73
shrenik
  • 49
  • 2
  • 6
  • You will need some kind of text to speech engine. An open source engine is festival: http://www.cstr.ed.ac.uk/projects/festival/ – korylprince Sep 28 '12 at 07:51
  • 5
    Welcome to Stack Overflow! We encourage you to [research your questions](http://stackoverflow.com/questions/how-to-ask). If you've [tried something already](http://whathaveyoutried.com/), please add it to the question - if not, research and attempt your question first, and then come back. –  Sep 28 '12 at 07:51
  • 1
    There's also a js text-to-speech program called [speak.js](https://github.com/kripken/speak.js) – Landric Sep 28 '12 at 12:07

2 Answers2

0

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.

Community
  • 1
  • 1
Dave
  • 3,834
  • 2
  • 29
  • 44
0

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
shrenik
  • 49
  • 2
  • 6