improve emacspeak driver

This commit is contained in:
chrys 2017-10-22 23:35:47 +02:00
parent b836d3c370
commit 1e195ee063

View File

@ -9,6 +9,7 @@ from core import debug
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import pexpect import pexpect
import sys import sys
import time
class driver(): class driver():
def __init__(self): def __init__(self):
@ -35,9 +36,14 @@ class driver():
if not queueable: if not queueable:
self.cancel() self.cancel()
try: try:
self.server.sendline('tts_say ' + '\"' + text +'\"') cleanText = text.replace('}', '\}')
cleanText = cleanText.replace('{', '\{')
cleanText = cleanText.replace('*', '\*')
cleanText = cleanText.replace('"', '\"')
cleanText = cleanText.replace('\n', ' ')
cleanText = cleanText.replace('[', '\[')
#print(text.replace('"', '\\\"')) #print(text.replace('"', '\\\"'))
self.server.sendline('tts_say ' + '"' + text.replace('"', '\"') +'"') self.server.sendline('tts_say ' + '"' + 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)
@ -67,7 +73,7 @@ class driver():
if not self._isInitialized: if not self._isInitialized:
return return
try: try:
self.server.sendline('tts_set_speech_rate' + str(int(rate * 500))) 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)
@ -76,6 +82,6 @@ class driver():
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): def setVolume(self, volume):
pass pass