Revision e21d7f2c tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py
tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py | ||
---|---|---|
34 | 34 |
import actionlib |
35 | 35 |
from io import BytesIO |
36 | 36 |
import wave |
37 |
import os |
|
38 |
import pkgutil |
|
37 | 39 |
from MaryTTSClient import * |
38 | 40 |
from cStringIO import StringIO |
39 | 41 |
|
... | ... | |
116 | 118 |
for line in sio: |
117 | 119 |
if (line[0] != '#'): |
118 | 120 |
phoneme_list = line.split(" ") |
119 |
symbol = phoneme_list[2] |
|
120 |
symbol = symbol.rstrip() |
|
121 |
|
|
122 |
now = float(phoneme_list[0]) |
|
123 |
duration = (now - last)*1000 |
|
124 |
last = now |
|
125 |
plist.append(phoneme(symbol, int(duration))) |
|
121 |
if (line == '\n'): |
|
122 |
#ignore empty lines |
|
123 |
continue |
|
124 |
elif (len(phoneme_list) != 3): |
|
125 |
print("> could not split line '%s' during phoneme seperation\n" % (line)) |
|
126 |
else: |
|
127 |
symbol = phoneme_list[2] |
|
128 |
symbol = symbol.rstrip() |
|
129 |
|
|
130 |
now = float(phoneme_list[0]) |
|
131 |
duration = (now - last)*1000 |
|
132 |
last = now |
|
133 |
plist.append(phoneme(symbol, int(duration))) |
|
126 | 134 |
|
127 | 135 |
self.logger.info("created phonemelist with " + str(len(plist)) + " elements") |
128 | 136 |
|
... | ... | |
137 | 145 |
self.logger.info("created utterance for 'phonemelist with '" + u.text + "'") |
138 | 146 |
return u |
139 | 147 |
|
148 |
def get_error_message(self): |
|
149 |
data_wav = pkgutil.get_data('mary_tts_bridge', 'data/connection_failed.wav') |
|
150 |
data_phonemes = pkgutil.get_data('mary_tts_bridge', 'data/connection_failed.phonemes') |
|
151 |
return (data_wav, data_phonemes) |
|
152 |
|
|
140 | 153 |
def execute_cb(self, goal): |
141 | 154 |
self.logger.info("incoming utterance '" + goal.text + "'") |
142 | 155 |
|
... | ... | |
150 | 163 |
|
151 | 164 |
except: |
152 | 165 |
self.logger.error("failed to create utterance error = '" + str(sys.exc_info()[1]) + "'") |
153 |
success = False |
|
166 |
#try to open error message from file: |
|
167 |
success = True |
|
168 |
(audio, phonelist) = self.get_error_message() |
|
154 | 169 |
|
155 | 170 |
if success: |
156 | 171 |
#build soundchunk |
Also available in: Unified diff