start inherit drivers

This commit is contained in:
chrys 2017-10-24 07:34:22 +02:00
parent fc53810e14
commit cd49aa3dca
9 changed files with 50 additions and 312 deletions

View File

@ -5,51 +5,8 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
from core.brailleDriver import brailleDriver
class driver(): class driver(brailleDriver):
def __init__(self): def __init__(self):
self.printMessages = False brailleDriver.__init__(self)
def initialize(self, environment):
self.env = environment
self._isInitialized = True
self.deviceSize = (40,0)
if self.printMessages:
print('BrailleDummyDriver: Initialize')
def getDeviceSize(self):
if not self._isInitialized:
return (0,0)
if self.printMessages:
print('BrailleDummyDriver: getDeviceSize ' + str(self.deviceSize))
return self.deviceSize
def writeText(self,text):
if not self._isInitialized:
return
if self.printMessages:
print('BrailleDummyDriver: writeText:' + str(text))
print('BrailleDummyDriver: -----------------------------------')
def connectDevice(self):
if self.printMessages:
print('BrailleDummyDriver: connectDevice')
def enterScreen(self, screen):
if not self._isInitialized:
return
if self.printMessages:
print('BrailleDummyDriver: enterScreen')
def leveScreen(self):
if not self._isInitialized:
return
if self.printMessages:
print('BrailleDummyDriver: leveScreen')
def shutdown(self):
if not self._isInitialized:
return
if self.printMessages:
print('BrailleDummyDriver: Shutdown')

View File

@ -6,55 +6,13 @@
import time import time
from core import debug from core import debug
from core.inputDriver import inputDriver
class driver(): class driver(inputDriver):
def __init__(self): def __init__(self):
self._initialized = False inputDriver.__init__(self)
def initialize(self, environment):
self.env = environment
def shutdown(self):
pass
def getInputEvent(self): def getInputEvent(self):
time.sleep(0.05) time.sleep(0.05)
if not self._initialized: if not self._initialized:
return None return None
def writeEventBuffer(self):
if not self._initialized:
return
def clearEventBuffer(self):
if not self._initialized:
return
del self.env['input']['eventBuffer'][:]
def updateInputDevices(self, force = False, init = False):
if not self._initialized:
return
def getLedState(self, led = 0):
if not self._initialized:
return False
return False
def toggleLedState(self, led = 0):
if not self._initialized:
return None
def grabDevices(self):
if not self._initialized:
return None
def releaseDevices(self):
if not self._initialized:
return None
def __del__(self):
if not self._initialized:
return None
self.releaseDevices()

View File

@ -5,51 +5,8 @@
# By Chrys, Storm Dragon, and contributers. # By Chrys, Storm Dragon, and contributers.
from core import debug from core import debug
from core.soundDriver import soundDriver
class driver(): class driver(soundDriver):
def __init__(self): def __init__(self):
self.volume = None soundDriver.__init__(self)
self._initialized = False
def initialize(self, environment):
self.env = environment
self._initialized = True
print('SoundDummyDriver: Initialize')
def shutdown(self):
if not self._initialized:
return
self.cancel()
print('SoundDummyDriver: Shutdown')
def playFrequence(self, frequence = 1000, duration = 0.3, adjustVolume = 0):
if not self._initialized:
return
if interrupt:
self.cancel()
print('SoundDummyDriver: playFrequence:' + ' freq:' + str(frequence) + ' duration:' + str(duration) + ' adjustVolume:' + str(adjustVolume) )
print('SoundDummyDriver: -----------------------------------')
def playSoundFile(self, filePath, interrupt = True):
if not self._initialized:
return
if interrupt:
self.cancel()
print('SoundDummyDriver: playSoundFile:' + str(filePath))
print('SoundDummyDriver: -----------------------------------')
def cancel(self):
if not self._initialized:
return
print('SoundDummyDriver: Cancel')
def setCallback(self, callback):
if not self._initialized:
return
print('SoundDummyDriver: setCallback')
def setVolume(self, volume):
if not self._initialized:
return
self.volume = volume
print('SoundDummyDriver: setVolume:' + str(self.volume))

View File

