From 2089e7b6c4a42b6f028b11aaaa505694e4d9ae43 Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 12 Sep 2014 17:56:22 +0200 Subject: Make FST model used for PocketSphinxSTT configurable --- client/g2p.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'client') 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' (.*) ') -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: -- cgit v1.3.1 From d24204caa73906a7ad98488281caac8aad6bcaec Mon Sep 17 00:00:00 2001 From: schneefux Date: Fri, 12 Sep 2014 18:02:01 +0200 Subject: Make HMM dir used for PocketSphinxSTT configurable --- client/stt.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'client') diff --git a/client/stt.py b/client/stt.py index e14ab26..d012245 100644 --- a/client/stt.py +++ b/client/stt.py @@ -1,8 +1,10 @@ #!/usr/bin/env python2 # -*- coding: utf-8-*- +import os import traceback import json import requests +import yaml """ The default Speech-to-Text implementation which relies on PocketSphinx. @@ -31,13 +33,24 @@ class PocketSphinxSTT(object): except: import pocketsphinx as ps - hmdir = "/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k" + hmm_dir = None + + # Try to get hmm_dir 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 'hmm_dir' in profile['pocketsphinx']: + hmm_dir = profile['pocketsphinx']['hmm_dir'] + + if not hmm_dir: + hmm_dir = "/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k" if lmd_music and dictd_music: - self.speechRec_music = ps.Decoder(hmm=hmdir, lm=lmd_music, dict=dictd_music) + self.speechRec_music = ps.Decoder(hmm=hmm_dir, lm=lmd_music, dict=dictd_music) self.speechRec_persona = ps.Decoder( - hmm=hmdir, lm=lmd_persona, dict=dictd_persona) - self.speechRec = ps.Decoder(hmm=hmdir, lm=lmd, dict=dictd) + hmm=hmm_dir, lm=lmd_persona, dict=dictd_persona) + self.speechRec = ps.Decoder(hmm=hmm_dir, lm=lmd, dict=dictd) def transcribe(self, audio_file_path, PERSONA_ONLY=False, MUSIC=False): """ -- cgit v1.3.1