work on generic speech driver

This commit is contained in:
chrys 2017-03-02 22:26:36 +01:00
parent b5ec64bb13
commit 15f6a4c027

View File

@ -8,8 +8,9 @@
from core import debug from core import debug
from threading import Thread from threading import Thread
from queue import Queue, Empty from queue import Queue, Empty
#import subprocess, os import time
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import subprocess
class speakQueue(Queue): class speakQueue(Queue):
def clear(self): def clear(self):
@ -43,7 +44,7 @@ class driver():
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 "fenrirText"' self.speechCommand = 'spd-say --wait -r 100 -i 100 "fenrirText"'
self._isInitialized = True self._isInitialized = True
if self._isInitialized: if self._isInitialized:
@ -75,7 +76,9 @@ class driver():
return return
self.clear_buffer() self.clear_buffer()
if self.proc: if self.proc:
self.proc.terminate()
self.proc.kill() self.proc.kill()
self.proc = None
def setCallback(self, callback): def setCallback(self, callback):
print('SpeechDummyDriver: setCallback') print('SpeechDummyDriver: setCallback')
@ -83,7 +86,6 @@ class driver():
def clear_buffer(self): def clear_buffer(self):
if not self._isInitialized: if not self._isInitialized:
return return
if not self.textQueue.not_empty:
self.textQueue.clear() self.textQueue.clear()
def setVoice(self, voice): def setVoice(self, voice):
if not self._isInitialized: if not self._isInitialized:
@ -118,6 +120,7 @@ class driver():
def worker(self): def worker(self):
while True: while True:
utterance = self.textQueue.get() utterance = self.textQueue.get()
if isinstance(utterance, int): if isinstance(utterance, int):
if utterance == -1: if utterance == -1:
return return
@ -129,7 +132,7 @@ class driver():
utterance[key] = '' utterance[key] = ''
if not utterance[key]: if not utterance[key]:
utterance[key] = '' utterance[key] = ''
print(utterance) utterance = utterance.copy()
popenSpeechCommand = self.speechCommand popenSpeechCommand = self.speechCommand
popenSpeechCommand = popenSpeechCommand.replace('fenrirVolume', str(utterance['volume'] ).replace('"','')) popenSpeechCommand = popenSpeechCommand.replace('fenrirVolume', str(utterance['volume'] ).replace('"',''))
popenSpeechCommand = popenSpeechCommand.replace('fenrirModule', str(utterance['module']).replace('"','')) popenSpeechCommand = popenSpeechCommand.replace('fenrirModule', str(utterance['module']).replace('"',''))
@ -140,15 +143,13 @@ class driver():
popenSpeechCommand = popenSpeechCommand.replace('fenrirText', str(utterance['text']).replace('"','').replace('\n','')) popenSpeechCommand = popenSpeechCommand.replace('fenrirText', str(utterance['text']).replace('"','').replace('\n',''))
try: try:
s = time.time()
#subprocess.check_call(popenSpeechCommand,shell=True)
self.proc = Popen(popenSpeechCommand , stdout=PIPE, stderr=PIPE, shell=True) self.proc = Popen(popenSpeechCommand , stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = self.proc.communicate() self.proc.wait()
screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding') self.proc = None
stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') print(popenSpeechCommand)
stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') print('run',time.time() -s)
if stderr != '':
print('err' + stderr)
if stdout != '':
print('out' + stdout)
except Exception as e: except Exception as e:
print('except' + str(e)) print('except' + str(e))