def initialize(): global espeakDLL, bgThread, bgQueue, player espeakDLL = cdll.LoadLibrary(r"synthDrivers\espeak.dll") espeakDLL.espeak_Info.restype = c_char_p espeakDLL.espeak_Synth.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByName.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByProperties.errcheck = espeak_errcheck espeakDLL.espeak_SetParameter.errcheck = espeak_errcheck espeakDLL.espeak_Terminate.errcheck = espeak_errcheck espeakDLL.espeak_ListVoices.restype = POINTER(POINTER(espeak_VOICE)) espeakDLL.espeak_GetCurrentVoice.restype = POINTER(espeak_VOICE) espeakDLL.espeak_SetVoiceByName.argtypes = (c_char_p, ) sampleRate = espeakDLL.espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 300, os.path.abspath("synthDrivers"), 0) if sampleRate < 0: raise OSError("espeak_Initialize %d" % sampleRate) player = nvwave.WavePlayer( channels=1, samplesPerSec=sampleRate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) espeakDLL.espeak_SetSynthCallback(callback) bgQueue = Queue.Queue() bgThread = BgThread() bgThread.start()
def playWaveFileEx(fileName, asynchronous=True): """plays a specified wave file. @param asynchronous: whether the wave file should be played asynchronously @type asynchronous: bool """ from synthDriverHandler import _audioOutputDevice f = wave.open(fileName, "r") if f is None: raise RuntimeError("can not open file %s" % fileName) if nvwave.fileWavePlayer is not None: nvwave.fileWavePlayer.stop() nvwave.fileWavePlayer = nvwave.WavePlayer( channels=f.getnchannels(), samplesPerSec=f.getframerate(), bitsPerSample=f.getsampwidth() * 8, # outputDevice=config.conf["speech"]["outputDevice"], outputDevice=_audioOutputDevice, 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()
def run(self): try: self.wavePlayer = nvwave.WavePlayer( channels=1, samplesPerSec=self.sampleRate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.synthEvent = threading.Event() finally: self.initializeEvent.set() while self.keepAlive: self.synthEvent.wait() self.synthEvent.clear() lastIndex = None while self.keepAlive: data = self.speechPlayer.synthesize(8192) if self.isSpeaking and data: indexNum = self.speechPlayer.getLastIndex() self.wavePlayer.feed( ctypes.string_at(data, data.length * 2), onDone=lambda indexNum=indexNum: synthIndexReached. notify(synth=self.synthRef(), index=indexNum) if indexNum >= 0 else False) lastIndex = indexNum else: indexNum = self.speechPlayer.getLastIndex() if indexNum > 0 and indexNum != lastIndex: synthIndexReached.notify(synth=self.synthRef(), index=indexNum) self.wavePlayer.idle() synthDoneSpeaking.notify(synth=self.synthRef()) break self.initializeEvent.set()
def bgPlay(stri): global player if not player or len(stri) == 0: return # Sometimes player.feed() tries to open the device when it's already open, # causing a WindowsError. This code catches and works around this. # [DGL, 2012-12-18 with help from Tyler] tries = 0 while tries < 10: try: player.feed(stri) if tries > 0: log.warning("Eloq speech retries: %d" % (tries)) return except FileNotFoundError: # reset the player if the used soundcard is not present. E.G. the total number of sound devices has changed. player.close() player = nvwave.WavePlayer( 1, 11025, 16, outputDevice=config.conf["speech"]["outputDevice"]) except: player.idle() time.sleep(0.02) tries += 1 log.error("Eloq speech failed to feed one buffer.")
def initialize(indexCallback=None): """ @param indexCallback: A function which is called when eSpeak reaches an index. It is called with one argument: the number of the index or C{None} when speech stops. """ global espeakDLL, bgThread, bgQueue, player, onIndexReached espeakDLL = cdll.LoadLibrary(r"synthDrivers\espeak.dll") espeakDLL.espeak_Info.restype = c_char_p espeakDLL.espeak_Synth.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByName.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByProperties.errcheck = espeak_errcheck espeakDLL.espeak_SetParameter.errcheck = espeak_errcheck espeakDLL.espeak_Terminate.errcheck = espeak_errcheck espeakDLL.espeak_ListVoices.restype = POINTER(POINTER(espeak_VOICE)) espeakDLL.espeak_GetCurrentVoice.restype = POINTER(espeak_VOICE) espeakDLL.espeak_SetVoiceByName.argtypes = (c_char_p, ) eSpeakPath = os.path.abspath("synthDrivers") sampleRate = espeakDLL.espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 300, os.fsencode(eSpeakPath), 0) if sampleRate < 0: raise OSError("espeak_Initialize %d" % sampleRate) player = nvwave.WavePlayer( channels=1, samplesPerSec=sampleRate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], buffered=True) onIndexReached = indexCallback espeakDLL.espeak_SetSynthCallback(callback) bgQueue = queue.Queue() bgThread = BgThread() bgThread.start()
def initialize(): global espeakDLL, bgThread, bgQueue, player if platform.architecture()[0][:2] == "64": espeakDLL = cdll.LoadLibrary(r"espeak64.dll") else: espeakDLL = cdll.LoadLibrary(r"espeak.dll") espeakDLL.espeak_Info.restype = c_char_p espeakDLL.espeak_Synth.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByName.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByProperties.errcheck = espeak_errcheck espeakDLL.espeak_SetParameter.errcheck = espeak_errcheck espeakDLL.espeak_Terminate.errcheck = espeak_errcheck espeakDLL.espeak_ListVoices.restype = POINTER(POINTER(espeak_VOICE)) espeakDLL.espeak_GetCurrentVoice.restype = POINTER(espeak_VOICE) espeakDLL.espeak_SetVoiceByName.argtypes = (c_char_p, ) sampleRate = espeakDLL.espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 300, ".", 0) if sampleRate < 0: raise OSError("espeak_Initialize %d" % sampleRate) player = nvwave.WavePlayer(channels=1, samplesPerSec=sampleRate, bitsPerSample=16) espeakDLL.espeak_SetSynthCallback(callback) bgQueue = queue.Queue() bgThread = BgThread() bgThread.start()
def __init__(self): self.player = nvwave.WavePlayer( channels=2, samplesPerSec=int(tones.SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], wantDucking=False) self.stopSignal = False
def __init__(self, fileName, startAdjustment=0, endAdjustment=0): self.fileName = fileName self.startAdjustment = startAdjustment self.endAdjustment = endAdjustment self.f = wave.open(self.fileName,"r") f = self.f if self.f is None: raise RuntimeError("can not open file %s"%self.fileName) self.fileWavePlayer = nvwave.WavePlayer(channels=f.getnchannels(), samplesPerSec=f.getframerate(),bitsPerSample=f.getsampwidth()*8, outputDevice=config.conf["speech"]["outputDevice"],wantDucking=False)
def do_get_player(self): if self.__closed: return None if self.__sample_rate==0: return None player=self.__players.get(self.__sample_rate,None) if player is None: player=nvwave.WavePlayer(channels=1,samplesPerSec=self.__sample_rate,bitsPerSample=16,outputDevice=config.conf["speech"]["outputDevice"]) self.__players[self.__sample_rate]=player return player
def initialize(): global player try: player = nvwave.WavePlayer( channels=2, samplesPerSec=int(SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], wantDucking=False) except Exception: log.warning("Failed to initialize audio for tones", exc_info=True) player = None
def initialize(indexCallback=None): global eci, player, bgt, dll, handle, onIndexReached onIndexReached = indexCallback player = nvwave.WavePlayer( 1, 11025, 16, outputDevice=config.conf["speech"]["outputDevice"]) eci = eciThread() eci.start() started.wait() started.clear() bgt = BgThread() bgt.start()
def initialize(): global bgThread, bgQueue, player player = nvwave.WavePlayer(channels=1, samplesPerSec=16000, bitsPerSample=16) bgQueue = Queue.Queue() bgThread = BgThread() bgThread.start() # OpenJTalk_initialize() OpenJTalk_load() Mecab_initialize() Mecab_load()
def doInit(self): if self.player is not None: try: self.player.stop() except: pass self.buf, framerate = generateBeepBuf(getConfig('whiteNoiseVolume')) self.player = nvwave.WavePlayer( channels=2, samplesPerSec=framerate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], wantDucking=False)
def __init__(self, sim, mix_ahead): self.sim = sim self.mix_ahead = mix_ahead self.queue = Queue.Queue(mix_ahead + 1) self.player = nvwave.WavePlayer( channels=2, samplesPerSec=44100, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.feeding_thread = threading.Thread(target=self.feeder_func) self.playing_thread = threading.Thread(target=self.player_func) self.playing_thread.daemon = True self.feeding_thread.daemon = True self.playing_thread.start() self.feeding_thread.start()
def _maybeInitPlayer(self, wav): """Initialize audio playback based on the wave header provided by the synthesizer. If the sampling rate has not changed, the existing player is used. Otherwise, a new one is created with the appropriate parameters. """ samplesPerSec = wav.getframerate() if self._player and self._player.samplesPerSec == samplesPerSec: return if self._player: # Finalise any pending audio. self._player.idle() bytesPerSample = wav.getsampwidth() self._bytesPerSec = samplesPerSec * bytesPerSample self._player = nvwave.WavePlayer(channels=wav.getnchannels(), samplesPerSec=samplesPerSec, bitsPerSample=bytesPerSample * 8, outputDevice=config.conf["speech"]["outputDevice"])
def player_func(self): prev_device = config.conf["speech"]["outputDevice"] zero_string = struct.pack("882h", *[0] * 882) #10 ms of silence. while True: current_device = config.conf["speech"]["outputDevice"] if prev_device != current_device: self.player = nvwave.WavePlayer( channels=2, samplesPerSec=44100, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) prev_device = current_device try: send_string = self.queue.get(block=True, timeout=0.01) self.player.feed(send_string) except Queue.Empty: self.player.feed(zero_string)
def __init__(self): global player player = nvwave.WavePlayer( channels=1, samplesPerSec=10000, bitsPerSample=8, outputDevice=config.conf["speech"]["outputDevice"]) self.hasDictLib = os.path.isfile('synthDrivers/dict.dll') if self.hasDictLib: self.sdrvxpdb_lib = windll.LoadLibrary( r"synthDrivers\sdrvxpdb.dll") self.dict_lib = windll.LoadLibrary(r"synthDrivers\dict.dll") self.newfon_lib = windll.LoadLibrary(r"synthDrivers\newfon_nvda.dll") self.newfon_lib.speakText.argtypes = [c_char_p, c_int] if not self.newfon_lib.initialize(): raise Exception self.newfon_lib.set_callback(processAudio) self.newfon_lib.set_dictionary(1)
def initialize(indexCallback, doneCallback): global callbackQueue, callbackThread, eciQueue, eciThread, idleTimer, onIndexReached, onDoneSpeaking, player onIndexReached = indexCallback onDoneSpeaking = doneCallback idleTimer = threading.Timer( 0.3, time.sleep) # fake timer because this can't be None. player = nvwave.WavePlayer( 1, 11025, 16, outputDevice=config.conf["speech"]["outputDevice"]) if not eciCheck(): raise RuntimeError("No IBMTTS synthesizer available") eciQueue = queue.Queue() eciThread = EciThread() eciThread.start() started.wait() started.clear() callbackQueue = queue.Queue() callbackThread = CallbackThread() callbackThread.start()
def initialize(indexCallback=None): """ Initializes communication with vocalizer libraries. """ global veDll, platformDll, hSpeechClass, installResources, bgThread, bgQueue global pcmBuf, pcmBufLen, feedBuf, markBufSize, markBuf, player, onIndexReached onIndexReached = indexCallback # load dlls and stuff: preInitialize() # Start background thread bgQueue = queue.Queue() bgThread = BgThread(bgQueue) # and allocate PCM and mark buffers pcmBuf = (c_byte * pcmBufLen)() feedBuf = BytesIO() markBuf = (VE_MARKINFO * markBufSize)() # Create a wave player #sampleRate = sampleRateConversions[getParameter(VE_PARAM_FREQUENCY)] sampleRate = 22050 player = nvwave.WavePlayer( 1, sampleRate, 16, outputDevice=config.conf["speech"]["outputDevice"])
def run(self): try: self.wavePlayer = nvwave.WavePlayer( channels=1, samplesPerSec=self.sampleRate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.synthEvent = threading.Event() finally: self.initializeEvent.set() while self.keepAlive: self.synthEvent.wait() self.synthEvent.clear() while self.keepAlive: data = self.speechPlayer.synthesize(8192) if self.isSpeaking and data: self.wavePlayer.feed(data) else: self.wavePlayer.idle() break self.initializeEvent.set()
def initialize(indexCallback=None): """ @param indexCallback: A function which is called when eSpeak reaches an index. It is called with one argument: the number of the index or C{None} when speech stops. """ global espeakDLL, bgThread, bgQueue, player, onIndexReached espeakDLL = cdll.LoadLibrary( os.path.join(globalVars.appDir, "synthDrivers", "espeak.dll")) espeakDLL.espeak_Info.restype = c_char_p espeakDLL.espeak_Synth.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByName.errcheck = espeak_errcheck espeakDLL.espeak_SetVoiceByProperties.errcheck = espeak_errcheck espeakDLL.espeak_SetParameter.errcheck = espeak_errcheck espeakDLL.espeak_Terminate.errcheck = espeak_errcheck espeakDLL.espeak_ListVoices.restype = POINTER(POINTER(espeak_VOICE)) espeakDLL.espeak_GetCurrentVoice.restype = POINTER(espeak_VOICE) espeakDLL.espeak_SetVoiceByName.argtypes = (c_char_p, ) eSpeakPath = os.path.join(globalVars.appDir, "synthDrivers") sampleRate = espeakDLL.espeak_Initialize( AUDIO_OUTPUT_SYNCHRONOUS, 300, os.fsencode(eSpeakPath), # #10607: ensure espeak does not exit NVDA's process on errors such as the espeak path being invalid. espeakINITIALIZE_DONT_EXIT) if sampleRate <= 0: raise OSError( f"espeak_Initialize failed with code {sampleRate}. Given Espeak data path of {eSpeakPath}" ) player = nvwave.WavePlayer( channels=1, samplesPerSec=sampleRate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], buffered=True) onIndexReached = indexCallback espeakDLL.espeak_SetSynthCallback(callback) bgQueue = queue.Queue() bgThread = BgThread() bgThread.start()
def __init__(self): self.dll=ctypes.cdll.LoadLibrary(os.path.join(BASE_PATH, 'svox-pico.dll')) #prepare dll object system_functs = ('pico_initialize', 'pico_terminate', 'pico_getSystemStatusMessage', 'pico_getNrSystemWarnings', 'pico_getSystemWarning', 'pico_loadResource', 'pico_unloadResource', 'pico_getResourceName', 'pico_createVoiceDefinition', 'pico_addResourceToVoiceDefinition', 'pico_releaseVoiceDefinition', 'pico_newEngine', 'pico_disposeEngine') for func in system_functs: getattr(self.dll,func).errcheck=self.pico_system_errcheck engine_funcs = ('pico_putTextUtf8', 'pico_getData', 'pico_resetEngine', 'pico_getEngineStatusMessage', 'pico_getNrEngineWarnings', 'pico_getEngineWarning') for func in engine_funcs: getattr(self.dll, func).errcheck = self.pico_engine_errcheck #init pico system self._svox_memory = ctypes.create_string_buffer(SVOX_MEMORY_SIZE) self.pico_system = pico_system() self.dll.pico_initialize(self._svox_memory, SVOX_MEMORY_SIZE, ctypes.byref(self.pico_system)) self.pico_engine = None self.player = nvwave.WavePlayer(channels=1, samplesPerSec=16000, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.queue = queue.Queue() self.isSpeaking = False self.background_thread = threading.Thread(target=self.background_thread_func) self.background_thread.daemon = True self.background_thread.start() self._set_voice("es")
def __init__(self): super(SynthDriver, self).__init__() self._dll = ctypes.windll[DLL_FILE] self._dll.ocSpeech_getCurrentVoiceLanguage.restype = ctypes.c_wchar_p self._handle = self._dll.ocSpeech_initialize() self._callbackInst = ocSpeech_Callback(self._callback) self._dll.ocSpeech_setCallback(self._handle, self._callbackInst) self._dll.ocSpeech_getVoices.restype = bstrReturn self._dll.ocSpeech_getCurrentVoiceId.restype = ctypes.c_wchar_p self._player = nvwave.WavePlayer( 1, SAMPLES_PER_SEC, BITS_PER_SAMPLE, outputDevice=config.conf["speech"]["outputDevice"]) # Initialize state. self._queuedSpeech = [] self._wasCancelled = False self._isProcessing = False # Set initial values for parameters that can't be queried. # This initialises our cache for the value. self.rate = 50 self.pitch = 50 self.volume = 100
def __init__(self): self.__lib = ctypes.CDLL(lib_path.encode(sys.getfilesystemencoding())) self.__lib.RHVoice_initialize.argtypes = (c_char_p, RHVoice_callback, c_char_p, c_uint) self.__lib.RHVoice_initialize.restype = c_int self.__lib.RHVoice_new_message_utf16.argtypes = (c_wchar_p, c_int, c_int) self.__lib.RHVoice_new_message_utf16.restype = RHVoice_message self.__lib.RHVoice_delete_message.argtypes = (RHVoice_message, ) self.__lib.RHVoice_speak.argtypes = (RHVoice_message, ) self.__lib.RHVoice_get_min_rate.restype = c_float self.__lib.RHVoice_get_rate.restype = c_float self.__lib.RHVoice_get_max_rate.restype = c_float self.__lib.RHVoice_get_min_pitch.restype = c_float self.__lib.RHVoice_get_pitch.restype = c_float self.__lib.RHVoice_get_max_pitch.restype = c_float self.__lib.RHVoice_get_volume.restype = c_float self.__lib.RHVoice_get_max_volume.restype = c_float self.__lib.RHVoice_get_voice_count.restype = c_int self.__lib.RHVoice_get_variant_count.restype = c_int self.__lib.RHVoice_get_voice_name.argtypes = (c_int, ) self.__lib.RHVoice_get_voice_name.restype = c_char_p self.__lib.RHVoice_get_variant_name.argtypes = (c_int, ) self.__lib.RHVoice_get_variant_name.restype = c_char_p self.__lib.RHVoice_find_voice.argtypes = (c_char_p, ) self.__lib.RHVoice_find_voice.restype = c_int self.__lib.RHVoice_find_variant.argtypes = (c_char_p, ) self.__lib.RHVoice_find_variant.restype = c_int self.__lib.RHVoice_get_voice.restype = c_int self.__lib.RHVoice_get_variant.restype = c_int self.__lib.RHVoice_set_voice.argtypes = (c_int, ) self.__lib.RHVoice_set_variant.argtypes = (c_int, ) self.__lib.RHVoice_get_version.restype = c_char_p self.__silence_flag = threading.Event() self.__audio_callback = AudioCallback(self.__lib, self.__silence_flag) self.__audio_callback_wrapper = RHVoice_callback(self.__audio_callback) sample_rate = self.__lib.RHVoice_initialize( data_path.encode("UTF-8"), self.__audio_callback_wrapper, cfg_path.encode("UTF-8"), 0) if sample_rate == 0: raise RuntimeError("RHVoice: initialization error") voice_count = self.__lib.RHVoice_get_voice_count() if voice_count == 0: raise RuntimeError("RHVoice: initialization error") self.__player = nvwave.WavePlayer( channels=1, samplesPerSec=sample_rate, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.__audio_callback.set_player(self.__player) self.__tts_queue = Queue.Queue() self.__tts_thread = TTSThread(self.__lib, self.__tts_queue, self.__player, self.__silence_flag) self._availableVoices = OrderedDict() for id in range(1, voice_count + 1): name = self.__lib.RHVoice_get_voice_name(id) self._availableVoices[name] = VoiceInfo(name, name, "ru") self.__lib.RHVoice_set_voice(1) self.__voice = self.__lib.RHVoice_get_voice_name(1) variant_count = self.__lib.RHVoice_get_variant_count() self._availableVariants = OrderedDict() for id in range(1, variant_count + 1): name = self.__lib.RHVoice_get_variant_name(id) self._availableVariants[name] = VoiceInfo(name, name, "ru") self.__lib.RHVoice_set_variant(1) self.__variant = self.__lib.RHVoice_get_variant_name(1) self.__rate = 50 self.__pitch = 50 self.__volume = 50 self.__native_rate_range = (self.__lib.RHVoice_get_min_rate(), self.__lib.RHVoice_get_max_rate(), self.__lib.RHVoice_get_rate()) self.__native_pitch_range = (self.__lib.RHVoice_get_min_pitch(), self.__lib.RHVoice_get_max_pitch(), self.__lib.RHVoice_get_pitch()) self.__native_volume_range = (0, self.__lib.RHVoice_get_max_volume(), self.__lib.RHVoice_get_volume()) self.__char_mapping = {} for c in range(9): self.__char_mapping[c] = 32 self.__char_mapping[11] = 32 self.__char_mapping[12] = 32 for c in range(14, 32): self.__char_mapping[c] = 32 self.__char_mapping[ord("<")] = u"<" self.__char_mapping[ord("&")] = u"&" self.__tts_thread.start() log.info("Using RHVoice version %s" % self.__lib.RHVoice_get_version())
def __init__(self): self.__lib = load_tts_library() self.__cancel_flag = threading.Event() self.__player = nvwave.WavePlayer( channels=1, samplesPerSec=16000, bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"]) self.__speech_callback = speech_callback(self.__lib, self.__player, self.__cancel_flag) self.__c_speech_callback = RHVoice_callback_types.play_speech( self.__speech_callback) self.__mark_callback = mark_callback(self.__lib) self.__c_mark_callback = RHVoice_callback_types.process_mark( self.__mark_callback) resource_paths = [ os.path.join(addon.path, "data").encode("UTF-8") for addon in addonHandler.getRunningAddons() if (addon.name.startswith("RHVoice-language") or addon.name.startswith("RHVoice-voice")) ] c_resource_paths = (c_char_p * (len(resource_paths) + 1))( *(resource_paths + [None])) init_params = RHVoice_init_params( None, config_path.encode("utf-8"), c_resource_paths, RHVoice_callbacks( self.__c_speech_callback, self.__c_mark_callback, cast(None, RHVoice_callback_types.word_starts), cast(None, RHVoice_callback_types.word_ends), cast(None, RHVoice_callback_types.sentence_starts), cast(None, RHVoice_callback_types.sentence_ends), cast(None, RHVoice_callback_types.play_audio)), 0) self.__tts_engine = self.__lib.RHVoice_new_tts_engine( byref(init_params)) if not self.__tts_engine: raise RuntimeError("RHVoice: initialization error") nvda_language = languageHandler.getLanguage().split("_")[0] number_of_voices = self.__lib.RHVoice_get_number_of_voices( self.__tts_engine) native_voices = self.__lib.RHVoice_get_voices(self.__tts_engine) self.__voice_languages = dict() self.__languages = set() for i in xrange(number_of_voices): native_voice = native_voices[i] self.__voice_languages[native_voice.name] = native_voice.language self.__languages.add(native_voice.language) self.__profile = None self.__profiles = list() number_of_profiles = self.__lib.RHVoice_get_number_of_voice_profiles( self.__tts_engine) native_profile_names = self.__lib.RHVoice_get_voice_profiles( self.__tts_engine) for i in xrange(number_of_profiles): name = native_profile_names[i] self.__profiles.append(name) if (self.__profile is None) and (nvda_language == self.__voice_languages[name.split("+")[0]]): self.__profile = name if self.__profile is None: self.__profile = self.__profiles[0] self.__rate = 50 self.__pitch = 50 self.__volume = 50 self.__tts_queue = Queue.Queue() self.__tts_thread = TTSThread(self.__tts_queue) self.__tts_thread.start() log.info("Using RHVoice version {}".format( self.__lib.RHVoice_get_version()))
"ruleType": "prosody", "startAdjustment": 0, "tone": 500, "wavFile": "" } ] """.replace("\\", "\\\\") def initConfiguration(): confspec = { "enabled" : "boolean( default=True)", "rules" : "string( default='')", } config.conf.spec[pp] = confspec ppSynchronousPlayer = nvwave.WavePlayer(channels=2, samplesPerSec=int(tones.SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"],wantDucking=True) class PpSynchronousCommand(speech.commands.BaseCallbackCommand): def getDuration(self): raise NotImplementedError() def terminate(self): raise NotImplementedError() class PpBeepCommand(PpSynchronousCommand): def __init__(self, hz, length, left=50, right=50): super().__init__() self.hz = hz self.length = length self.left = left self.right = right
import gui from logHandler import log from NVDAHelper import generateBeep import nvwave import speech from threading import Lock, Thread import time import tones import ui import wx SAMPLE_RATE = 44100 try: player = nvwave.WavePlayer( channels=2, samplesPerSec=int(SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"], wantDucking=False) except: log.warning("Failed to initialize player for BluetoothAudio") counter = 0 counterThreshold = 5 lock = Lock() def resetCounter(): global counter, lock with lock: counter = 0