[orca: 1/2] speech: add progress marking support



commit 30286b2c5edff0fafec90add3c3c7969915cd981
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Fri Jul 6 13:20:58 2018 +0200

    speech: add progress marking support
    
    This introduces marks in the text sent to speech-dispatcher so that
    speech modules which support indexing provide progress feedback. Scripts
    can then use it from __sayAllProgressCallback to show the progression.

 src/orca/speechdispatcherfactory.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/src/orca/speechdispatcherfactory.py b/src/orca/speechdispatcherfactory.py
index 70c95eb1e..4bfc1356e 100644
--- a/src/orca/speechdispatcherfactory.py
+++ b/src/orca/speechdispatcherfactory.py
@@ -148,7 +148,7 @@ class SpeechServer(speechserver.SpeechServer):
             speechd.CallbackType.BEGIN: speechserver.SayAllContext.PROGRESS,
             speechd.CallbackType.CANCEL: speechserver.SayAllContext.INTERRUPTED,
             speechd.CallbackType.END: speechserver.SayAllContext.COMPLETED,
-           #speechd.CallbackType.INDEX_MARK:speechserver.SayAllContext.PROGRESS,
+            speechd.CallbackType.INDEX_MARK:speechserver.SayAllContext.PROGRESS,
             }
 
         self._default_voice_name = guilabels.SPEECH_DEFAULT_VOICE % serverId
@@ -172,6 +172,7 @@ class SpeechServer(speechserver.SpeechServer):
         self._current_voice_properties = {}
         mode = self._PUNCTUATION_MODE_MAP[settings.verbalizePunctuationStyle]
         client.set_punctuation(mode)
+        client.set_data_mode(speechd.DataMode.SSML)
 
     def updateCapitalizationStyle(self):
         """Updates the capitalization style used by the speech server."""
@@ -343,6 +344,15 @@ class SpeechServer(speechserver.SpeechServer):
     def _speak(self, text, acss, **kwargs):
         if isinstance(text, ACSS):
             text = ''
+
+        # Mark words to get speech progression feedback.
+        # Note: we need to do it before disturbing the text offsets
+        markedtext = ""
+        for i in range(len(text)):
+            markedtext += text[i]
+            if text[i] == ' ' or text[i] == '\u00a0':
+                markedtext += '<mark name="%u"/>' % (i+1)
+
         text = self.__addVerbalizedPunctuation(text)
         if orca_state.activeScript:
             text = orca_state.activeScript.\
@@ -359,8 +369,8 @@ class SpeechServer(speechserver.SpeechServer):
         text = text.replace('\n.', '\n')
 
         self._apply_acss(acss)
-        self._debug_sd_values("Speaking '%s' " % text)
-        self._send_command(self._client.speak, text, **kwargs)
+        self._debug_sd_values("Speaking '%s' " % markedtext)
+        self._send_command(self._client.speak, markedtext, **kwargs)
 
     def _say_all(self, iterator, orca_callback):
         """Process another sayAll chunk.


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