@ -6,15 +6,15 @@
from core import debug from core import debug
import subprocess import subprocess
from core.soundDriver import soundDriver
class driver(): class driver(soundDriver):
def __init__(self): def __init__(self):
soundDriver.__init__(self)
self.proc = None self.proc = None
self.volume = 1.0
self.soundType = '' self.soundType = ''
self.soundFileCommand = '' self.soundFileCommand = ''
self.frequenceCommand = '' self.frequenceCommand = ''
self._initialized = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.soundFileCommand = self.env['runtime']['settingsManager'].getSetting('sound', 'genericPlayFileCommand') self.soundFileCommand = self.env['runtime']['settingsManager'].getSetting('sound', 'genericPlayFileCommand')
@ -24,10 +24,7 @@ class driver():
if self.frequenceCommand == '': if self.frequenceCommand == '':
self.frequenceCommand = 'play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence' self.frequenceCommand = 'play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence'
self._initialized = True self._initialized = True
def shutdown(self):
if not self._initialized:
return
self.cancel()
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
@ -56,11 +53,4 @@ class driver():
self.proc.kill() self.proc.kill()
if self.soundType == 'frequence': if self.soundType == 'frequence':
self.proc.kill() self.proc.kill()
self.soundType = '' self.soundType = ''
def setCallback(self, callback):
if not self._initialized:
return
def setVolume(self, volume):
if not self._initialized:
return
self.volume = volume

View File

@ -6,7 +6,7 @@
from core import debug from core import debug
import time, threading import time, threading
from core.soundDriver import soundDriver
_gstreamerAvailable = False _gstreamerAvailable = False
try: try:
@ -19,12 +19,11 @@ except Exception as e:
_gstreamerAvailable = False _gstreamerAvailable = False
_availableError = str(e) _availableError = str(e)
class driver: class driver(soundDriver):
def __init__(self): def __init__(self):
soundDriver.__init__(self)
self._source = None self._source = None
self._sink = None self._sink = None
self.volume = 1
self._initialized = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
@ -112,10 +111,3 @@ class driver:
return return
self._player.set_state(Gst.State.NULL) self._player.set_state(Gst.State.NULL)
self._pipeline.set_state(Gst.State.NULL) self._pipeline.set_state(Gst.State.NULL)
def setVolume(self, volume):
if not self._initialized:
return
self.volume = volume

View File

@ -6,65 +6,7 @@
# generic driver # generic driver
from core import debug from core import debug
from core.speechDriver import speechDriver
class driver(): class driver(speechDriver):
def __init__(self): def __init__(self):
pass speechDriver.__init__(self)
def initialize(self, environment):
self._isInitialized = True
self.env = environment
print('SpeechDummyDriver: Iitialize')
def shutdown(self):
print('SpeechDummyDriver: Shutdown')
def speak(self,text, queueable=True):
if not self._isInitialized:
return
if not queueable:
self.cancel()
print('SpeechDummyDriver: Speak:'+text)
print('SpeechDummyDriver: -----------------------------------')
def cancel(self):
if not self._isInitialized:
return
print('SpeechDummyDriver: Cancel')
def setCallback(self, callback):
print('SpeechDummyDriver: setCallback')
def clear_buffer(self):
if not self._isInitialized:
return
print('SpeechDummyDriver: clear_buffer')
def setVoice(self, voice):
if not self._isInitialized:
return
print('SpeechDummyDriver: setVoice:' + str(voice))
def setPitch(self, pitch):
if not self._isInitialized:
return
print('SpeechDummyDriver: setPitch:' + str(pitch))
def setRate(self, rate):
if not self._isInitialized:
return
print('SpeechDummyDriver: setRate:' + str(rate))
def setModule(self, module):
if not self._isInitialized:
return
print('SpeechDummyDriver: setModule:' + str(module))
def setLanguage(self, language):
if not self._isInitialized:
return
print('SpeechDummyDriver: setLanguage:' + str(language))
def setVolume(self, volume):
if not self._isInitialized:
return
print('SpeechDummyDriver: setVolume:' + str(volume))

View File

@ -10,12 +10,12 @@ from subprocess import Popen, PIPE
import pexpect import pexpect
import sys import sys
import time import time
from core.speechDriver import speechDriver
class driver(): class driver(speechDriver):
def __init__(self): def __init__(self):
pass speechDriver.__init__(self)
def initialize(self, environment): def initialize(self, environment):
self._isInitialized = False
self.env = environment self.env = environment
try: try:
self.server = pexpect.spawnu('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath')) self.server = pexpect.spawnu('tclsh ' + self.env['runtime']['settingsManager'].getSetting('speech', 'serverPath'))
@ -55,20 +55,6 @@ class driver():
except Exception as e: except Exception as 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 setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return
def setVoice(self, voice):
if not self._isInitialized:
return
def setPitch(self, pitch):
pass
def setRate(self, rate): def setRate(self, rate):
if not self._isInitialized: if not self._isInitialized:
return return
@ -77,11 +63,7 @@ class driver():
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 setModule(self, module):
pass
def setLanguage(self, language): def setLanguage(self, language):
if not self._isInitialized: if not self._isInitialized:
return return
self.server.sendline('set_lang ' + language + '') self.server.sendline('set_lang ' + language + '')
def setVolume(self, volume):
pass

