From 163859a05104eeb5f4ddf2131688d698c79ce4a2 Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Fri, 14 Dec 2012 15:48:34 -0300
Subject: [PATCH clock] 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 <humitos@gmail.com>
---
speaker.py | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/speaker.py b/speaker.py
index f33dbad..1963747 100755
a
|
b
|
Controls the espeak program available on the OLPC XO laptop. |
14 | 14 | |
15 | 15 | import sys |
16 | 16 | import os |
| 17 | import tempfile |
17 | 18 | |
18 | 19 | from gettext import gettext as _ |
19 | 20 | |
… |
… |
class Speaker: |
51 | 52 | # http://espeak.sourceforge.net/languages.html to see if your language is supported. |
52 | 53 | VOICE = _("en") |
53 | 54 | |
| 55 | # Temporary file to save the 'espeak -w' output and then play it |
| 56 | # with 'playwave' command |
| 57 | WAV_TEMP_FILE = tempfile.mktemp() |
| 58 | |
| 59 | # 'espeak' command to generate the wav file to be played with 'playwave' |
| 60 | ESPEAK_COMMAND = 'espeak -p%s -s%s -g%s -v%s "%s" -w %s' |
| 61 | |
| 62 | # 'playwave' command that plays the wav generated by 'espeak' |
| 63 | PLAYWAVE_COMMAND = 'playwave %s' % WAV_TEMP_FILE |
54 | 64 | |
55 | 65 | def speak(self, text): |
56 | 66 | """Speaks aloud the given text. |
57 | 67 | """ |
58 | 68 | text = text.replace("\"", "\\\"") |
59 | | child = os.popen("espeak -p%s -s%s -g%s -v%s \"%s\"" % (Speaker.PITCH, Speaker.SPEED, Speaker.WORD_GAP, Speaker.VOICE, text)) |
| 69 | child = os.popen(Speaker.ESPEAK_COMMAND % ( |
| 70 | Speaker.PITCH, Speaker.SPEED, Speaker.WORD_GAP, Speaker.VOICE, |
| 71 | text, Speaker.WAV_TEMP_FILE)) |
| 72 | data = child.read() |
| 73 | child.close() |
| 74 | |
| 75 | # This is a workaround for SL #4079 |
| 76 | child = os.popen(Speaker.PLAYWAVE_COMMAND) |
60 | 77 | data = child.read() |
61 | 78 | child.close() |
62 | 79 | |