def test_setSynth_auto_fallbackMode(self): """ Ensures setSynth("auto") successfully sets a synth in defaultSynthPriorityList, and config is unchanged. """ synthDriverHandler.setSynth("auto", isFallback=True) self.assertIn(synthDriverHandler.getSynth().name, synthDriverHandler.defaultSynthPriorityList) self.assertEqual(FAKE_DEFAULT_LANG, config.conf["speech"]["synth"])
def test_setSynth_auto(self): """ Ensures setSynth("auto") successfully sets a synth in defaultSynthPriorityList, and saves it to config. """ synthDriverHandler.setSynth("auto") autoSynthName = synthDriverHandler.getSynth().name self.assertIn(autoSynthName, synthDriverHandler.defaultSynthPriorityList) self.assertEqual(config.conf["speech"]["synth"], autoSynthName)
def test_setSynth_auto_usesOneCore_ifSupportsDefaultLanguage(self): """ Ensures that if oneCore supports the current language, setSynth("auto") uses "oneCore". """ # test setup ensures current NVDA language is supported for oneCore synthDriverHandler.setSynth(None) # reset the synth so there is no fallback synthDriverHandler.setSynth("auto") self.assertEqual(synthDriverHandler.getSynth().name, "oneCore")
def test_setSynth_defaultSynths_fallbackMode(self): """ For each synth in the synthDriverHandler.defaultSynthPriorityList, ensure they can be successfully set and the config is unchanged. """ for synthName in synthDriverHandler.defaultSynthPriorityList: synthDriverHandler.setSynth(synthName, isFallback=True) self.assertEqual(synthName, synthDriverHandler.getSynth().name) self.assertEqual(FAKE_DEFAULT_LANG, config.conf["speech"]["synth"])
def test_setSynth_defaultSynths(self): """ For each synth in the synthDriverHandler.defaultSynthPriorityList, ensure they can be successfully set and saved to config. """ for synthName in synthDriverHandler.defaultSynthPriorityList: synthDriverHandler.setSynth(synthName) self.assertEqual(synthName, synthDriverHandler.getSynth().name) self.assertEqual(synthName, config.conf["speech"]["synth"])
def finish(synthName, synthspeechConfig, msg): # stop previous synth because oneCore voice switch don't work without it config.conf[SCT_Speech] = synthSpeechConfig.copy() setSynth(synthName) config.conf[SCT_Speech][synthName] = synthSpeechConfig[ synthName].copy() getSynth().loadSettings() # Reinitialize the tones module to update the audio device import tones tones.terminate() tones.initialize() if msg: ui.message(msg)
def resetSynth(self) -> None: """If the synthesizer is not initialized - repeat attempts to initialize it.""" if not synthDriverHandler.getSynth(): synthDriverHandler.initialize() i = 0 while not synthDriverHandler.getSynth() and i <= config.conf[ADDON_NAME]['retries']: synthDriverHandler.setSynth(config.conf['speech']['synth']) sleep(1) if config.conf[ADDON_NAME]['retries'] != 0: i += 1 else: if config.conf[ADDON_NAME]['playsound']: self.audioEnabledSound()
def initialize(): """ Loads and sets the synth driver configured in nvda.ini. Initializes the state of speech and initializes the sayAllHandler """ synthDriverHandler.initialize() synthDriverHandler.setSynth(config.conf["speech"]["synth"]) speechInitialize() sayAllInitialize( speak, speakObject, getTextInfoSpeech, SpeakTextInfoState, )
def switchToDefaultOutputDevice(self) -> None: """Switch NVDA audio output to the default audio device.""" device: str = self.getDefaultDeviceName() if config.conf['speech']['outputDevice'] not in ("Microsoft Sound Mapper", device,): config.conf['speech']['outputDevice'] = device if synthDriverHandler.setSynth(synthDriverHandler.getSynth().name): tones.terminate() tones.initialize() if config.conf[ADDON_NAME]['playsound']: self.audioEnabledSound()
def setOutputDevice(self, name: str) -> None: """Switche the NVDA output to the audio device with the specified name. @param name: name of the audio output device @type name: str """ config.conf['speech']['outputDevice'] = name status: bool = setSynth(getSynth().name) if status: tones.terminate() tones.initialize() ui.message(name)
def setUp(self): import speechDictHandler speechDictHandler.initialize( ) # setting the synth depends on dictionary["voice"] import synthDriverHandler # Some speech functions (speakTextInfo due to calling getSpellingSpeech) rely on getting config for a # synth, they first get the synth, then synth.name. # Previously this wasn't necessary since speech.speak and speech.speakSpelling are a no-op # (see tests/unit/__init__.py), however, since logic from these methods has moved to get*Speech methods # the logic is now executed, and the following dependencies need to be met. assert synthDriverHandler.setSynth("silence") assert synthDriverHandler.getSynth()
def setOutputDevice(synth, outputDevice): import speech speech.cancelSpeech() prevOutputDevice = config.conf["speech"]["outputDevice"] config.conf["speech"]["outputDevice"] = outputDevice # Reinitialize the tones module to update the audio device import tones tones.terminate() if not setSynth(synth.name): log.error("Could not load the %s synthesizer." % synth) ret = False else: ret = True tones.initialize() config.conf["speech"]["outputDevice"] = prevOutputDevice return ret
def set(self) -> bool: """Sets the profile as the current voice synthesizer. @return: an indication of whether the synthesizer has been successfully switched on @rtype: bool """ state = False try: config.conf.profiles[0]['speech'][self._name].clear() config.conf.profiles[0]['speech'][self._name].update(self._conf) config.conf['speech'][self._name]._cache.clear() state = setSynth(self._name) getSynth().saveSettings() except KeyError: pass self._status = state return state
def test_setSynth_auto_fallback_ifOneCoreDoesntSupportDefaultLanguage(self): """ Ensures that if oneCore doesn't support the current language, setSynth("auto") falls back to the current synth, or espeak if there is no current synth. """ globalVars.appArgs.language = "bar" # set the lang so it is not supported synthDriverHandler.setSynth("auto") self.assertEqual(synthDriverHandler.getSynth().name, FAKE_DEFAULT_SYNTH_NAME) synthDriverHandler.setSynth(None) # reset the synth so there is no fallback synthDriverHandler.setSynth("auto") self.assertEqual(synthDriverHandler.getSynth().name, "espeak")
def initialize(): """Loads and sets the synth driver configured in nvda.ini.""" synthDriverHandler.initialize() synthDriverHandler.setSynth(config.conf["speech"]["synth"]) speechInitialize()
wantDucking=False ) nvwave.fileWavePlayer.feed(f.readframes(f.getnframes())) if asynchronous: if nvwave.fileWavePlayerThread is not None: nvwave.fileWavePlayerThread.join() nvwave.fileWavePlayerThread = threading.Thread( name=f"{__name__}.playWaveFile({os.path.basename(fileName)})", target=nvwave.fileWavePlayer.idle ) nvwave.fileWavePlayerThread.start() else: nvwave.fileWavePlayer.idle() """ patch for OneCore synthetizer this method use config.conf["speech"]["outputDevice"] to get the output device directly so if we change config.conf["speech"]["outputDevice"] after synthetizer initialization, it takes it as output device. but we don't that. we want change the output device of a synthetizer with no configuration change, like that: oldOutputDevice= config.conf["speech"]["outputDevice"] config.conf["speech"]["outputDevice"] = newOutputDevice setSynth(getSynth().name) config.conf["speech"]["outputDevice"] = oldOutputDevice We use _audioOutputDevice variable set by setSynth method """ def _maybeInitPlayerEx(self, wav):
def terminate(): synthDriverHandler.setSynth(None)