Esempio n. 1
0
	def script_saveSynth(self, gesture):
		if self.slot not in self.synths:
			self.synths[self.slot] = {}
		self.synths[self.slot]['name'] = speech.getSynth().name
		self.synths[self.slot]['config'] = dict(config.conf['speech'][speech.getSynth().name].iteritems())
		self.write()
		ui.message(_("saved"))
Esempio n. 2
0
 def script_saveSynth(self, gesture):
     if self.slot not in self.synths:
         self.synths[self.slot] = {}
     self.synths[self.slot]['name'] = speech.getSynth().name
     self.synths[self.slot]['config'] = dict(
         config.conf['speech'][speech.getSynth().name].items())
     self.write()
     ui.message(_("saved"))
Esempio n. 3
0
	def script_setSynth(self, gesture):
		self.slot = slot = int(gesture.displayName[-1])
		if slot in self.synths:
			config.conf.profiles[0]['speech'][self.synths[slot]['name']].clear()
			config.conf.profiles[0]['speech'][self.synths[slot]['name']].update(self.synths[slot]['config'])
			config.conf['speech'][self.synths[slot]['name']]._cache.clear()
			speech.setSynth(self.synths[slot]['name'])
		speech.getSynth().saveSettings()
		ui.message(str(slot))
Esempio n. 4
0
 def script_setSynth(self, gesture):
     self.slot = slot = int(gesture.displayName[-1])
     if slot in self.synths:
         config.conf.profiles[0]['speech'][self.synths[slot]
                                           ['name']].clear()
         config.conf.profiles[0]['speech'][
             self.synths[slot]['name']].update(self.synths[slot]['config'])
         config.conf['speech'][self.synths[slot]['name']]._cache.clear()
         speech.setSynth(self.synths[slot]['name'])
     speech.getSynth().saveSettings()
     ui.message(str(slot))
Esempio n. 5
0
def _processMpSpeech(text, language):
	# MathPlayer's default rate is 180 wpm.
	# Assume that 0% is 80 wpm and 100% is 450 wpm and scale accordingly.
	synth = speech.getSynth()
	wpm = synth._percentToParam(synth.rate, 80, 450)
	breakMulti = 180.0 / wpm
	out = []
	if language:
		out.append(speech.LangChangeCommand(language))
	resetProsody = set()
	for m in RE_MP_SPEECH.finditer(text):
		if m.lastgroup == "break":
			out.append(speech.BreakCommand(time=int(m.group("break")) * breakMulti))
		elif m.lastgroup == "char":
			out.extend((speech.CharacterModeCommand(True),
				m.group("char"), speech.CharacterModeCommand(False)))
		elif m.lastgroup == "comma":
			out.append(speech.BreakCommand(time=100))
		elif m.lastgroup in PROSODY_COMMANDS:
			command = PROSODY_COMMANDS[m.lastgroup]
			out.append(command(multiplier=int(m.group(m.lastgroup)) / 100.0))
			resetProsody.add(command)
		elif m.lastgroup == "prosodyReset":
			for command in resetProsody:
				out.append(command(multiplier=1))
			resetProsody.clear()
		elif m.lastgroup == "phonemeText":
			out.append(speech.PhonemeCommand(m.group("ipa"),
				text=m.group("phonemeText")))
		elif m.lastgroup == "content":
			out.append(m.group(0))
	if language:
		out.append(speech.LangChangeCommand(None))
	return out
def compute_volume(volume=0):
    if getCfgVal("useSynthVolume") or not volume:
        driver = speech.getSynth()
        volume = getattr(driver, 'volume', 100)
    volume = volume / 100.0  #nvda reports as percent.
    volume = clamp(volume, 0.0, 1.0)
    return volume
Esempio n. 7
0
	def _compute_volume(self):
		if not config.conf["unspoken"]["volumeAdjust"]:
			return 1.0
		driver=speech.getSynth()
		volume = getattr(driver, 'volume', 100)/100.0 #nvda reports as percent.
		volume=clamp(volume, 0.0, 1.0)
		print volume
		return volume
Esempio n. 8
0
 def _compute_volume(self):
     if not self.use_synth_volume:
         return clamp(self.volume / 100, 0.0, 1.0)
     driver = speech.getSynth()
     volume = getattr(driver, "volume",
                      100) / 100.0  # nvda reports as percent.
     volume = clamp(volume, 0.0, 1.0)
     return volume
