Most of the pep8 changes finished. Be careful, things may be horribly broken.
This commit is contained in:
@ -6,26 +6,26 @@
|
||||
# generic driver
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
from fenrirscreenreader.core.speechDriver import speechDriver
|
||||
from fenrirscreenreader.core.speechDriver import speech_driver
|
||||
|
||||
|
||||
class driver(speechDriver):
|
||||
class driver(speech_driver):
|
||||
def __init__(self):
|
||||
speechDriver.__init__(self)
|
||||
speech_driver.__init__(self)
|
||||
|
||||
def initialize(self, environment):
|
||||
self._isInitialized = True
|
||||
self._is_initialized = True
|
||||
self.env = environment
|
||||
print('Speech Debug Driver: Iitialized')
|
||||
|
||||
def shutdown(self):
|
||||
if self._isInitialized:
|
||||
if self._is_initialized:
|
||||
self.cancel()
|
||||
self._isInitialized = False
|
||||
self._is_initialized = False
|
||||
print('Speech Debug Driver: Shutdown')
|
||||
|
||||
def speak(self, text, queueable=True, ignorePunctuation=False):
|
||||
if not self._isInitialized:
|
||||
def speak(self, text, queueable=True, ignore_punctuation=False):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
if not queueable:
|
||||
self.cancel()
|
||||
@ -33,44 +33,44 @@ class driver(speechDriver):
|
||||
print('Speech Debug Driver: -----------------------------------')
|
||||
|
||||
def cancel(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: Cancel')
|
||||
|
||||
def setCallback(self, callback):
|
||||
print('Speech Debug Driver: setCallback')
|
||||
def set_callback(self, callback):
|
||||
print('Speech Debug Driver: set_callback')
|
||||
|
||||
def clear_buffer(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: clear_buffer')
|
||||
|
||||
def setVoice(self, voice):
|
||||
if not self._isInitialized:
|
||||
def set_voice(self, voice):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setVoice:' + str(voice))
|
||||
print('Speech Debug Driver: set_voice:' + str(voice))
|
||||
|
||||
def setPitch(self, pitch):
|
||||
if not self._isInitialized:
|
||||
def set_pitch(self, pitch):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setPitch:' + str(pitch))
|
||||
print('Speech Debug Driver: set_pitch:' + str(pitch))
|
||||
|
||||
def setRate(self, rate):
|
||||
if not self._isInitialized:
|
||||
def set_rate(self, rate):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setRate:' + str(rate))
|
||||
print('Speech Debug Driver: set_rate:' + str(rate))
|
||||
|
||||
def setModule(self, module):
|
||||
if not self._isInitialized:
|
||||
def set_module(self, module):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setModule:' + str(module))
|
||||
print('Speech Debug Driver: set_module:' + str(module))
|
||||
|
||||
def setLanguage(self, language):
|
||||
if not self._isInitialized:
|
||||
def set_language(self, language):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setLanguage:' + str(language))
|
||||
print('Speech Debug Driver: set_language:' + str(language))
|
||||
|
||||
def setVolume(self, volume):
|
||||
if not self._isInitialized:
|
||||
def set_volume(self, volume):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
print('Speech Debug Driver: setVolume:' + str(volume))
|
||||
print('Speech Debug Driver: set_volume:' + str(volume))
|
||||
|
@ -6,9 +6,9 @@
|
||||
# generic driver
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
from fenrirscreenreader.core.speechDriver import speechDriver
|
||||
from fenrirscreenreader.core.speechDriver import speech_driver
|
||||
|
||||
|
||||
class driver(speechDriver):
|
||||
class driver(speech_driver):
|
||||
def __init__(self):
|
||||
speechDriver.__init__(self)
|
||||
speech_driver.__init__(self)
|
||||
|
@ -11,10 +11,10 @@ from queue import Queue, Empty
|
||||
import shlex
|
||||
from subprocess import Popen
|
||||
import subprocess
|
||||
from fenrirscreenreader.core.speechDriver import speechDriver
|
||||
from fenrirscreenreader.core.speechDriver import speech_driver
|
||||
|
||||
|
||||
class speakQueue(Queue):
|
||||
class SpeakQueue(Queue):
|
||||
def clear(self):
|
||||
try:
|
||||
while True:
|
||||
@ -23,30 +23,30 @@ class speakQueue(Queue):
|
||||
pass
|
||||
|
||||
|
||||
class driver(speechDriver):
|
||||
class driver(speech_driver):
|
||||
def __init__(self):
|
||||
speechDriver.__init__(self)
|
||||
speech_driver.__init__(self)
|
||||
self.proc = None
|
||||
self.speechThread = Thread(target=self.worker)
|
||||
self.lock = Lock()
|
||||
self.textQueue = speakQueue()
|
||||
self.textQueue = SpeakQueue()
|
||||
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.minVolume = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMinVolume')
|
||||
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.maxVolume = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMaxVolume')
|
||||
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.minPitch = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMinPitch')
|
||||
self.maxPitch = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.maxPitch = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMaxPitch')
|
||||
self.minRate = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.minRate = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMinRate')
|
||||
self.maxRate = self.env['runtime']['settingsManager'].getSettingAsInt(
|
||||
self.maxRate = self.env['runtime']['SettingsManager'].get_setting_as_int(
|
||||
'speech', 'fenrirMaxRate')
|
||||
|
||||
self.speechCommand = self.env['runtime']['settingsManager'].getSetting(
|
||||
self.speechCommand = self.env['runtime']['SettingsManager'].get_setting(
|
||||
'speech', 'genericSpeechCommand')
|
||||
if self.speechCommand == '':
|
||||
self.speechCommand = 'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice -- "fenrirText"'
|
||||
@ -54,18 +54,18 @@ class driver(speechDriver):
|
||||
# self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
|
||||
self.speechCommand = 'flite -t "fenrirText"'
|
||||
|
||||
self._isInitialized = True
|
||||
if self._isInitialized:
|
||||
self._is_initialized = True
|
||||
if self._is_initialized:
|
||||
self.speechThread.start()
|
||||
|
||||
def shutdown(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.cancel()
|
||||
self.textQueue.put(-1)
|
||||
|
||||
def speak(self, text, queueable=True, ignorePunctuation=False):
|
||||
if not self._isInitialized:
|
||||
def speak(self, text, queueable=True, ignore_punctuation=False):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
if not queueable:
|
||||
self.cancel()
|
||||
@ -81,7 +81,7 @@ class driver(speechDriver):
|
||||
self.textQueue.put(utterance.copy())
|
||||
|
||||
def cancel(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.clear_buffer()
|
||||
self.lock.acquire(True)
|
||||
@ -97,56 +97,56 @@ class driver(speechDriver):
|
||||
self.proc.kill()
|
||||
self.proc.wait(timeout=1.0)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver:Cancel:self.proc.terminate():' + str(e), debug.debugLevel.WARNING)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'speech_driver:Cancel:self.proc.terminate():' + str(e), debug.DebugLevel.WARNING)
|
||||
try:
|
||||
self.proc.kill()
|
||||
# Wait after kill to prevent zombies
|
||||
self.proc.wait(timeout=1.0)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver:Cancel:self.proc.kill():' + str(e), debug.debugLevel.WARNING)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'speech_driver:Cancel:self.proc.kill():' + str(e), debug.DebugLevel.WARNING)
|
||||
self.proc = None
|
||||
finally:
|
||||
# Ensure lock is always released, even if process termination fails
|
||||
self.lock.release()
|
||||
|
||||
def setCallback(self, callback):
|
||||
print('SpeechDummyDriver: setCallback')
|
||||
def set_callback(self, callback):
|
||||
print('SpeechDummyDriver: set_callback')
|
||||
|
||||
def clear_buffer(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.textQueue.clear()
|
||||
|
||||
def setVoice(self, voice):
|
||||
if not self._isInitialized:
|
||||
def set_voice(self, voice):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.voice = str(voice)
|
||||
|
||||
def setPitch(self, pitch):
|
||||
if not self._isInitialized:
|
||||
def set_pitch(self, pitch):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.pitch = str(self.minPitch + pitch *
|
||||
(self.maxPitch - self.minPitch))
|
||||
|
||||
def setRate(self, rate):
|
||||
if not self._isInitialized:
|
||||
def set_rate(self, rate):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.rate = str(self.minRate + rate * (self.maxRate - self.minRate))
|
||||
|
||||
def setModule(self, module):
|
||||
if not self._isInitialized:
|
||||
def set_module(self, module):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.module = str(module)
|
||||
|
||||
def setLanguage(self, language):
|
||||
if not self._isInitialized:
|
||||
def set_language(self, language):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.language = str(language)
|
||||
|
||||
def setVolume(self, volume):
|
||||
if not self._isInitialized:
|
||||
def set_volume(self, volume):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.volume = str(self.minVolume + volume *
|
||||
(self.maxVolume - self.minVolume))
|
||||
@ -195,8 +195,8 @@ class driver(speechDriver):
|
||||
if not isinstance(utterance['rate'], str):
|
||||
utterance['rate'] = ''
|
||||
|
||||
popenSpeechCommand = shlex.split(self.speechCommand)
|
||||
for idx, word in enumerate(popenSpeechCommand):
|
||||
popen_speech_command = shlex.split(self.speechCommand)
|
||||
for idx, word in enumerate(popen_speech_command):
|
||||
word = word.replace('fenrirVolume', str(utterance['volume']))
|
||||
word = word.replace('fenrirModule', str(utterance['module']))
|
||||
word = word.replace(
|
||||
@ -208,14 +208,14 @@ class driver(speechDriver):
|
||||
# Properly quote text to prevent command injection
|
||||
word = word.replace('fenrirText',
|
||||
shlex.quote(str(utterance['text'])))
|
||||
popenSpeechCommand[idx] = word
|
||||
popen_speech_command[idx] = word
|
||||
|
||||
try:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver:worker:' + ' '.join(popenSpeechCommand), debug.debugLevel.INFO)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'speech_driver:worker:' + ' '.join(popen_speech_command), debug.DebugLevel.INFO)
|
||||
self.lock.acquire(True)
|
||||
self.proc = Popen(
|
||||
popenSpeechCommand,
|
||||
popen_speech_command,
|
||||
stdin=None,
|
||||
stdout=None,
|
||||
stderr=None,
|
||||
@ -223,8 +223,8 @@ class driver(speechDriver):
|
||||
self.lock.release()
|
||||
self.proc.wait()
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver:worker:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'speech_driver:worker:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
self.lock.acquire(True)
|
||||
self.proc = None
|
||||
|
@ -6,17 +6,17 @@
|
||||
# speech-dispatcher driver
|
||||
|
||||
from fenrirscreenreader.core import debug
|
||||
from fenrirscreenreader.core.speechDriver import speechDriver
|
||||
from fenrirscreenreader.core.speechDriver import speech_driver
|
||||
|
||||
|
||||
class driver(speechDriver):
|
||||
class driver(speech_driver):
|
||||
def __init__(self):
|
||||
speechDriver.__init__(self)
|
||||
speech_driver.__init__(self)
|
||||
|
||||
def initialize(self, environment):
|
||||
self._sd = None
|
||||
self.env = environment
|
||||
self._isInitialized = False
|
||||
self._is_initialized = False
|
||||
|
||||
# Only set these if they haven't been set yet (preserve existing
|
||||
# values)
|
||||
@ -29,105 +29,105 @@ class driver(speechDriver):
|
||||
|
||||
try:
|
||||
import speechd
|
||||
self._sd = speechd.SSIPClient('fenrir')
|
||||
self._sd = speechd.SSIPClient('fenrir-dev')
|
||||
self._punct = speechd.PunctuationMode()
|
||||
self._isInitialized = True
|
||||
self._is_initialized = True
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver initialize:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver initialize:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
def shutdown(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
self.cancel()
|
||||
try:
|
||||
self._sd.close()
|
||||
except Exception as e:
|
||||
pass
|
||||
self._isInitialized = False
|
||||
self._is_initialized = False
|
||||
|
||||
def speak(self, text, queueable=True, ignorePunctuation=False):
|
||||
def speak(self, text, queueable=True, ignore_punctuation=False):
|
||||
if not queueable:
|
||||
self.cancel()
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
self.initialize(self.env)
|
||||
if not queueable:
|
||||
self.cancel()
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
|
||||
try:
|
||||
if self.module != '':
|
||||
self._sd.set_output_module(self.module)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver setModule:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_module:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
try:
|
||||
if self.language != '':
|
||||
self._sd.set_language(self.language)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver set_language:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_language:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
try:
|
||||
if self.voice != '':
|
||||
self._sd.set_synthesis_voice(self.voice)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver setVoice:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_voice:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
try:
|
||||
if ignorePunctuation:
|
||||
if ignore_punctuation:
|
||||
self._sd.set_punctuation(self._punct.ALL)
|
||||
else:
|
||||
self._sd.set_punctuation(self._punct.NONE)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver set_punctuation:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_punctuation:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
try:
|
||||
self._sd.speak(text)
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver speak:' + str(e), debug.debugLevel.ERROR)
|
||||
self._isInitialized = False
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver speak:' + str(e), debug.DebugLevel.ERROR)
|
||||
self._is_initialized = False
|
||||
|
||||
def cancel(self):
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
self.initialize(self.env)
|
||||
if not self._isInitialized:
|
||||
if not self._is_initialized:
|
||||
return
|
||||
try:
|
||||
self._sd.cancel()
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver cancel:' + str(e), debug.debugLevel.ERROR)
|
||||
self._isInitialized = False
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver cancel:' + str(e), debug.DebugLevel.ERROR)
|
||||
self._is_initialized = False
|
||||
|
||||
def setPitch(self, pitch):
|
||||
if not self._isInitialized:
|
||||
def set_pitch(self, pitch):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
try:
|
||||
self._sd.set_pitch(int(-100 + pitch * 200))
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver setPitch:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_pitch:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
def setRate(self, rate):
|
||||
if not self._isInitialized:
|
||||
def set_rate(self, rate):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
try:
|
||||
self._sd.set_rate(int(-100 + rate * 200))
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver setRate:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_rate:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
||||
def setVolume(self, volume):
|
||||
if not self._isInitialized:
|
||||
def set_volume(self, volume):
|
||||
if not self._is_initialized:
|
||||
return
|
||||
try:
|
||||
self._sd.set_volume(int(-100 + volume * 200))
|
||||
except Exception as e:
|
||||
self.env['runtime']['debug'].writeDebugOut(
|
||||
'speechDriver setVolume:' + str(e), debug.debugLevel.ERROR)
|
||||
self.env['runtime']['DebugManager'].write_debug_out(
|
||||
'SpeechDriver set_volume:' + str(e), debug.DebugLevel.ERROR)
|
||||
|
Reference in New Issue
Block a user