1

Am currently working on a project that uses Festival TTS engine on the RPi.

Have used it plenty before. I have also used pyfestival to do basic stuff. I am currently trying to generate the viseme file for a piece of text. This works perfectly if done in the Festival command interpreter, I need to do the exact same but in bash or python.

festival> (set! mytext (SayText "Hello word")) festival> (utt.save.segs mytext "hw_viseme_file")

Have searched high and low for this info but have drawn a blank. Can someone give an example of how the 2 lines of code above can be called from either bash or Python?

Many thanks.

DP.

Ren
  • 2,852
  • 2
  • 23
  • 45

2 Answers2

0

The festival command has a --script option, so you should be able to run from bash something like:

festival --script generate_visemes

Where 'generate-visemes' contains the Festival commands (above) that you want to execute.

From python you can call an external program like this:

os.system("festival --script generate_visemes")

Perhaps to create the script file, something like this:

import os

ttsMessage = "Hello World"
ttsVisemeFile = "hw_viseme_file"

f = open('generate_visemes','w')
textParam = '(set! mytext(SayText "{0}"))\n'.format(ttsMessage)
visemeParam = '(utt.save.segs mytext "{0}")\n'.format(ttsVisemeFile)

f.write(textParam)
f.write(visemeParam)
f.close()

os.execute("festival --script generate_visemes")
TheMagicCow
  • 396
  • 1
  • 10
  • Hi, thanks for reply. I know about the --script option, the problem is with how the parameters are actually passed - the 'generate_visemes' part. The lines of code are what is entered into the Festival interpreter, they are in Scheme / Lisp. I unfortunately have no idea how to translate that into something that can be passed as a parameter :( I have tried basically every variation that I can think of but just get an error. – David Pride Mar 27 '16 at 10:45
  • Hi again, thanks for trying to help but I think you mis-understand the question slightly. The code you post above will generate a text file containing the parameters, this is not what is required sorry. – David Pride Mar 27 '16 at 12:02
  • Please ignore last comment. Bloody thing timed out!. Hi again, thanks for trying to help! The code you posted above will generate a text file containing the parameters, if this is then passed to festival via --script I get the same error (SIOD Unbound Variable SayText) that I get if I do same thing from command line. This (and many variations I have tried) is not correct.... festival --script (utt.save.segs mytext "hw_viseme_file") What I am trying to do is get Festival to perform exactly that operation, but from bash / Python but I am beginning to wonder if it's actually possible. – David Pride Mar 27 '16 at 12:11
0

Finally worked this out - is fairly involved. The following runs in Python 2.7 on RPi when Festival TTS engine is installed.

    import os

    #Simple example
    bashcommand = "echo 'Hello World' | festival --tts"
    os.system(bashcommand)

    # This bash command takes the entered phrase and returns an audio .wav file and a text file of the visemes

    while True:
        phrase = raw_input("Enter phrase:")  

        bashcommand = "festival -b '(set! mytext (Utterance Text " + '"' + phrase + '"))' + "' '(utt.synth mytext)' '(utt.save.wave mytext " + '"my_wav.wav")' + "' '(utt.save.segs mytext " + '"textfile"' + ")'"

        os.system(bashcommand)

You can of course also just run the bash from the command line. Hope that may help someone in the future.