summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2015-01-12 13:35:20 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2015-01-12 13:35:20 +0100
commit7475cf0b7f0076d5e6b78ee3961697f70b630ef9 (patch)
tree962001a80ddee7f00404a7542a2783922490c441
parent051e1f7aec42dc9bed13a6caddb465ac20f8df17 (diff)
downloadjasper-client-7475cf0b7f0076d5e6b78ee3961697f70b630ef9.tar.gz
jasper-client-7475cf0b7f0076d5e6b78ee3961697f70b630ef9.zip
Julius STT error logging improved
-rw-r--r--client/stt.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/client/stt.py b/client/stt.py
index fc1452a..c192e6a 100644
--- a/client/stt.py
+++ b/client/stt.py
@@ -195,6 +195,31 @@ class JuliusSTT(AbstractSTTEngine):
self._tiedlist = tiedlist
self._pattern = re.compile(r'sentence(\d+): <s> (.+) </s>')
+ # Inital test run: we run this command once to log errors/warnings
+ cmd = ['julius',
+ '-input', 'stdin',
+ '-dfa', self._vocabulary.dfa_file,
+ '-v', self._vocabulary.dict_file,
+ '-h', self._hmmdefs,
+ '-hlist', self._tiedlist,
+ '-forcedict']
+ cmd = [str(x) for x in cmd]
+ self._logger.debug('Executing: %r', cmd)
+ with tempfile.SpooledTemporaryFile() as out_f:
+ with tempfile.SpooledTemporaryFile() as f:
+ with tempfile.SpooledTemporaryFile() as err_f:
+ subprocess.call(cmd, stdin=f, stdout=out_f, stderr=err_f)
+ out_f.seek(0)
+ for line in out_f.read().splitlines():
+ line = line.strip()
+ if len(line) > 7 and line[:7].upper() == 'ERROR: ':
+ if not line[7:].startswith('adin_'):
+ self._logger.error(line[7:])
+ elif len(line) > 9 and line[:9].upper() == 'WARNING: ':
+ self._logger.warning(line[9:])
+ elif len(line) > 6 and line[:6].upper() == 'STAT: ':
+ self._logger.debug(line[6:])
+
@classmethod
def get_config(cls):
# FIXME: Replace this as soon as we have a config module
@@ -225,21 +250,15 @@ class JuliusSTT(AbstractSTTEngine):
'-forcedict']
cmd = [str(x) for x in cmd]
self._logger.debug('Executing: %r', cmd)
- transcribed = []
with tempfile.SpooledTemporaryFile() as out_f:
with tempfile.SpooledTemporaryFile() as err_f:
subprocess.call(cmd, stdin=fp, stdout=out_f, stderr=err_f)
out_f.seek(0)
- output = out_f.read()
- for line in output.splitlines():
- line = line.strip()
- if line:
- if line.startswith('sentence'):
- print(line)
- matchobj = self._pattern.search(line)
- if matchobj and matchobj.groups(1):
- transcribed.append(matchobj.group(2))
- self._logger.debug(line)
+ results = [(int(i), text) for i, text in
+ self._pattern.findall(out_f.read())]
+ transcribed = [text for i, text in
+ sorted(results, key=lambda x: x[0])
+ if text]
if not transcribed:
transcribed.append('')
self._logger.info('Transcribed: %r', transcribed)