Esempio n. 9
0
def checkForUpdate(auto=False):
	"""Check for an updated version of NVDA.
	This will block, so it generally shouldn't be called from the main thread.
	@param auto: Whether this is an automatic check for updates.
	@type auto: bool
	@return: Information about the update or C{None} if there is no update.
	@rtype: dict
	@raise RuntimeError: If there is an error checking for an update.
	"""
	allowUsageStats=config.conf["update"]['allowUsageStats']
	params = {
		"autoCheck": auto,
		"allowUsageStats":allowUsageStats,
		"version": versionInfo.version,
		"versionType": versionInfo.updateVersionType,
		"osVersion": winVersion.winVersionText,
		"x64": os.environ.get("PROCESSOR_ARCHITEW6432") == "AMD64",
	}
	if auto and allowUsageStats:
		synthDriverClass=speech.getSynth().__class__
		brailleDisplayClass=braille.handler.display.__class__ if braille.handler else None
		# Following are parameters sent purely for stats gathering.
		#  If new parameters are added here, they must be documented in the userGuide for transparency.
		extraParams={
			"language": languageHandler.getLanguage(),
			"installed": config.isInstalledCopy(),
			"synthDriver":getQualifiedDriverClassNameForStats(synthDriverClass) if synthDriverClass else None,
			"brailleDisplay":getQualifiedDriverClassNameForStats(brailleDisplayClass) if brailleDisplayClass else None,
			"outputBrailleTable":config.conf['braille']['translationTable'] if brailleDisplayClass else None,
		}
		params.update(extraParams)
	url = "%s?%s" % (CHECK_URL, urllib.urlencode(params))
	try:
		res = urllib.urlopen(url)
	except IOError as e:
		if isinstance(e.strerror, ssl.SSLError) and e.strerror.reason == "CERTIFICATE_VERIFY_FAILED":
			# #4803: Windows fetches trusted root certificates on demand.
			# Python doesn't trigger this fetch (PythonIssue:20916), so try it ourselves
			_updateWindowsRootCertificates()
			# and then retry the update check.
			res = urllib.urlopen(url)
		else:
			raise
	if res.code != 200:
		raise RuntimeError("Checking for update failed with code %d" % res.code)
	info = {}
	for line in res:
		line = line.rstrip()
		try:
			key, val = line.split(": ", 1)
		except ValueError:
			raise RuntimeError("Error in update check output")
		info[key] = val
	if not info:
		return None
	return info
Esempio n. 10
0
def checkForUpdate(auto=False):
	"""Check for an updated version of NVDA.
	This will block, so it generally shouldn't be called from the main thread.
	@param auto: Whether this is an automatic check for updates.
	@type auto: bool
	@return: Information about the update or C{None} if there is no update.
	@rtype: dict
	@raise RuntimeError: If there is an error checking for an update.
	"""
	allowUsageStats=config.conf["update"]['allowUsageStats']
	params = {
		"autoCheck": auto,
		"allowUsageStats":allowUsageStats,
		"version": versionInfo.version,
		"versionType": versionInfo.updateVersionType,
		"osVersion": winVersion.winVersionText,
		"x64": os.environ.get("PROCESSOR_ARCHITEW6432") == "AMD64",
	}
	if auto and allowUsageStats:
		synthDriverClass=speech.getSynth().__class__
		brailleDisplayClass=braille.handler.display.__class__ if braille.handler else None
		# Following are parameters sent purely for stats gathering.
		#  If new parameters are added here, they must be documented in the userGuide for transparency.
		extraParams={
			"language": languageHandler.getLanguage(),
			"installed": config.isInstalledCopy(),
			"synthDriver":getQualifiedDriverClassNameForStats(synthDriverClass) if synthDriverClass else None,
			"brailleDisplay":getQualifiedDriverClassNameForStats(brailleDisplayClass) if brailleDisplayClass else None,
			"outputBrailleTable":config.conf['braille']['translationTable'] if brailleDisplayClass else None,
		}
		params.update(extraParams)
	url = "%s?%s" % (CHECK_URL, urllib.urlencode(params))
	try:
		res = urllib.urlopen(url)
	except IOError as e:
		if isinstance(e.strerror, ssl.SSLError) and e.strerror.reason == "CERTIFICATE_VERIFY_FAILED":
			# #4803: Windows fetches trusted root certificates on demand.
			# Python doesn't trigger this fetch (PythonIssue:20916), so try it ourselves
			_updateWindowsRootCertificates()
			# and then retry the update check.
			res = urllib.urlopen(url)
		else:
			raise
	if res.code != 200:
		raise RuntimeError("Checking for update failed with code %d" % res.code)
	info = {}
	for line in res:
		line = line.rstrip()
		try:
			key, val = line.split(": ", 1)
		except ValueError:
			raise RuntimeError("Error in update check output")
		info[key] = val
	if not info:
		return None
	return info
Esempio n. 11
0
	def send_indexes(self):
		last = None
		POLL_TIME = 0.05
		while self.transport.connected:
			synth = speech.getSynth()
			if synth is None: #While switching synths
				time.sleep(POLL_TIME)
				continue
			index = synth.lastIndex
			if index != last:
				self.transport.send(type="index", index=index)
				last = index
			time.sleep(POLL_TIME)
Esempio n. 12
0
	def _reportIndentChange(self, text):
		""" Reports the current level change as a tone. The first twenty levels are given distinct stereo positions, and otherwise, no tone will play.
		@var text: The text to report indents for. Only pass a homoginous set of tabs or spaces, because the length is calculated assuming each character is one indent unit.
		@type text: string
		@returns: Indent level.
		"""
		level = len(text) #assume 1 indent unit per character.
		if level > MAX_LEVEL:
			return level
		volume = speech.getSynth().volume
		note = 128*2**(level/MAX_LEVEL*3) #MAX_LEVEL*3 gives us 3 octaves of whole tones.
		#calculate stereo values. NVDA expects  values between 0 and 100 for stereo volume for each channel.
		right = int((volume/(MAX_LEVEL-1))*level)
		left = volume-right
		tones.beep(note, 80, left=left, right=right)
		return level
Esempio n. 13
0
	def unpatch_synth(self):
		if self.orig_speak is None:
			return
		synth = speech.getSynth()
		synth.speak = self.orig_speak
		self.orig_speak = None
		synth.cancel = self.orig_cancel
		self.orig_cancel = None
		if synth.__class__.name == 'silence':
			synth.__class__.lastIndex = self.orig_get_lastIndex
		else:
			synth.__class__.lastIndex.fget = self.orig_get_lastIndex
			self.orig_get_lastIndex = None
		synthDriverHandler.setSynth = self.orig_setSynth
		speech.setSynth = self.orig_setSynth
		gui.settingsDialogs.setSynth = self.orig_setSynth
		self.orig_setSynth = None
Esempio n. 14
0
	def _reportIndentChange(self,  level):
		""" Reports the current level change as a tone. The first twenty levels are given distinct stereo positions, and otherwise, no tone will play.
		@var level: The level to report indents for. Only pass a homoginous set of tabs or spaces, because the length is calculated assuming each character is one indent unit.
		@type level: int
		"""
		volume = speech.getSynth().volume
		if config.conf["indentone"]["toneType"] & PITCH:
			note = 128*2**(level/MAX_LEVEL*3) #MAX_LEVEL*3 gives us 3 octaves of whole tones.
		else:
			note = 256
		#calculate stereo values. NVDA expects  values between 0 and 100 for stereo volume for each channel.
		if config.conf["indentone"]["toneType"] & STEREO:
			right = int((volume/(MAX_LEVEL-1))*level)
			left = volume-right
		else:
			left = right = 50
		tones.beep(note, 80, left=left, right=right)
		return
Esempio n. 15
0
	def patch_synth(self):
		if self.orig_speak is not None:
			return
		synth = speech.getSynth()
		self.orig_speak = synth.speak
		synth.speak = self.speak
		self.orig_cancel = synth.cancel
		synth.cancel = self.cancel
		if synth.__class__.name == 'silence':
			def setter(self, val):
				pass
			self.orig_get_lastIndex = synth.__class__.lastIndex
			synth.__class__.lastIndex = property(fget=self._get_lastIndex, fset=setter)
		else:
			self.orig_get_lastIndex = synth.__class__.lastIndex.fget
			synth.__class__.lastIndex.fget = self._get_lastIndex
		self.orig_setSynth = synthDriverHandler.setSynth
		synthDriverHandler.setSynth = self.setSynth
		speech.setSynth = self.setSynth
		gui.settingsDialogs.setSynth = self.setSynth
Esempio n. 16
0
	def _compute_volume(self):
		driver=speech.getSynth()
		volume = getattr(driver, 'volume', 100)/100.0 #nvda reports as percent.
		volume=clamp(volume, 0.0, 1.0)
		return volume
Esempio n. 17
0
	def speak(self, sequence, **kwargs):
		if self.is_muted:
			return
		synth = speech.getSynth()
		speech.beenCanceled = False
		wx.CallAfter(synth.speak, sequence)
Esempio n. 18
0
	def cancel_speech(self, **kwargs):
		if self.is_muted:
			return
		synth = speech.getSynth()
		wx.CallAfter(synth.cancel)
Esempio n. 19
0
 def _compute_volume(self):
     driver = speech.getSynth()
     volume = getattr(driver, 'volume',
                      100) / 100.0  #nvda reports as percent.
     volume = clamp(volume, 0.0, 1.0)
     return volume