read new keybindig format

This commit is contained in:
chrys 2016-09-15 00:04:36 +02:00
parent c7045528df
commit d7bff19680
14 changed files with 100 additions and 643 deletions

View File

@ -1,21 +1,56 @@
[sound]
# Turn sound on or off:
enabled=True
# Select the driver used to play sounds, choices are sox and gstreamer.
# Sox is the default.
driver=sox
# Sound themes. This is the pack of sounds used for sound alerts.
# Sound packs may be located at /usr/share/sounds
# For system wide availability, or ~/.local/share/fenrir/sounds
# For the current user.
theme=default
# Sound volume controls how loud the sounds for your chosen soundpack are.
# 0 is quietest, 1.0 is loudest.
volume=1.0
[speech]
# Turn speech on or off:
enabled=True
# Select speech driver, options are speechd (default) or espeak:
driver=speechd
rate=0.75
#driver=espeak
# The rate selects how fast fenrir will speak. Options range from 0, slowest, to 1.0, fastest.
rate=0.45
# Pitch controls the pitch of the voice, select from 0, lowest, to 1.0, highest.
pitch=0.5
# Volume controls the loudness of the voice, select from 0, quietest, to 1.0, loudest.
volume=1.0
# Module is used for speech-dispatcher, to select the speech module you want to use.
# Consult speech-dispatcher's configuration and help ti find out which modules are available.
# The default is espeak.
module=espeak
voice=de
language=de
volume=0.8
# Voice selects the varient you want to use, for example, f5 will use the female voice #5 in espeak,
# or if using the espeak module in speech-dispatcher. To find out which voices are available, consult the documentation provided with your chosen synthesizer.
voice=
# Select the language you want fenrir to use.
language=english-us
# Read new text as it happens?
autoReadIncomming=True
[braille]
#braille is not implemented yet
enabled=False
layout=en
@ -29,27 +64,35 @@ autodetectSuspendingScreen=False
[keyboard]
driver=evdev
device=all
# gives fenrir exclusive access to the keyboard and let consume keystrokes. just disable on problems.
grabDevices=True
ignoreShortcuts=False
keyboardLayout=test
charEcho=True
# the current shortcut layout located in /etc/fenrir/keyboard
keyboardLayout=desktop
# echo chars while typing.
charEcho=False
# echo deleted chars
charDeleteEcho=True
wordEcho=True
# echo word after pressing space
wordEcho=False
# interrupt speech on any keypress
interruptOnKeyPress=False
# timeout for double tap in sec
doubleTapDelay=0.2
[general]
debugLevel=1
debugLevel=0
punctuationLevel=1
numberOfClipboards=10
# define the current fenrir key
fenrirKeys=KEY_KP0
timeFormat=%H:%M:%P
dateFormat="%A, %B %d, %Y"
autoSpellCheck=True
spellCheckLanguage=en_US
[promote]
enabled=True
inactiveTimeoutSec=120
list=chrys,test
list=

View File