View File

@ -6,11 +6,12 @@
# Espeak driver # Espeak driver
from core import debug from core import debug
from core.speechDriver import speechDriver
class driver(): class driver(speechDriver):
def __init__(self): def __init__(self):
speechDriver.__init__(self)
self._es = None self._es = None
self._isInitialized = False
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
@ -21,15 +22,18 @@ class driver():
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 shutdown(self):
pass
def speak(self,text, interrupt=True): def speak(self,text, interrupt=True):
if not self._isInitialized: if not self._isInitialized:
return return
if not interrupt: if not interrupt:
self.cancel() self.cancel()
if self.language != None:
if self.language != '':
self._es.set_voice(self.language)
elif self.voice != None:
if self.voice != '':
self._es.set_voice(self.voice)
self._es.synth(text) self._es.synth(text)
def cancel(self): def cancel(self):
@ -38,20 +42,6 @@ class driver():
self._es.cancel() self._es.cancel()
return True return True
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return
def setVoice(self, voice):
if not self._isInitialized:
return
if voice =='':
return
return self._es.set_voice(voice)
def setPitch(self, pitch): def setPitch(self, pitch):
if not self._isInitialized: if not self._isInitialized:
return return
@ -62,17 +52,6 @@ class driver():
return return
return self._es.set_parameter(self._es.Parameter().Rate, int(rate * 500 + 100)) return self._es.set_parameter(self._es.Parameter().Rate, int(rate * 500 + 100))
def setModule(self, module):
if not self._isInitialized:
return
def setLanguage(self, language):
if not self._isInitialized:
return
if language =='':
return
return self._es.set_voice(language)
def setVolume(self, volume): def setVolume(self, volume):
if not self._isInitialized: if not self._isInitialized:
return return

View File

@ -6,12 +6,12 @@
# speech-dispatcher driver # speech-dispatcher driver
from core import debug from core import debug
from core.speechDriver import speechDriver
class driver(): class driver(speechDriver):
def __init__(self): def __init__(self):
speechDriver.__init__(self)
self._sd = None self._sd = None
self._isInitialized = False
self._language = ''
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
@ -22,7 +22,6 @@ class driver():
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)
self._initialized = False
def shutdown(self): def shutdown(self):
if not self._isInitialized: if not self._isInitialized:
@ -42,7 +41,18 @@ class driver():
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
self._sd.set_synthesis_voice(self._language) self._sd.set_output_module(self.module)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR)
try:
if self.voice != '':
self._sd.set_voice(self.voice)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR)
try:
if self.language != '':
self._sd.set_synthesis_voice(self.language)
self._sd.set_punctuation(self._punct.NONE) self._sd.set_punctuation(self._punct.NONE)
self._sd.speak(text) self._sd.speak(text)
except Exception as e: except Exception as e:
@ -57,23 +67,7 @@ class driver():
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver cancel:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver cancel:' + str(e),debug.debugLevel.ERROR)
self._isInitialized = False self._isInitialized = False
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return
def setVoice(self, voice):
if not self._isInitialized:
return
try:
if voice != '':
self._sd.set_voice(voice)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setVoice:' + str(e),debug.debugLevel.ERROR)
def setPitch(self, pitch): def setPitch(self, pitch):
if not self._isInitialized: if not self._isInitialized:
return return
@ -88,20 +82,7 @@ class driver():
try: try:
self._sd.set_rate(int(-100 + rate * 200)) self._sd.set_rate(int(-100 + rate * 200))
except Exception as e: except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR) self.env['runtime']['debug'].writeDebugOut('speechDriver setRate:' + str(e),debug.debugLevel.ERROR)
def setModule(self, module):
if not self._isInitialized:
return
try:
self._sd.set_output_module(module)
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver setModule:' + str(e),debug.debugLevel.ERROR)
def setLanguage(self, language):
if not self._isInitialized:
return
self._language = language
def setVolume(self, volume): def setVolume(self, volume):
if not self._isInitialized: if not self._isInitialized: