summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-09-12 17:56:22 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2014-09-12 18:09:49 +0200
commit2089e7b6c4a42b6f028b11aaaa505694e4d9ae43 (patch)
treef9c0a52c85a138fc9fae86063e906b6796df50b8
parent013d42ca921432ac5513d9c9b2427b3ffe0bb8a0 (diff)
downloadjasper-client-2089e7b6c4a42b6f028b11aaaa505694e4d9ae43.tar.gz
jasper-client-2089e7b6c4a42b6f028b11aaaa505694e4d9ae43.zip
Make FST model used for PocketSphinxSTT configurable
-rw-r--r--client/g2p.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/client/g2p.py b/client/g2p.py
index 3225c73..87e8b0d 100644
--- a/client/g2p.py
+++ b/client/g2p.py
@@ -3,10 +3,22 @@ import os
import tempfile
import subprocess
import re
+import yaml
PHONE_MATCH = re.compile(r'<s> (.*) </s>')
-PHONETISAURUS_PATH = os.environ['JASPER_HOME'] + "/phonetisaurus"
+FST_MODEL = None
+
+# Try to get fst_model from config
+profile_path = os.path.join(os.path.dirname(__file__),'profile.yml')
+if os.path.exists(profile_path):
+ with open(profile_path, 'r') as f:
+ profile = yaml.safe_load(f)
+ if 'pocketsphinx' in profile and 'fst_model' in profile['pocketsphinx']:
+ FST_MODEL = profile['pocketsphinx']['fst_model']
+
+if not FST_MODEL:
+ FST_MODEL = os.environ['JASPER_HOME'] + "/phonetisaurus/g014b2b.fst"
def parseLine(line):
return PHONE_MATCH.search(line).group(1)
@@ -17,8 +29,7 @@ def parseOutput(output):
def translateWord(word):
- out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' %
- PHONETISAURUS_PATH + "/g014b2b.fst", '--input=%s' % word])
+ out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' % FST_MODEL, '--input=%s' % word])
return parseLine(out)
@@ -36,8 +47,7 @@ def translateWords(words):
def translateFile(input_filename, output_filename=None):
- out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' %
- PHONETISAURUS_PATH + "/g014b2b.fst", '--input=%s' % input_filename, '--words', '--isfile'])
+ out = subprocess.check_output(['phonetisaurus-g2p', '--model=%s' % FST_MODEL, '--input=%s' % input_filename, '--words', '--isfile'])
out = parseOutput(out)
if output_filename: