3

What I'm trying to achieve is to save a text to speech output from Python to an audiofile.

Well the only constraint is Python version 2.7 (would be cool if it runs on Windows and ubuntu, but not necessary). I found pyttsx and managed to have a text read but I can't capture it because there is no method like in pyTTS SpeakToMemory. Well pyTTS is just available for Python 2.5. I can't use that either.

How can I make a text to speech and save it in an audio file with python 2.7?

Charles
  • 50,943
  • 13
  • 104
  • 142
DIDoS
  • 812
  • 9
  • 23
  • I can't really figure where your problem lies, could you provide a little more insight on your issue? – Thomas Orozco Nov 17 '11 at 18:24
  • well in short the question is: how can I make a text to speech and save it in an audio file with python 2.7... – DIDoS Nov 17 '11 at 18:33
  • @ele, this seems like a duplicate of this question: http://stackoverflow.com/questions/1614059/how-tomake-python-speak. Does the answer to that question answer your question? – Yann Nov 17 '11 at 20:06
  • Thanks for the link.. As I mentioned above I already tried pyttsx and pytts (like mentioned in your link) but i can't figure out how to save it to wav under Python 2.7 - either it does not work under python 2.7 at all (pytts) or it cant save it to a file (pyttsx) – DIDoS Nov 17 '11 at 20:13
  • 1
    maybe this can help you http://stackoverflow.com/questions/892199/detect-record-audio-in-python – Facundo Casco Nov 17 '11 at 20:18
  • @F.C. Thanks for the link... He is recording from microphone. I tried to make it record from my python app but it didnt work... – DIDoS Nov 21 '11 at 12:19
  • Did you find any solution for this problem? – w2lame Dec 13 '12 at 17:35

2 Answers2

0

How to create audio from text with google text to speech API

First install gtts from cmd pip install gtts

from gtts import gTTS

tts = gTTS("Hello","en")
tts.save("hello.mp3")

and you're done.

Community
  • 1
  • 1
PythonProgrammi
  • 22,305
  • 3
  • 41
  • 34
0

Your question implies it's ok if this is a Mac OS X only solution? If so, then you can modify the Mac OS X driver in pyttsx (pyttsx/drivers/nsss.py) and give it the ability to call the startSpeakingString:toURL: method on the NSSpeechSynthesizer class:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSpeechSynthesizer_Class/Reference/Reference.html

This will save synthesized text to a file.

David K. Hess
  • 16,632
  • 2
  • 49
  • 73