Quick and Dirty Text-to-Speech in Python
I looked around for some python bindings for Festival, but neither pyfestival nor pyfest seem to be maintained. I was too tired to use swig or similar to wrap the C++ library. Instead, I wrote a thin shim between python and the Scheme-based command interpreter. (You must have festival installed.)
import os
BIN="/usr/bin/festival"
class Festival(object):
def __init__(self):
self.p = os.popen("%s --pipe" % BIN, "w")
def eval(self, scm):
self.p.write(scm + "\n")
self.p.flush()
def say(self, text):
text = text.replace('"', '')
self.eval('(SayText "%s")' % str(text))
Import the module, instantiate a Festival object, and call its "say" method to create utterances.
>>> import festival
>>> tts = festival.Festival()
>>> tts.say("Hello, world.")
It's quick. It's dirty. It works.
Comments: 0