From a7af1d2a9289191e017d145687e8c973fad1ea42 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Fri, 14 Dec 2012 18:48:34 +0000 Subject: Clock goes back to the speaking-mode SL #4079 This PATCH is just a workaround to the real problem: Clock is using gst 0.11 but we have installed the 'espeak' plugin for Gst 1.0 because we need that version for the shell itself. So, Clock does not find the proper plugin and tries to use the 'espeak' command directily but it fails as well because a 'portaudio' lib issue. This PATCH makes 'espeak' to create a WAV file in a temporary file and then plays it with the command 'playwave'. It's the same idea used in Speak, with the difference than Speak uses gstreamer to play the wav file. This workaround will not be necessary when Clock uses Gtk3 and Gst 1.0. Signed-off-by: Manuel Kaufmann --- diff --git a/speaker.py b/speaker.py index f33dbad..1963747 100755 --- a/speaker.py +++ b/speaker.py @@ -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() -- cgit v0.9.1