diff options
-rwxr-xr-x | speaker.py | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -14,6 +14,7 @@ Controls the espeak program available on the OLPC XO laptop. import sys import os +import tempfile from gettext import gettext as _ @@ -51,12 +52,28 @@ class Speaker: # http://espeak.sourceforge.net/languages.html to see if your language is supported. VOICE = _("en") + # Temporary file to save the 'espeak -w' output and then play it + # with 'playwave' command + WAV_TEMP_FILE = tempfile.mktemp() + + # 'espeak' command to generate the wav file to be played with 'playwave' + ESPEAK_COMMAND = 'espeak -p%s -s%s -g%s -v%s "%s" -w %s' + + # 'playwave' command that plays the wav generated by 'espeak' + PLAYWAVE_COMMAND = 'playwave %s' % WAV_TEMP_FILE def speak(self, text): """Speaks aloud the given text. """ text = text.replace("\"", "\\\"") - child = os.popen("espeak -p%s -s%s -g%s -v%s \"%s\"" % (Speaker.PITCH, Speaker.SPEED, Speaker.WORD_GAP, Speaker.VOICE, text)) + child = os.popen(Speaker.ESPEAK_COMMAND % ( + Speaker.PITCH, Speaker.SPEED, Speaker.WORD_GAP, Speaker.VOICE, + text, Speaker.WAV_TEMP_FILE)) + data = child.read() + child.close() + + # This is a workaround for SL #4079 + child = os.popen(Speaker.PLAYWAVE_COMMAND) data = child.read() child.close() |