[orca] Latent work for bgo#400729 - Orca should provide support for general audio



commit cdac8aa9572686bf0fdd373a2ed63268daa5b29f
Author: Willie Walker <william walker sun com>
Date:   Fri Jul 10 07:21:02 2009 -0400

    Latent work for bgo#400729 - Orca should provide support for general audio
    
    This adds some latent support for audio that gives people something to
    experiment with.  The goal is to let heavy audio users provide us with
    feedback for how we can better integrate audio cues into Orca.

 src/orca/Makefile.am         |    1 +
 src/orca/settings.py         |   11 +++++++
 src/orca/sound.py            |   63 ++++++++++++++++++++++++++++++++++++++++++
 src/orca/speech.py           |   12 ++++++-
 src/orca/speech_generator.py |   17 +++++++++++
 5 files changed, 102 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/Makefile.am b/src/orca/Makefile.am
index e1266af..01eb05a 100644
--- a/src/orca/Makefile.am
+++ b/src/orca/Makefile.am
@@ -55,6 +55,7 @@ orca_python_PYTHON = \
 	rolenames.py \
 	script.py \
 	settings.py \
+	sound.py \
 	speech.py \
 	speechdispatcherfactory.py \
 	speech_generator.py \
diff --git a/src/orca/settings.py b/src/orca/settings.py
index fbd2816..f930902 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -1202,6 +1202,17 @@ presentRequiredState = False
 
 ########################################################################
 #                                                                      #
+# Sounds                                                               #
+#                                                                      #
+########################################################################
+
+# A dictionary where the keys are rolenames and the values are
+# filenames containing audio snippets.
+#
+sounds = {}
+
+########################################################################
+#                                                                      #
 # Strings for speech and braille                                       #
 #                                                                      #
 ########################################################################
diff --git a/src/orca/sound.py b/src/orca/sound.py
new file mode 100644
index 0000000..5215321
--- /dev/null
+++ b/src/orca/sound.py
@@ -0,0 +1,63 @@
+# Orca
+#
+# Copyright 2009 Sun Microsystems Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
+# Boston MA  02110-1301 USA.
+
+"""Provides support for playing audio files."""
+
+__id__        = "$Id$"
+__version__   = "$Revision$"
+__date__      = "$Date$"
+__copyright__ = "Copyright (c) 2009 Sun Microsystems Inc."
+__license__   = "LGPL"
+
+import pygst
+pygst.require("0.10")
+import gst
+
+class Sound:
+    """Class to hold a path to a sound file to play."""
+    def __init__(self, path):
+        self._path = path
+
+    def play(self):
+        if False:
+            # WDW - this plays audio once, but then never plays it again.
+            #
+            pipe = gst.parse_launch(
+                "filesrc location=%s ! wavparse ! autoaudiosink" % self._path)
+            pipe.set_state(gst.STATE_PLAYING)
+        elif True:
+            import os
+            os.system(
+                'gst-launch filesrc location="%s" ! wavparse '\
+                '! autoaudiosink > /dev/null 2>&1 &'\
+                % self._path)
+        else:
+            # WDW - This has issues with linking up the pipeline. It
+            # doesn't work.
+            #
+            player = gst.Pipeline("OrcaPlayer")
+            source = gst.element_factory_make("filesrc", "file-source")
+            decoder = gst.element_factory_make("wavparse", "wav-decoder")
+            sink = gst.element_factory_make("autoaudiosink", "audio-sink")
+            print source, decoder, sink
+            player.add(source, decoder, sink)
+            gst.element_link_many(source, decoder, sink)
+            player.get_by_name("file-source").set_property(
+                "location", self._path)
+            player.set_state(gst.STATE_PLAYING)
diff --git a/src/orca/speech.py b/src/orca/speech.py
index 4a84542..5e189eb 100644
--- a/src/orca/speech.py
+++ b/src/orca/speech.py
@@ -1,6 +1,6 @@
 # Orca
 #
-# Copyright 2004-2008 Sun Microsystems Inc.
+# Copyright 2004-2009 Sun Microsystems Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -23,7 +23,7 @@ as its speech server, or it can feel free to create one of its own."""
 __id__        = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import logging
@@ -38,6 +38,7 @@ import keynames
 import orca
 import orca_state
 import settings
+import sound
 import speech_generator
 
 from acss import ACSS
@@ -197,6 +198,11 @@ def speak(content, acss=None, interrupt=True):
                 if subString:
                     _speak(subString, acss, interrupt)
                     subString = None
+            elif isinstance(element, sound.Sound):
+                if subString:
+                    _speak(subString, acss, interrupt)
+                    subString = None
+                element.play()
             else:
                 if subString:
                     _speak(subString, acss, interrupt)
@@ -209,6 +215,8 @@ def speak(content, acss=None, interrupt=True):
                 else:
                     debug.println(debug.LEVEL_WARNING,
                                   "UNKNOWN speech element: '%s'" % element)
+    elif isinstance(content, sound.Sound):
+        content.play()
     elif isinstance(content, (speech_generator.Pause,
                               speech_generator.LineBreak)):
         pass
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 3ff75f2..f49394c 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -32,6 +32,7 @@ import orca_state
 import pyatspi
 import rolenames
 import settings
+import sound
 import text_attribute_names
 
 from orca_i18n import _         # for gettext support
@@ -79,6 +80,22 @@ class SpeechGenerator(generator.Generator):
         """
         generator.Generator._addGlobals(self, globalsDict)
         globalsDict['voice'] = self.voice
+        globalsDict['play'] = self.play
+
+    def play(self, key):
+        """Returns an array containing a sound.Sound instance.
+        The key can a value to be used to look up a filename in the
+        settings.py:sounds dictionary (e.g., a pyatspi.ROLE_* value)
+        or just the name of an audio file to use.
+        """
+        try:
+            soundBite = sound.Sound(settings.sounds[key])
+        except:
+            if isinstance(key, basestring):
+                soundBite = sound.Sound(key)
+            else:
+                soundBite = None
+        return [soundBite]
 
     def generateSpeech(self, obj, **args):
         return self.generate(obj, **args)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]