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.

Sat, 20 Jun 2009 23:25

Comments: 0

Reader Comments

Add a Comment

  • Only the name field is mandatory. It's hard to keep track of a conversations where everyone is Anonymous.
  • If you choose to leave an email address, it will not be shown on the page.
  • A limited subset of HTML is allowed in your comment.

Name

Email

URL


Comment: (Limited HTML allowed.)