Author: remi
Date: 2008-12-18 03:12:01 +0100 (Thu, 18 Dec 2008)
New Revision: 3160
Modified:
software_suite_v2/tuxware/tuxhttpserver/trunk/src/resources/ResourceTTS.py
Log:
* added the tuxosl running state check
Modified:
software_suite_v2/tuxware/tuxhttpserver/trunk/src/resources/ResourceTTS.py
===================================================================
--- software_suite_v2/tuxware/tuxhttpserver/trunk/src/resources/ResourceTTS.py
2008-12-18 02:11:16 UTC (rev 3159)
+++ software_suite_v2/tuxware/tuxhttpserver/trunk/src/resources/ResourceTTS.py
2008-12-18 02:12:01 UTC (rev 3160)
@@ -9,14 +9,14 @@
self.__stackMutex = threading.Lock()
self.__stackSFlag = False
self.__stackThread = None
-
+
def __setStarted(self, value):
'''
'''
self.__stackMutex.acquire()
self.__stackSFlag = value
self.__stackMutex.release()
-
+
def __getStarted(self):
'''
'''
@@ -24,7 +24,7 @@
value = self.__stackSFlag
self.__stackMutex.release()
return value
-
+
def flush(self):
'''
'''
@@ -32,17 +32,17 @@
self.__stack = []
self.__stackMutex.release()
Glb_tuxApi.tts.stop()
-
+
def push(self, text):
'''
'''
if len(text) == 0:
return
-
+
self.__stackMutex.acquire()
self.__stack.append(text)
self.__stackMutex.release()
-
+
def __pop(self):
'''
'''
@@ -53,7 +53,7 @@
self.__stackMutex.release()
return text
-
+
def __getTTSState(self):
'''
'''
@@ -61,12 +61,12 @@
state = Glb_TuxOSL.GetStatusStruct(ret)
print state['value']
return state['value']
-
+
def __popLoop(self):
'''
'''
self.__setStarted(True)
-
+
while self.__getStarted():
ret = self.__pop()
if ret != "":
@@ -74,23 +74,23 @@
Glb_tuxApi.tts.speak(ret)
Glb_tuxApi.event.setDelay(1.0)
time.sleep(0.5)
-
+
def start(self):
'''
'''
self.__stackThread = threading.Thread(target = self.__popLoop)
self.__stackThread.start()
-
+
def stop(self):
'''
'''
self.__setStarted(False)
-
+
if self.__stackThread != None:
if self.__stackThread.isAlive():
Glb_tuxApi.tts.stop()
self.__stackThread.join()
-
+
Glb_TTSStack = TTSSpeakStack()
Glb_TTSStack.start()
@@ -103,14 +103,14 @@
p_fmt = {
'text' : 'string',
}
-
+
if not Glb_DonglePresent:
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
-
+
result, params = parseParameters(parameters, p_fmt)
-
+
if result:
text = params['text']
try:
@@ -118,17 +118,17 @@
text = u.encode("cp1252", "replace")
except:
pass
-
+
Glb_TTSStack.push(text)
else:
content_struct['root']['result'] = \
getStrError(E_TDREST_INVALIDPARAMETERS)
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/stack_speak?',
+
+Glb_ServiceContainer.createService('/tts/stack_speak?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_stack_speak,
"TTS",
@@ -143,22 +143,22 @@
def funct_tts_stack_flush(id_client, parameters):
content_struct = copy.deepcopy(DEFAULT_CONTENT_STRUCT)
content_struct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-
+
if not Glb_DonglePresent:
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
Glb_TTSStack.flush()
-
+
cmd_rsp = {'cmd_answer' : True}
content_struct['root']['data'] = cmd_rsp
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/stack_flush?',
+
+Glb_ServiceContainer.createService('/tts/stack_flush?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_stack_flush,
"TTS",
@@ -173,14 +173,14 @@
p_fmt = {
'text' : 'string',
}
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
-
+
result, params = parseParameters(parameters, p_fmt)
-
+
if result:
text = params['text']
try:
@@ -195,12 +195,12 @@
else:
content_struct['root']['result'] = \
getStrError(E_TDREST_INVALIDPARAMETERS)
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/speak?',
+
+Glb_ServiceContainer.createService('/tts/speak?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_speak,
"TTS",
@@ -218,14 +218,14 @@
p_fmt = {
'value' : 'int',
}
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
-
+
result, params = parseParameters(parameters, p_fmt)
-
+
if result:
Glb_tuxApi.tts.setPitch(int(params['value']))
cmd = 'OSL_CMD:TTS:SET_PITCH:%d' % (params['value'])
@@ -235,12 +235,12 @@
else:
content_struct['root']['result'] = \
getStrError(E_TDREST_INVALIDPARAMETERS)
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/pitch?',
+
+Glb_ServiceContainer.createService('/tts/pitch?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_pitch,
"TTS",
@@ -259,14 +259,14 @@
p_fmt = {
'value' : '<True|False>',
}
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
-
+
result, params = parseParameters(parameters, p_fmt)
-
+
if result:
cmd = 'OSL_CMD:TTS:SET_PAUSE:%s' % (params['value'])
ret = Glb_TuxOSL.PerformCommand(0.0, cmd)
@@ -275,12 +275,12 @@
else:
content_struct['root']['result'] = \
getStrError(E_TDREST_INVALIDPARAMETERS)
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/pause?',
+
+Glb_ServiceContainer.createService('/tts/pause?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_pause,
"TTS",
@@ -295,23 +295,23 @@
def funct_tts_stop(id_client, parameters):
content_struct = copy.deepcopy(DEFAULT_CONTENT_STRUCT)
content_struct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
cmd = 'OSL_CMD:TTS:STOP'
ret = Glb_TuxOSL.PerformCommand(0.0, cmd)
-
+
cmd_rsp = {'cmd_answer' : ret}
content_struct['root']['data'] = cmd_rsp
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/stop?',
+
+Glb_ServiceContainer.createService('/tts/stop?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_stop,
"TTS",
@@ -326,14 +326,14 @@
p_fmt = {
'name' : 'string',
}
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
-
+
result, params = parseParameters(parameters, p_fmt)
-
+
if result:
if params['name'].find('8k') == -1:
params['name'] = params['name'] + '8k'
@@ -345,12 +345,12 @@
else:
content_struct['root']['result'] = \
getStrError(E_TDREST_INVALIDPARAMETERS)
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/locutor?',
+
+Glb_ServiceContainer.createService('/tts/locutor?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_locutor,
"TTS",
@@ -365,8 +365,8 @@
def funct_tts_voices(id_client, parameters):
content_struct = copy.deepcopy(DEFAULT_CONTENT_STRUCT)
content_struct['root']['result'] = getStrError(E_TDREST_SUCCESS)
-
- if not Glb_DonglePresent:
+
+ if not Glb_DonglePresent or not Glb_TuxOSL.getStarted():
content_struct['root']['result'] = getStrError(E_TDREST_FAILED)
content = structToXML(content_struct, True)
return DEFAULT_HEADERS, content
@@ -375,9 +375,9 @@
id = Glb_TuxOSL.GetStatusId('tts_0_voice_list')
state = Glb_TuxOSL.GetStatusState(id)
state = Glb_TuxOSL.GetStatusStruct(state)
-
+
voices = state['value'][1:-1].split(',')
-
+
i = 0
for voice in voices:
if len(voice) < 2:
@@ -385,12 +385,12 @@
d_name = "data|%d" % i
i += 1
content_struct['root'][d_name] = {'locutor' : voice,}
-
+
content = structToXML(content_struct, True)
-
+
return DEFAULT_HEADERS, content
-
-Glb_ServiceContainer.createService('/tts/voices?',
+
+Glb_ServiceContainer.createService('/tts/voices?',
TDCC_LEVEL_FREE_CLIENT,
funct_tts_voices,
"TTS",
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn