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

[PATCH] Improve performance of servers/espeak.



Calling the espeak library to set speech parameters seems to be an
expensive operation.  This patch guarantees that we only call
espeak_SetParameter to update parameters which have *actually* changed.
E.G., the call
tts_set_punctuations all
should be a no-op when the punctuation mode is already "all".
---
 servers/linux-espeak/tclespeak.cpp |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/servers/linux-espeak/tclespeak.cpp b/servers/linux-espeak/tclespeak.cpp
index a4e0b70..14bc3db 100644
--- a/servers/linux-espeak/tclespeak.cpp
+++ b/servers/linux-espeak/tclespeak.cpp
@@ -216,7 +216,9 @@ int
 SetRate (ClientData handle, Tcl_Interp * interp,
 	 int objc, Tcl_Obj * CONST objv[])
 {
+  static int current_rate = -1;
   int rc, rate, voice;
+  int success = 1;
   if (objc != 3)
     {
       Tcl_AppendResult (interp, "Usage: setRate voiceCode speechRate ",
@@ -230,7 +232,13 @@ SetRate (ClientData handle, Tcl_Interp * interp,
   if (rc != TCL_OK)
     return rc;
 
-  return (espeak_SetParameter(espeakRATE, rate, 0) == EE_OK) ? TCL_OK : TCL_ERROR;
+  if (rate != current_rate)
+    {
+      success =  (espeak_SetParameter(espeakRATE, rate, 0) == EE_OK);
+      if (success)
+        current_rate = rate;
+    }
+  return success ? TCL_OK : TCL_ERROR;
 }
 
 //>
@@ -447,22 +455,31 @@ int
 Caps (ClientData handle,
       Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
 {
+  static const char *current_mode = "";
   char* a_mode = (char*)Tcl_GetStringFromObj (objv[1], NULL);
-  if (a_mode)
+  if (a_mode && strcmp(a_mode, current_mode))
     {
       int a_type = 0; // none
   
       if (strcmp(a_mode,"tone") == 0)
 	{
 	  a_type = 1;
+	  current_mode = "tone";
 	}
       else if (strcmp(a_mode,"spelling") == 0)
 	{
 	  a_type = 2;
+	  current_mode = "spelling";
 	}
       else if (strcmp(a_mode,"pitch") == 0)
 	{
 	  a_type = 30;
+	  current_mode = "pitch";
+	}
+      else if (strcmp(a_mode, "none") == 0)
+	{
+	    current_mode = "none";
+	    // a_type is already 0 (none).  No need to assign.
 	}
 
       espeak_SetParameter(espeakCAPITALS, a_type, 0);
@@ -478,21 +495,25 @@ Punct (ClientData handle,
        Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[])
 {
   char* a_mode = (char*)Tcl_GetStringFromObj (objv[1], NULL);
-  if (a_mode)
+  static const char *current_mode = "";
+  if (a_mode && strcmp(a_mode, current_mode))
     {
       espeak_PUNCT_TYPE a_type = espeakPUNCT_NONE;
   
       if (strcmp(a_mode,"none")==0)
 	{
 	  a_type = espeakPUNCT_NONE;
+	  current_mode = "none";
 	}
       else if (strcmp(a_mode,"all")==0)
 	{
 	  a_type = espeakPUNCT_ALL;
+	  current_mode = "all";
 	}
       else if (strcmp(a_mode,"some")==0)
 	{
 	  a_type = espeakPUNCT_SOME;
+	  current_mode = "some";
 	}
 
       espeak_SetParameter(espeakPUNCTUATION, a_type, 0);
-- 
1.7.3.2

-----------------------------------------------------------------------------
To unsubscribe from the emacspeak list or change your address on the
emacspeak list send mail to "emacspeak-request@cs.vassar.edu" with a
subject of "unsubscribe" or "help".



If you have questions about this archive or had problems using it, please send mail to:

priestdo@cs.vassar.edu No Soliciting!

Emacspeak List Archive | 2010 | 2009 | 2008 | 2007 | 2006 | 2005 | 2004 | 2003 | 2002 | 2001 | 2000 | 1999 | 1998 | Pre 1998

Emacspeak Files | Emacspeak Blog | Search the archive