[Nvda-dev] commit r2707 - in trunk: . source/synthDrivers

NVDA Subversion svn at nvda-project.org
Thu Feb 5 15:28:08 UTC 2009


Author: nvda
Date: Thu Feb  5 15:28:06 2009
New Revision: 2707

Log:
sapi5 synth driver: Optimisation and cleanup:
	* Move the code which initialises the tts object and sets the audio output from _set_voice() into a new function called _initTts().
	* __init__(): The tts object is already initialised with the default voice, so there's no need to call tts.getVoices() and use the voice property (which scans the list again). Instead, just call _initTts().
	* Don't bother caching the voice ID, as it is quick enough to retrieve this from the tts object.


Modified:
   trunk/   (props changed)
   trunk/source/synthDrivers/sapi5.py

Modified: trunk/source/synthDrivers/sapi5.py
==============================================================================
--- trunk/source/synthDrivers/sapi5.py	(original)
+++ trunk/source/synthDrivers/sapi5.py	Thu Feb  5 15:28:06 2009
@@ -40,10 +40,8 @@
 			return False
 
 	def __init__(self):
-		self.tts = comtypes.client.CreateObject(COM_CLASS)
 		self._pitch=50
-		self.voice=self.tts.GetVoices()[0].Id
-
+		self._initTts()
 
 	def terminate(self):
 		del self.tts
@@ -66,7 +64,7 @@
 		return self.tts.volume
 
 	def _get_voice(self):
-		return self._voice
+		return self.tts.voice.Id
  
 	def _get_lastIndex(self):
 		bookmark=self.tts.status.LastBookmark
@@ -85,16 +83,21 @@
 	def _set_volume(self,value):
 		self.tts.Volume = value
 
+	def _initTts(self):
+		self.tts=comtypes.client.CreateObject(COM_CLASS)
+		outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True)
+		if outputDeviceID>=0:
+			self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID]
+
 	def _set_voice(self,value):
 		for v in self.tts.GetVoices():
 			if value==v.Id:
-				self.tts=comtypes.client.CreateObject('sapi.spVoice')
-				outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True)
-				if outputDeviceID>=0:
-					self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID]
-				self.tts.voice=v
-				self._voice=value
 				break
+		else:
+			# Voice not found.
+			return
+		self._initTts()
+		self.tts.voice=v
 
 	def speakText(self,text,index=None):
 		flags=constants.SVSFIsXML



More information about the Nvda-dev mailing list