unify more loops, remove spaces
This commit is contained in:
parent
8663ad1ac9
commit
3f85d672a6
@ -16,11 +16,11 @@ class driver(brailleDriver):
|
|||||||
self.env = environment
|
self.env = environment
|
||||||
try:
|
try:
|
||||||
import brlapi
|
import brlapi
|
||||||
self._brl = brlapi.Connection()
|
self._brl = brlapi.Connection()
|
||||||
self._deviceSize = self._brl.displaySize
|
self._deviceSize = self._brl.displaySize
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
|
|
||||||
|
@ -44,6 +44,6 @@ class driver(brailleDriver):
|
|||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self._isInitialized:
|
if self._isInitialized:
|
||||||
self.leveScreen()
|
self.leveScreen()
|
||||||
self._isInitialized = False
|
self._isInitialized = False
|
||||||
print('Braille Debug Driver: Shutdown')
|
print('Braille Debug Driver: Shutdown')
|
||||||
|
@ -14,14 +14,14 @@ class driver(inputDriver):
|
|||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.env['runtime']['inputManager'].setShortcutType('KEY')
|
self.env['runtime']['inputManager'].setShortcutType('KEY')
|
||||||
self._initialized = True
|
self._initialized = True
|
||||||
print('Input Debug Driver: Initialized')
|
print('Input Debug Driver: Initialized')
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self._initialized:
|
if self._initialized:
|
||||||
self.removeAllDevices()
|
self.removeAllDevices()
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
print('Input Debug Driver: Shutdown')
|
print('Input Debug Driver: Shutdown')
|
||||||
|
|
||||||
def getInputEvent(self):
|
def getInputEvent(self):
|
||||||
@ -32,32 +32,32 @@ class driver(inputDriver):
|
|||||||
return None
|
return None
|
||||||
def writeEventBuffer(self):
|
def writeEventBuffer(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
print('Input Debug Driver: writeEventBuffer')
|
print('Input Debug Driver: writeEventBuffer')
|
||||||
def clearEventBuffer(self):
|
def clearEventBuffer(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
del self.env['input']['eventBuffer'][:]
|
del self.env['input']['eventBuffer'][:]
|
||||||
print('Input Debug Driver: clearEventBuffer')
|
print('Input Debug Driver: clearEventBuffer')
|
||||||
def updateInputDevices(self, newDevices = None, init = False):
|
def updateInputDevices(self, newDevices = None, init = False):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
print('Input Debug Driver: updateInputDevices')
|
print('Input Debug Driver: updateInputDevices')
|
||||||
def getLedState(self, led = 0):
|
def getLedState(self, led = 0):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
def toggleLedState(self, led = 0):
|
def toggleLedState(self, led = 0):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
print('Input Debug Driver: toggleLedState')
|
print('Input Debug Driver: toggleLedState')
|
||||||
def grabAllDevices(self):
|
def grabAllDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
print('Input Debug Driver: grabAllDevices')
|
print('Input Debug Driver: grabAllDevices')
|
||||||
def ungrabAllDevices(self):
|
def ungrabAllDevices(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
print('Input Debug Driver: ungrabAllDevices')
|
print('Input Debug Driver: ungrabAllDevices')
|
||||||
|
|
||||||
def removeAllDevices(self):
|
def removeAllDevices(self):
|
||||||
@ -67,6 +67,6 @@ class driver(inputDriver):
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._initialized:
|
if self._initialized:
|
||||||
self.removeAllDevices()
|
self.removeAllDevices()
|
||||||
print('Input Debug Driver: __del__')
|
print('Input Debug Driver: __del__')
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@ from fenrirscreenreader.core.inputDriver import inputDriver
|
|||||||
|
|
||||||
class driver(inputDriver):
|
class driver(inputDriver):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._isInitialized = False
|
self._isInitialized = False
|
||||||
inputDriver.__init__(self)
|
inputDriver.__init__(self)
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.env['runtime']['inputManager'].setShortcutType('BYTE')
|
self.env['runtime']['inputManager'].setShortcutType('BYTE')
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
|
@ -33,7 +33,7 @@ class driver(screenDriver):
|
|||||||
self.charmap = {}
|
self.charmap = {}
|
||||||
self.bgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'white'}
|
self.bgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'white'}
|
||||||
self.fgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'light gray', 8: 'dark gray', 9: 'light blue', 10: 'light green', 11: 'light cyan', 12: 'light red', 13: 'light magenta', 14: 'light yellow', 15: 'white'}
|
self.fgColorValues = {0: 'black', 1: 'blue', 2: 'green', 3: 'cyan', 4: 'red', 5: 'magenta', 6: 'brown/yellow', 7: 'light gray', 8: 'dark gray', 9: 'light blue', 10: 'light green', 11: 'light cyan', 12: 'light red', 13: 'light magenta', 14: 'light yellow', 15: 'white'}
|
||||||
self.hichar = None
|
self.hichar = None
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.env['runtime']['attributeManager'].appendDefaultAttributes([
|
self.env['runtime']['attributeManager'].appendDefaultAttributes([
|
||||||
@ -47,11 +47,11 @@ class driver(screenDriver):
|
|||||||
False, # blink
|
False, # blink
|
||||||
'default', # fontsize
|
'default', # fontsize
|
||||||
'default' # fontfamily
|
'default' # fontfamily
|
||||||
]) #end attribute )
|
]) #end attribute )
|
||||||
self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog, multiprocess=True)
|
self.env['runtime']['processManager'].addCustomEventThread(self.updateWatchdog, multiprocess=True)
|
||||||
def getCurrScreen(self):
|
def getCurrScreen(self):
|
||||||
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
|
self.env['screen']['oldTTY'] = self.env['screen']['newTTY']
|
||||||
try:
|
try:
|
||||||
currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r')
|
currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r')
|
||||||
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
self.env['screen']['newTTY'] = str(currScreenFile.read()[3:-1])
|
||||||
currScreenFile.close()
|
currScreenFile.close()
|
||||||
@ -121,7 +121,7 @@ class driver(screenDriver):
|
|||||||
watchdog = select.epoll()
|
watchdog = select.epoll()
|
||||||
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
|
watchdog.register(vcsa[currScreen], select.POLLPRI | select.POLLERR)
|
||||||
watchdog.register(tty, select.POLLPRI | select.POLLERR)
|
watchdog.register(tty, select.POLLPRI | select.POLLERR)
|
||||||
while active.value == 1:
|
while active.value:
|
||||||
changes = watchdog.poll(1)
|
changes = watchdog.poll(1)
|
||||||
for change in changes:
|
for change in changes:
|
||||||
fileno = change[0]
|
fileno = change[0]
|
||||||
@ -229,7 +229,7 @@ class driver(screenDriver):
|
|||||||
tty = open('/dev/tty' + screen, 'rb')
|
tty = open('/dev/tty' + screen, 'rb')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('VCSA:updateCharMap:' + str(e),debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
GIO_UNIMAP = 0x4B66
|
GIO_UNIMAP = 0x4B66
|
||||||
VT_GETHIFONTMASK = 0x560D
|
VT_GETHIFONTMASK = 0x560D
|
||||||
himask = array("H", (0,))
|
himask = array("H", (0,))
|
||||||
|
@ -28,7 +28,7 @@ class driver(soundDriver):
|
|||||||
|
|
||||||
def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0):
|
def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
popenFrequenceCommand = shlex.split(self.frequenceCommand)
|
popenFrequenceCommand = shlex.split(self.frequenceCommand)
|
||||||
@ -36,28 +36,28 @@ class driver(soundDriver):
|
|||||||
word = word.replace('fenrirVolume', str(self.volume + adjustVolume ))
|
word = word.replace('fenrirVolume', str(self.volume + adjustVolume ))
|
||||||
word = word.replace('fenrirFreqDuration', str(duration))
|
word = word.replace('fenrirFreqDuration', str(duration))
|
||||||
word = word.replace('fenrirFrequence', str(frequence))
|
word = word.replace('fenrirFrequence', str(frequence))
|
||||||
popenFrequenceCommand[idx] = word
|
popenFrequenceCommand[idx] = word
|
||||||
self.proc = subprocess.Popen(popenFrequenceCommand, stdin=None, stdout=None, stderr=None, shell=False)
|
self.proc = subprocess.Popen(popenFrequenceCommand, stdin=None, stdout=None, stderr=None, shell=False)
|
||||||
self.soundType = 'frequence'
|
self.soundType = 'frequence'
|
||||||
def playSoundFile(self, filePath, interrupt = True):
|
def playSoundFile(self, filePath, interrupt = True):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
popenSoundFileCommand = shlex.split(self.soundFileCommand)
|
popenSoundFileCommand = shlex.split(self.soundFileCommand)
|
||||||
for idx, word in enumerate(popenSoundFileCommand):
|
for idx, word in enumerate(popenSoundFileCommand):
|
||||||
word = word.replace('fenrirVolume', str(self.volume ))
|
word = word.replace('fenrirVolume', str(self.volume ))
|
||||||
word = word.replace('fenrirSoundFile', str(filePath))
|
word = word.replace('fenrirSoundFile', str(filePath))
|
||||||
popenSoundFileCommand[idx] = word
|
popenSoundFileCommand[idx] = word
|
||||||
self.proc = subprocess.Popen(popenSoundFileCommand, shell=False)
|
self.proc = subprocess.Popen(popenSoundFileCommand, shell=False)
|
||||||
self.soundType = 'file'
|
self.soundType = 'file'
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
if self.soundType == '':
|
if self.soundType == '':
|
||||||
return
|
return
|
||||||
if self.soundType == 'file':
|
if self.soundType == 'file':
|
||||||
self.proc.kill()
|
self.proc.kill()
|
||||||
if self.soundType == 'frequence':
|
if self.soundType == 'frequence':
|
||||||
self.proc.kill()
|
self.proc.kill()
|
||||||
self.soundType = ''
|
self.soundType = ''
|
||||||
|
@ -10,11 +10,11 @@ from fenrirscreenreader.core.soundDriver import soundDriver
|
|||||||
|
|
||||||
_gstreamerAvailable = False
|
_gstreamerAvailable = False
|
||||||
try:
|
try:
|
||||||
import gi
|
import gi
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
gi.require_version('Gst', '1.0')
|
gi.require_version('Gst', '1.0')
|
||||||
from gi.repository import Gst
|
from gi.repository import Gst
|
||||||
_gstreamerAvailable, args = Gst.init_check(None)
|
_gstreamerAvailable, args = Gst.init_check(None)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_gstreamerAvailable = False
|
_gstreamerAvailable = False
|
||||||
_availableError = str(e)
|
_availableError = str(e)
|
||||||
@ -28,10 +28,10 @@ class driver(soundDriver):
|
|||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
global _gstreamerAvailable
|
global _gstreamerAvailable
|
||||||
self._initialized = _gstreamerAvailable
|
self._initialized = _gstreamerAvailable
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
global _availableError
|
global _availableError
|
||||||
self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available ' + _availableError,debug.debugLevel.ERROR)
|
self.environment['runtime']['debug'].writeDebugOut('Gstreamer not available ' + _availableError,debug.debugLevel.ERROR)
|
||||||
return
|
return
|
||||||
self._player = Gst.ElementFactory.make('playbin', 'player')
|
self._player = Gst.ElementFactory.make('playbin', 'player')
|
||||||
bus = self._player.get_bus()
|
bus = self._player.get_bus()
|
||||||
@ -48,7 +48,7 @@ class driver(soundDriver):
|
|||||||
self._pipeline.add(self._source)
|
self._pipeline.add(self._source)
|
||||||
self._pipeline.add(self._sink)
|
self._pipeline.add(self._sink)
|
||||||
self._source.link(self._sink)
|
self._source.link(self._sink)
|
||||||
self.mainloop = GLib.MainLoop()
|
self.mainloop = GLib.MainLoop()
|
||||||
self.thread = threading.Thread(target=self.mainloop.run)
|
self.thread = threading.Thread(target=self.mainloop.run)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ class driver(soundDriver):
|
|||||||
elif message.type == Gst.MessageType.ERROR:
|
elif message.type == Gst.MessageType.ERROR:
|
||||||
self._player.set_state(Gst.State.NULL)
|
self._player.set_state(Gst.State.NULL)
|
||||||
error, info = message.parse_error()
|
error, info = message.parse_error()
|
||||||
self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
|
self.env['runtime']['debug'].writeDebugOut('GSTREAMER: _onPlayerMessage'+ str(error) + str(info),debug.debugLevel.WARNING)
|
||||||
|
|
||||||
def _onPipelineMessage(self, bus, message):
|
def _onPipelineMessage(self, bus, message):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
@ -80,12 +80,12 @@ class driver(soundDriver):
|
|||||||
|
|
||||||
def _onTimeout(self, element):
|
def _onTimeout(self, element):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
element.set_state(Gst.State.NULL)
|
element.set_state(Gst.State.NULL)
|
||||||
|
|
||||||
def playSoundFile(self, fileName, interrupt=True):
|
def playSoundFile(self, fileName, interrupt=True):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
self._player.set_property('uri', 'file://%s' % fileName)
|
self._player.set_property('uri', 'file://%s' % fileName)
|
||||||
@ -93,7 +93,7 @@ class driver(soundDriver):
|
|||||||
|
|
||||||
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
|
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
|
||||||
if not self._initialized:
|
if not self._initialized:
|
||||||
return
|
return
|
||||||
if interrupt:
|
if interrupt:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
self._source.set_property('volume', tone.volume)
|
self._source.set_property('volume', tone.volume)
|
||||||
|
@ -19,7 +19,7 @@ class driver(speechDriver):
|
|||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self._isInitialized:
|
if self._isInitialized:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
self._isInitialized = False
|
self._isInitialized = False
|
||||||
print('Speech Debug Driver: Shutdown')
|
print('Speech Debug Driver: Shutdown')
|
||||||
|
|
||||||
def speak(self,text, queueable=True):
|
def speak(self,text, queueable=True):
|
||||||
@ -33,42 +33,42 @@ class driver(speechDriver):
|
|||||||
def cancel(self):
|
def cancel(self):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: Cancel')
|
print('Speech Debug Driver: Cancel')
|
||||||
|
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
print('Speech Debug Driver: setCallback')
|
print('Speech Debug Driver: setCallback')
|
||||||
|
|
||||||
def clear_buffer(self):
|
def clear_buffer(self):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: clear_buffer')
|
print('Speech Debug Driver: clear_buffer')
|
||||||
|
|
||||||
def setVoice(self, voice):
|
def setVoice(self, voice):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setVoice:' + str(voice))
|
print('Speech Debug Driver: setVoice:' + str(voice))
|
||||||
|
|
||||||
def setPitch(self, pitch):
|
def setPitch(self, pitch):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setPitch:' + str(pitch))
|
print('Speech Debug Driver: setPitch:' + str(pitch))
|
||||||
|
|
||||||
def setRate(self, rate):
|
def setRate(self, rate):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setRate:' + str(rate))
|
print('Speech Debug Driver: setRate:' + str(rate))
|
||||||
|
|
||||||
def setModule(self, module):
|
def setModule(self, module):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setModule:' + str(module))
|
print('Speech Debug Driver: setModule:' + str(module))
|
||||||
|
|
||||||
def setLanguage(self, language):
|
def setLanguage(self, language):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setLanguage:' + str(language))
|
print('Speech Debug Driver: setLanguage:' + str(language))
|
||||||
|
|
||||||
def setVolume(self, volume):
|
def setVolume(self, volume):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
print('Speech Debug Driver: setVolume:' + str(volume))
|
print('Speech Debug Driver: setVolume:' + str(volume))
|
||||||
|
@ -15,19 +15,19 @@ class driver(speechDriver):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
speechDriver.__init__(self)
|
speechDriver.__init__(self)
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
try:
|
try:
|
||||||
self.server = pexpect.spawn('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath'))
|
self.server = pexpect.spawn('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath'))
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self.server:
|
if self.server:
|
||||||
try:
|
try:
|
||||||
self.server.terminate()
|
self.server.terminate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:shutdown:self.server.terminate():' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:shutdown:self.server.terminate():' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def speak(self,text, queueable=True):
|
def speak(self,text, queueable=True):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
@ -45,7 +45,7 @@ class driver(speechDriver):
|
|||||||
cleanText = 'tts_say \"' + cleanText +'\"'
|
cleanText = 'tts_say \"' + cleanText +'\"'
|
||||||
self.server.sendline(cleanText)
|
self.server.sendline(cleanText)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:speak:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:speak:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
@ -54,7 +54,7 @@ class driver(speechDriver):
|
|||||||
self.server.sendline('stop')
|
self.server.sendline('stop')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:cancel:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:cancel:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def setRate(self, rate):
|
def setRate(self, rate):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
@ -62,7 +62,7 @@ class driver(speechDriver):
|
|||||||
try:
|
try:
|
||||||
self.server.sendline('tts_set_speech_rate ' + str(int(rate * 400)))
|
self.server.sendline('tts_set_speech_rate ' + str(int(rate * 400)))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:setRate:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:setRate:self.server.sendline():' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def setLanguage(self, language):
|
def setLanguage(self, language):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
|
@ -14,13 +14,13 @@ class driver(speechDriver):
|
|||||||
self._es = None
|
self._es = None
|
||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
try:
|
try:
|
||||||
from espeak import espeak
|
from espeak import espeak
|
||||||
self._es = espeak
|
self._es = espeak
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
|
|
||||||
def speak(self,text, interrupt=True):
|
def speak(self,text, interrupt=True):
|
||||||
@ -30,10 +30,10 @@ class driver(speechDriver):
|
|||||||
self.cancel()
|
self.cancel()
|
||||||
if self.language != None:
|
if self.language != None:
|
||||||
if self.language != '':
|
if self.language != '':
|
||||||
self._es.set_voice(self.language)
|
self._es.set_voice(self.language)
|
||||||
elif self.voice != None:
|
elif self.voice != None:
|
||||||
if self.voice != '':
|
if self.voice != '':
|
||||||
self._es.set_voice(self.voice)
|
self._es.set_voice(self.voice)
|
||||||
self._es.synth(text)
|
self._es.synth(text)
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
|
@ -27,11 +27,11 @@ class driver(speechDriver):
|
|||||||
self.speechThread = Thread(target=self.worker)
|
self.speechThread = Thread(target=self.worker)
|
||||||
self.lock = Lock()
|
self.lock = Lock()
|
||||||
self.textQueue = speakQueue()
|
self.textQueue = speakQueue()
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinVolume')
|
self.minVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinVolume')
|
||||||
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxVolume')
|
self.maxVolume = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxVolume')
|
||||||
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinPitch')
|
self.minPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinPitch')
|
||||||
self.maxPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxPitch')
|
self.maxPitch = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxPitch')
|
||||||
self.minRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinRate')
|
self.minRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMinRate')
|
||||||
self.maxRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxRate')
|
self.maxRate = self.env['runtime']['settingsManager'].getSettingAsInt('speech', 'fenrirMaxRate')
|
||||||
@ -40,23 +40,23 @@ class driver(speechDriver):
|
|||||||
if self.speechCommand == '':
|
if self.speechCommand == '':
|
||||||
self.speechCommand = 'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice -- "fenrirText"'
|
self.speechCommand = 'espeak -a fenrirVolume -s fenrirRate -p fenrirPitch -v fenrirVoice -- "fenrirText"'
|
||||||
if False: #for debugging overwrite here
|
if False: #for debugging overwrite here
|
||||||
#self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
|
#self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
|
||||||
self.speechCommand = 'flite -t "fenrirText"'
|
self.speechCommand = 'flite -t "fenrirText"'
|
||||||
|
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
if self._isInitialized:
|
if self._isInitialized:
|
||||||
self.speechThread.start()
|
self.speechThread.start()
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
self.cancel()
|
self.cancel()
|
||||||
self.textQueue.put(-1)
|
self.textQueue.put(-1)
|
||||||
|
|
||||||
def speak(self,text, queueable=True):
|
def speak(self,text, queueable=True):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
if not queueable:
|
if not queueable:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
utterance = {
|
utterance = {
|
||||||
'text': text,
|
'text': text,
|
||||||
'volume': self.volume,
|
'volume': self.volume,
|
||||||
@ -65,7 +65,7 @@ class driver(speechDriver):
|
|||||||
'module': self.module,
|
'module': self.module,
|
||||||
'language': self.language,
|
'language': self.language,
|
||||||
'voice': self.voice,
|
'voice': self.voice,
|
||||||
}
|
}
|
||||||
self.textQueue.put(utterance.copy())
|
self.textQueue.put(utterance.copy())
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
@ -77,20 +77,20 @@ class driver(speechDriver):
|
|||||||
try:
|
try:
|
||||||
self.proc.terminate()
|
self.proc.terminate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
|
||||||
try:
|
try:
|
||||||
self.proc.kill()
|
self.proc.kill()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
|
||||||
self.proc = None
|
self.proc = None
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
print('SpeechDummyDriver: setCallback')
|
print('SpeechDummyDriver: setCallback')
|
||||||
|
|
||||||
def clear_buffer(self):
|
def clear_buffer(self):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
self.textQueue.clear()
|
self.textQueue.clear()
|
||||||
|
|
||||||
def setVoice(self, voice):
|
def setVoice(self, voice):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
@ -137,7 +137,7 @@ class driver(speechDriver):
|
|||||||
if not 'text' in utterance:
|
if not 'text' in utterance:
|
||||||
continue
|
continue
|
||||||
if not isinstance(utterance['text'],str):
|
if not isinstance(utterance['text'],str):
|
||||||
continue
|
continue
|
||||||
if utterance['text'] == '':
|
if utterance['text'] == '':
|
||||||
continue
|
continue
|
||||||
# check for valid data fields
|
# check for valid data fields
|
||||||
@ -178,13 +178,13 @@ class driver(speechDriver):
|
|||||||
popenSpeechCommand[idx] = word
|
popenSpeechCommand[idx] = word
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + ' '.join(popenSpeechCommand),debug.debugLevel.INFO)
|
||||||
self.lock.acquire(True)
|
self.lock.acquire(True)
|
||||||
self.proc = Popen(popenSpeechCommand, stdin=None, stdout=None, stderr=None, shell=False)
|
self.proc = Popen(popenSpeechCommand, stdin=None, stdout=None, stderr=None, shell=False)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
self.proc.wait()
|
self.proc.wait()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
self.lock.acquire(True)
|
self.lock.acquire(True)
|
||||||
self.proc = None
|
self.proc = None
|
||||||
|
@ -14,12 +14,12 @@ class driver(speechDriver):
|
|||||||
speechDriver.__init__(self)
|
speechDriver.__init__(self)
|
||||||
self._engine = None
|
self._engine = None
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if self._isInitialized:
|
if self._isInitialized:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
self._engine.endLoop()
|
self._engine.endLoop()
|
||||||
self._initialized = False
|
self._initialized = False
|
||||||
def eventLoop(self):
|
def eventLoop(self):
|
||||||
self._engine.startLoop()
|
self._engine.startLoop()
|
||||||
def startEngine(self):
|
def startEngine(self):
|
||||||
@ -28,17 +28,17 @@ class driver(speechDriver):
|
|||||||
if self.module != '':
|
if self.module != '':
|
||||||
self._engine = pyttsx3.init(self.module)
|
self._engine = pyttsx3.init(self.module)
|
||||||
else:
|
else:
|
||||||
self._engine = pyttsx3.init()
|
self._engine = pyttsx3.init()
|
||||||
self.eventLoopThread = Thread(target=self.eventLoop)
|
self.eventLoopThread = Thread(target=self.eventLoop)
|
||||||
self._isInitialized = True
|
self._isInitialized = True
|
||||||
self.eventLoopThread.start()
|
self.eventLoopThread.start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:initialize:' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
def speak(self,text, interrupt=True):
|
def speak(self,text, interrupt=True):
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
self.startEngine()
|
self.startEngine()
|
||||||
if not self._isInitialized:
|
if not self._isInitialized:
|
||||||
return
|
return
|
||||||
if not interrupt:
|
if not interrupt:
|
||||||
self.cancel()
|
self.cancel()
|
||||||
@ -51,15 +51,15 @@ class driver(speechDriver):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:rate:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:rate:' + str(e),debug.debugLevel.ERROR)
|
||||||
try:
|
try:
|
||||||
self._engine.setProperty('pitch', self.pitch)
|
self._engine.setProperty('pitch', self.pitch)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:pitch:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:pitch:' + str(e),debug.debugLevel.ERROR)
|
||||||
if self.language != None:
|
if self.language != None:
|
||||||
if self.language != '':
|
if self.language != '':
|
||||||
try:
|
try:
|
||||||
self._engine.setProperty('voice', self.language)
|
self._engine.setProperty('voice', self.language)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:language:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('SpeechDriver:speak:language:' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
elif self.voice != None:
|
elif self.voice != None:
|
||||||
if self.voice != '':
|
if self.voice != '':
|
||||||
|
Loading…
Reference in New Issue
Block a user