@ -30,44 +30,20 @@ class settingsManager():
if line.count("=") != 1:
continue
sepLine = line.split('=')
commandString = sepLine[1]
keys = sepLine[0].replace(" ","").split(',')
currShortcut = []
validKeyString = True
keyIdent = ''
commandName = sepLine[1]
keys = sepLine[0].replace(" ","").replace("'","").replace('"',"").split(',')
shortcutKeys = []
shortcutRepeat = 1
shortcut = []
for key in keys:
if len(key) < 3:
validKeyString = False
break
if not key[0] in ['0','1','2']:
validKeyString = False
break
if key[1] != '-':
validKeyString = False
break
if key[2:] != '':
if key[2:] == 'FENRIR':
keyIdent= 'FENRIR'
else:
keyInt = self.getCodeForKeyID(key[2:])
keyIdent = str(keyInt)
else:
validKeyString = False
break
if keyIdent == '':
validKeyString = False
break
if not validKeyString:
break
else:
currShortcut.append(key[0] + '-' + keyIdent)
if validKeyString:
keyString = ''
for k in sorted(currShortcut):
if keyString != '':
keyString += ','
keyString += k
environment['bindings'][keyString] = commandString
try:
shortcutRepeat = int(key)
except:
shortcutKeys.append(key)
shortcut.append(shortcutRepeat)
shortcut.append(sorted(shortcutKeys))
print(str(shortcut))
environment['bindings'][str(shortcut)] = commandName
kbConfig.close()
return environment
@ -110,9 +86,10 @@ class settingsManager():
siConfig.close()
return environment
def loadSettings(self, environment, settingConfigPath='../../config/settings/settings.conf'):
def loadSettings(self, environment, settingConfigPath):
if not os.path.exists(settingConfigPath):
return None
environment['settings'] = ConfigParser()
#if not exist what is ?????
environment['settings'].read(settingConfigPath)
return environment
@ -152,40 +129,14 @@ class settingsManager():
value = self.settings[section][setting]
return value
def loadSpeechDriver(self, environment, driverName):
if environment['runtime']['speechDriver'] != None:
environment['runtime']['speechDriver'].shutdown()
spec = importlib.util.spec_from_file_location(driverName, 'speech/' + driverName + '.py')
def loadDriver(self, environment, driverName, driverType):
if environment['runtime'][driverType] != None:
environment['runtime'][driverType].shutdown()
spec = importlib.util.spec_from_file_location(driverName, driverType + '/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['speechDriver'] = driver_mod.speech()
environment['runtime']['speechDriver'].initialize(environment)
return environment
def loadSoundDriver(self, environment, driverName):
if environment['runtime']['soundDriver'] != None:
environment['runtime']['soundDriver'].shutdown()
spec = importlib.util.spec_from_file_location(driverName, 'sound/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['soundDriver'] = driver_mod.sound()
environment['runtime']['soundDriver'].initialize(environment)
return environment
def loadScreenDriver(self, environment, driverName):
spec = importlib.util.spec_from_file_location(driverName, 'screen/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen()
environment['runtime']['screenDriver'].initialize(environment)
return environment
def loadInputDriver(self, environment, driverName):
spec = importlib.util.spec_from_file_location(driverName, 'input/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['inputDriver'] = driver_mod.input()
environment['runtime']['inputDriver'].initialize(environment)
environment['runtime'][driverType] = driver_mod.driver()
environment['runtime'][driverType].initialize(environment)
return environment
def setFenrirKeys(self, environment, keys):
@ -204,15 +155,17 @@ class settingsManager():
except:
return ''
def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/config/', settingsFile='settings.conf'):
def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/', settingsFile='settings.conf'):
if not os.path.exists(settingsRoot):
if os.path.exists('../../config/'):
settingsRoot = '../../config/'
else:
return None
environment['runtime']['settingsManager'] = self
environment['runtime']['debug'] = debug.debug()
return None
environment['runtime']['debug'] = debug.debug()
environment['runtime']['settingsManager'] = self
environment = environment['runtime']['settingsManager'].loadSettings(environment, settingsRoot + '/settings/' + settingsFile)
if environment == None:
return None
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')):
@ -248,14 +201,14 @@ class settingsManager():
environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
environment = environment['runtime']['settingsManager'].loadSpeechDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'))
environment = environment['runtime']['settingsManager'].loadScreenDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'))
environment = environment['runtime']['settingsManager'].loadSoundDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'))
environment = environment['runtime']['settingsManager'].loadInputDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'))
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'), 'speechDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'), 'screenDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'), 'soundDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'), 'inputDriver')
environment['runtime']['debug'].writeDebugOut(environment,'\/-------environment-------\/',debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(environment),debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,'\/-------settings.conf-------\/',debug.debugLevel.ERROR)

View File

@ -9,7 +9,6 @@ import os, sys, signal, time
if not os.getcwd() in sys.path:
sys.path.append(os.getcwd())
from core import environment
from core import settingsManager
from utils import debug
@ -61,13 +60,17 @@ class fenrir():
def shutdown(self):
self.environment['runtime']['outputManager'].presentText(self.environment, "Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True)
if self.environment['runtime']['debug'] != None:
self.environment['runtime']['debug'].closeDebugFile()
if self.environment['runtime']['soundDriver'] != None:
self.environment['runtime']['soundDriver'].shutdown(environment)
if self.environment['runtime']['speechDriver'] != None:
self.environment['runtime']['speechDriver'].shutdown(environment)
self.environment['runtime']['inputManager'].releaseDevices(self.environment)
if self.environment['runtime']['screenDriver']:
self.environment['runtime']['screenDriver'].shutdown(self.environment)
self.environment['runtime']['inputManager'].releaseDevices(self.environment)
if self.environment['runtime']['inputDriver']:
self.environment['runtime']['inputDriver'].shutdown(self.environment)
if self.environment['runtime']['soundDriver']:
self.environment['runtime']['soundDriver'].shutdown(self.environment)
if self.environment['runtime']['speechDriver']:
self.environment['runtime']['speechDriver'].shutdown(self.environment)
if self.environment['runtime']['debug']:
self.environment['runtime']['debug'].closeDebugFile()
self.environment = None
app = fenrir()

View File

@ -1,73 +0,0 @@
#!/bin/python
import evdev
from evdev import InputDevice, UInput
from select import select
import time
from utils import debug
class input():
def __init__(self):
self.iDevices = {}
self.uDevices = {}
self.getInputDevices()
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def getInput(self, environment):
event = None
r, w, x = select(self.iDevices, [], [], environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'screen', 'screenUpdateDelay'))
print(len(list(r)))
if r != []:
for fd in r:
event = self.iDevices[fd].read_one()
return event
return None
def writeUInput(self, uDevice, event,environment):
uDevice.write_event(event)
uDevice.syn()
def getInputDevices(self):
self.iDevices = map(evdev.InputDevice, (evdev.list_devices()))
self.iDevices = {dev.fd: dev for dev in self.iDevices if 1 in dev.capabilities()}
def grabDevices(self):
for fd in self.iDevices:
dev = self.iDevices[fd]
cap = dev.capabilities()
del cap[0]
self.uDevices[fd] = UInput(
cap,
dev.name,
#dev.info.vendor,
#dev.info.product,
#dev.version,
#dev.info.bustype,
#'/dev/uinput'
)
dev.grab()
def releaseDevices(self):
for fd in self.iDevices:
try:
self.iDevices[fd].ungrab()
except:
pass
try:
self.iDevices[fd].close()
except:
pass
try:
self.uDevices[fd].close()
except:
pass
self.iDevices.clear()
self.uDevices.clear()
def __del__(self):
self.releaseDevices()

View File

@ -1,116 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
import difflib
from utils import debug
class screen():
def __init__(self):
self.vcsaDevicePath = '/dev/vcsa'
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def insert_newlines(self, string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
def getCurrScreen(self):
currScreen = -1
try:
currScreenFile = open('/sys/devices/virtual/tty/tty0/active','r')
currScreen = currScreenFile.read()[3:-1]
currScreenFile.close()
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
return currScreen
def getIgnoreScreens(self):
xlist = []
try:
x = subprocess.Popen('ps a -o tty,comm | grep -e irssi | grep -v "grep -e irssi"', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n')
except:
return xlist
for i in x:
if x[:3].upper() == 'TTY':
xlist.append(i[4])
return xlist
def update(self, environment, trigger='updateScreen'):
newTTY = ''
newContentBytes = b''
try:
# read screen
newTTY = self.getCurrScreen()
vcsa = open(self.vcsaDevicePath + newTTY,'rb',0)
newContentBytes = vcsa.read()
vcsa.close()
if len(newContentBytes) < 5:
return environment
except Exception as e:
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
return environment
screenEncoding = environment['runtime']['settingsManager'].getSetting(environment,'screen', 'encoding')
# set new "old" values
environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']
environment['screenData']['oldContentText'] = environment['screenData']['newContentText']
environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib']
environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x']
environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y']
if environment['screenData']['oldTTY'] == '-1':
environment['screenData']['oldTTY'] = newTTY # dont recognice starting fenrir as change
else:
environment['screenData']['oldTTY'] = environment['screenData']['newTTY']
environment['screenData']['oldDelta'] = environment['screenData']['newDelta']
environment['screenData']['oldNegativeDelta'] = environment['screenData']['newNegativeDelta']
environment['screenData']['newTTY'] = newTTY
environment['screenData']['newContentBytes'] = newContentBytes
# get metadata like cursor or screensize
environment['screenData']['lines'] = int( environment['screenData']['newContentBytes'][0])
environment['screenData']['columns'] = int( environment['screenData']['newContentBytes'][1])
environment['screenData']['newCursor']['x'] = int( environment['screenData']['newContentBytes'][2])
environment['screenData']['newCursor']['y'] = int( environment['screenData']['newContentBytes'][3])
# analyze content
environment['screenData']['newContentText'] = environment['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2]
environment['screenData']['newContentText'] = self.insert_newlines(environment['screenData']['newContentText'], environment['screenData']['columns'])
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
environment['screenData']['oldContentBytes'] = b''
environment['screenData']['oldContentAttrib'] = b''
environment['screenData']['oldContentText'] = ''
environment['screenData']['oldCursor']['x'] = 0
environment['screenData']['oldCursor']['y'] = 0
environment['screenData']['oldDelta'] = ''
environment['screenData']['oldNegativeDelta'] = ''
# always clear current deltas
environment['screenData']['newNegativeDelta'] = ''
environment['screenData']['newDelta'] = ''
# changes on the screen
if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \
(environment['screenData']['newContentText'] != '' ):
if environment['screenData']['oldContentText'] == '' and\
environment['screenData']['newContentText'] != '':
environment['screenData']['newDelta'] = environment['screenData']['newContentText']
else:
diffStart = 0
if environment['screenData']['oldCursor']['x'] != environment['screenData']['newCursor']['x'] and \
environment['screenData']['oldCursor']['y'] == environment['screenData']['newCursor']['y'] and \
environment['screenData']['newContentText'][:environment['screenData']['newCursor']['y']] == environment['screenData']['oldContentText'][:environment['screenData']['newCursor']['y']]:
diffStart = environment['screenData']['newCursor']['y'] * environment['screenData']['columns'] + environment['screenData']['newCursor']['y']
diff = difflib.ndiff(environment['screenData']['oldContentText'][diffStart:diffStart + environment['screenData']['columns']],\
environment['screenData']['newContentText'][diffStart:diffStart + environment['screenData']['columns']])
else:
diff = difflib.ndiff( environment['screenData']['oldContentText'][diffStart:].split('\n'),\
environment['screenData']['newContentText'][diffStart:].split('\n'))
diffList = list(diff)
environment['screenData']['newDelta'] = ''.join(x[2:] for x in diffList if x.startswith('+ '))
environment['screenData']['newNegativeDelta'] = ''.join(x[2:] for x in diffList if x.startswith('- '))
return environment

View File

@ -1,103 +0,0 @@
import gi
import time
from gi.repository import GLib
try:
gi.require_version('Gst', '1.0')
from gi.repository import Gst
except:
_gstreamerAvailable = False
else:
_gstreamerAvailable, args = Gst.init_check(None)
class sound:
def __init__(self):
self._initialized = False
self._source = None
self._sink = None
self.volume = 1
if not _gstreamerAvailable:
return
def initialize(self, environment):
if self._initialized:
return environment
if not _gstreamerAvailable:
return environment
self._player = Gst.ElementFactory.make('playbin', 'player')
bus = self._player.get_bus()
bus.add_signal_watch()
bus.connect("message", self._onPlayerMessage)
self._pipeline = Gst.Pipeline(name='fenrir-pipeline')
bus = self._pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", self._onPipelineMessage)
self._source = Gst.ElementFactory.make('audiotestsrc', 'src')
self._sink = Gst.ElementFactory.make('autoaudiosink', 'output')
self._pipeline.add(self._source)
self._pipeline.add(self._sink)
self._source.link(self._sink)
self._initialized = True
return environment
def shutdown(self, environment):
return environment
def _onPlayerMessage(self, bus, message):
if message.type == Gst.MessageType.EOS:
self._player.set_state(Gst.State.NULL)
elif message.type == Gst.MessageType.ERROR:
self._player.set_state(Gst.State.NULL)
error, info = message.parse_error()
print(error, info)
print('_onPlayerMessage')
def _onPipelineMessage(self, bus, message):
if message.type == Gst.MessageType.EOS:
self._pipeline.set_state(Gst.State.NULL)
elif message.type == Gst.MessageType.ERROR:
self._pipeline.set_state(Gst.State.NULL)
error, info = message.parse_error()
print(error, info)
print('_onPipelineMessage')
def _onTimeout(self, element):
element.set_state(Gst.State.NULL)
return False
def playSoundFile(self, fileName, interrupt=True):
if interrupt:
self.cancel()
self._player.set_property('uri', 'file://%s' % fileName)
self._player.set_state(Gst.State.PLAYING)
print('playSoundFile')
def playFrequence(self, frequence, duration, adjustVolume, interrupt=True):
if interrupt:
self.cancel()
self._source.set_property('volume', tone.volume)
self._source.set_property('freq', tone.frequency)
self._source.set_property('wave', tone.wave)
self._pipeline.set_state(Gst.State.PLAYING)
duration = int(1000 * tone.duration)
GLib.timeout_add(duration, self._onTimeout, self._pipeline)
def cancel(self, element=None):
if not _gstreamerAvailable:
return
if element:
element.set_state(Gst.State.NULL)
return
self._player.set_state(Gst.State.NULL)
self._pipeline.set_state(Gst.State.NULL)
def setVolume(self, volume):
self.volume = volume
def shutdown(self):
global _gstreamerAvailable
if not _gstreamerAvailable:
return
self.cancel()
self._initialized = False
_gstreamerAvailable = False

View File

@ -1,20 +0,0 @@
#!/bin/python
import subprocess
class sound():
def __init__(self):
self.volume = 1.0;
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def playFrequence(self, frequence, duration, adjustVolume):
pass
def playSoundFile(self, filePath, interrupt = True):
self.proc = subprocess.Popen("play -q -v " + str(self.volume ) + ' ' + filePath, shell=True)
def cancel(self):
pass
def setCallback(self, callback):
pass
def setVolume(self, volume):
self.volume = volume

View File

@ -1,3 +0,0 @@
espeak = espeak driver
speechd = speech-dispatcher driver
generic = generic driver via /bin/say

View File

@ -1,69 +0,0 @@
#!/usr/bin/python
# Espeak driver
class speech():
def __init__(self ):
self._es = None
self._isInitialized = False
try:
from espeak import espeak
self._es = espeak
self._isInitialized = True
except:
self._initialized = False
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def speak(self,text, queueable=True):
if not self._isInitialized:
return False
if not queueable:
self.cancel()
self._es.synth(text)
return True
def cancel(self):
if not self._isInitialized:
return False
self._es.cancel()
return True
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return False
return True
def setVoice(self, voice):
if not self._isInitialized:
return False
return self._es.set_voice(voice)
def setPitch(self, pitch):
if not self._isInitialized:
return False
def setRate(self, rate):
if not self._isInitialized:
return False
return self._es.set_parameter(self._es.Parameter().Rate, int(rate*450 + 80))
return self._es.set_parameter(self._es.Parameter().Pitch, int(pitch * 99))
def setModule(self, module):
if not self._isInitialized:
return False
def setLanguage(self, language):
if not self._isInitialized:
return False
return self._es.set_voice(language)
def setVolume(self, volume):
if not self._isInitialized:
return False
return self._es.set_parameter(self._es.Parameter().Volume, int(volume * 200))

View File

@ -1,61 +0,0 @@
#!/usr/bin/python
# generic driver
class speech():
def __init__(self ):
pass
def initialize(self, environment):
self._isInitialized = False
return environment
def shutdown(self, environment):
return environment
def speak(self,text, queueable=True):
if not self._isInitialized:
return False
if not queueable:
self.cancel()
return True
def cancel(self):
if not self._isInitialized:
return False
return True
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return False
return True
def setVoice(self, voice):
if not self._isInitialized:
return False
return True
def setPitch(self, pitch):
if not self._isInitialized:
return False
return True
def setRate(self, rate):
if not self._isInitialized:
return False
return True
def setModule(self, module):
if not self._isInitialized:
return False
def setLanguage(self, language):
if not self._isInitialized:
return False
return True
def setVolume(self, volume):
if not self._isInitialized:
return False
return True

View File

@ -1,97 +0,0 @@
#!/usr/bin/python
# speech-dispatcher driver
class speech():
def __init__(self ):
self._sd = None
self._isInitialized = False
self._language = ''
try:
import speechd
self._sd = speechd.SSIPClient('fenrir')
self._isInitialized = True
except:
self._initialized = False
def initialize(self, environment):
return environment
def shutdown(self, environment):
if not self._isInitialized:
return environment
self._isInitialized = False
self.cancel()
self._sd.close()
return environment
def speak(self,text, queueable=True):
if not self._isInitialized:
return False
if queueable == False: self.cancel()
try:
self._sd.set_synthesis_voice(self._language)
except:
pass
self._sd.speak(text)
return True
def cancel(self):
if not self._isInitialized:
return False
self._sd.cancel()
return True
def setCallback(self, callback):
pass
def clear_buffer(self):
if not self._isInitialized:
return False
return True
def setVoice(self, voice):
if not self._isInitialized:
return False
try:
if voice != '':
self._sd.set_voice(voice)
return True
except:
return False
def setPitch(self, pitch):
if not self._isInitialized:
return False
try:
self._sd.set_pitch(int(-100 + pitch * 200))
return True
except:
return False
def setRate(self, rate):
if not self._isInitialized:
return False
try:
self._sd.set_rate(int(-100 + rate * 200))
return True
except:
return False
def setModule(self, module):
if not self._isInitialized:
return False
try:
self._sd.set_output_module(module)
return True
except:
return False
def setLanguage(self, language):
if not self._isInitialized:
return False
self._language = language
def setVolume(self, volume):
if not self._isInitialized:
return False
self._sd.set_volume(int(-100 + volume * 200))