Ticket #4079: 0001-Clock-goes-back-to-the-speaking-mode-SL-4079.patch

File 0001-Clock-goes-back-to-the-speaking-mode-SL-4079.patch, 2.4 KB (added by humitos, 11 years ago)

A workaround to the real problem - no needed in Gtk3 and Gst 1.0 versions

  • speaker.py

    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. 
    1414
    1515import sys
    1616import os
     17import tempfile
    1718
    1819from gettext import gettext as _
    1920
    class Speaker: 
    5152    # http://espeak.sourceforge.net/languages.html to see if your language is supported.
    5253    VOICE = _("en")
    5354
     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
    5464
    5565    def speak(self, text):
    5666        """Speaks aloud the given text.
    5767        """
    5868        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)
    6077        data = child.read()
    6178        child.close()
    6279