speechDriver/genericDriver.py: avoid the shell and stay safe.
This commit is contained in:
parent
2f15dc945b
commit
6abc39e687
@ -8,6 +8,7 @@
|
|||||||
from core import debug
|
from core import debug
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
|
import shlex
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from core.speechDriver import speechDriver
|
from core.speechDriver import speechDriver
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ class driver(speechDriver):
|
|||||||
|
|
||||||
self.speechCommand = self.env['runtime']['settingsManager'].getSetting('speech', 'genericSpeechCommand')
|
self.speechCommand = self.env['runtime']['settingsManager'].getSetting('speech', 'genericSpeechCommand')
|
||||||
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"'
|
||||||
@ -140,19 +141,21 @@ class driver(speechDriver):
|
|||||||
if utterance[key] == '':
|
if utterance[key] == '':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
popenSpeechCommand = self.speechCommand
|
popenSpeechCommand = shlex.split(self.speechCommand)
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirVolume', str(utterance['volume'] ).replace('"',''))
|
for idx, word in enumerate(popenSpeechCommand):
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirModule', str(utterance['module']).replace('"',''))
|
word = word.replace('fenrirVolume', str(utterance['volume'] ))
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirLanguage', str(utterance['language']).replace('"',''))
|
word = word.replace('fenrirModule', str(utterance['module']))
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirVoice', str(utterance['voice']).replace('"',''))
|
word = word.replace('fenrirLanguage', str(utterance['language']))
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirPitch', str(utterance['pitch']).replace('"',''))
|
word = word.replace('fenrirVoice', str(utterance['voice']))
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirRate', str(utterance['rate']).replace('"',''))
|
word = word.replace('fenrirPitch', str(utterance['pitch']))
|
||||||
popenSpeechCommand = popenSpeechCommand.replace('fenrirText', str(utterance['text']).replace('"','').replace('\n',''))
|
word = word.replace('fenrirRate', str(utterance['rate']))
|
||||||
|
word = word.replace('fenrirText', str(utterance['text']))
|
||||||
|
popenSpeechCommand[idx] = word
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.env['runtime']['debug'].writeDebugOut('speechDriver:worker:' + 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, shell=True)
|
self.proc = Popen(popenSpeechCommand, shell=False)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
self.proc.wait()
|
self.proc.wait()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user