Python Bindings for CMU Flite

Flite is really useful for more than just speech synthesis - it's also very useful for text normalization and other things like that. Since I'm working on some [:EmailScraper:Text normalization code] that happens to be in Python, I figured I would write some Flite bindings.

These are not totally complete but I've attached them here anyway: attachment:flitemodule.c

It should be possible to compile this against any version of flite, but the mechanism for doing so will vary depending on where exactly your engine and voice libraries got installed.

Actually if [http://www.cepstral.com/ Swift] still supports the Flite API, it should also be possible to compile it against that. But I'm not sure about that.

This is done with the "raw" Python-C API, because I wanted to learn it, but in the future it will probably use SWIG.

Here is a really quick example of what can be done with them:

import flite
v = flite.load_voice()
v.text_to_speech("Hello world!") # Says "hello world"
v.text_to_speech("Hello world!", "foo.wav") # Writes audio for "hello world" to foo.wav
v.file_to_speech("/etc/passwd") # Speaks the password file
v.file_to_speech("/etc/passwd", "foo.wav") # Speaks the password file to foo.wav
u = flite.synth_text("Hello world!") # Get an utterance object for "Hello world!"
for i in u['Segment']: # Iterate over the Segment relation (phones)
    print "%s: %f" % (i['name'], i['end']) # Print out phone names and end times
for w in u['Word']: # Iterate over the Word relation
    print w.name
    for s in w.as_rel('SylStructure'): # Iterate over syllables
        for p in s: # Iterate over phones in each syllable
            print "%s: %f" % (i['name'], i['end'])

DHDWiki: PyFlite (last edited 2007-11-17 03:22:10 by DavidHugginsDaines)