Skip to content

Commit

Permalink
Merge pull request #8 from andweber/phonetisaurus_git
Browse files Browse the repository at this point in the history
sphinx-stt: added support for current github version of phonetisaurus

Ty
  • Loading branch information
chrobione authored Aug 21, 2016
2 parents 44aab76 + 30f37fa commit 717908c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
27 changes: 17 additions & 10 deletions plugins/stt/pocketsphinx-stt/g2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
r'input symbols table')


def execute(executable, fst_model, input, is_file=False, nbest=None):
def execute(executable, version, fst_model, input, is_file=False, nbest=None):
logger = logging.getLogger(__name__)

cmd = [executable,
'--model=%s' % fst_model,
'--input=%s' % input,
'--words']

if is_file:
cmd.append('--isfile')
'--model=%s' % fst_model]
if version <= 0.8:
cmd.append('--input=%s' % input)
cmd.append('--words')
if is_file:
cmd.append('--isfile')
else:
if is_file:
cmd.append('--wordlist=%s' % input)
else:
cmd.append('--word=%s' % input)

if nbest is not None:
cmd.extend(['--nbest=%d' % nbest])
Expand Down Expand Up @@ -74,7 +79,7 @@ def execute(executable, fst_model, input, is_file=False, nbest=None):


class PhonetisaurusG2P(object):
def __init__(self, executable, fst_model,
def __init__(self, executable, version, fst_model,
fst_model_alphabet='arpabet',
nbest=None):
self._logger = logging.getLogger(__name__)
Expand All @@ -88,6 +93,8 @@ def __init__(self, executable, fst_model,
self._logger.debug("Using FST model alphabet: '%s'",
self.fst_model_alphabet)

self.version = version

self.nbest = nbest
if self.nbest is not None:
self._logger.debug("Will use the %d best results.", self.nbest)
Expand All @@ -107,7 +114,7 @@ def _convert_phonemes(self, data):
raise ValueError('Invalid FST model alphabet!')

def _translate_word(self, word):
return execute(self.executable, self.fst_model, word,
return execute(self.executable, self.version, self.fst_model, word,
nbest=self.nbest)

def _translate_words(self, words):
Expand All @@ -118,7 +125,7 @@ def _translate_words(self, words):
for word in words:
f.write("%s\n" % word)
tmp_fname = f.name
output = execute(self.executable, self.fst_model, tmp_fname,
output = execute(self.executable, self.version, self.fst_model, tmp_fname,
is_file=True, nbest=self.nbest)
os.remove(tmp_fname)
return output
Expand Down
7 changes: 6 additions & 1 deletion plugins/stt/pocketsphinx-stt/sphinxvocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def compile_vocabulary(config, directory, phrases):
except KeyError:
executable = 'phonetisaurus-g2p'

try:
version = config['pocketsphinx']['phonetisaurus_version']
except KeyError:
version = 0.7

try:
nbest = config['pocketsphinx']['nbest']
except KeyError:
Expand All @@ -65,7 +70,7 @@ def compile_vocabulary(config, directory, phrases):
if not os.path.exists(fst_model):
raise OSError('FST model does not exist!')

g2pconverter = PhonetisaurusG2P(executable, fst_model,
g2pconverter = PhonetisaurusG2P(executable, version, fst_model,
fst_model_alphabet=fst_model_alphabet,
nbest=nbest)

Expand Down
2 changes: 1 addition & 1 deletion plugins/stt/pocketsphinx-stt/tests/test_g2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def poll(self):

class TestPatchedG2P(unittest.TestCase):
def setUp(self):
self.g2pconv = g2p.PhonetisaurusG2P('dummy_proc', 'dummy_fst_model',
self.g2pconv = g2p.PhonetisaurusG2P('dummy_proc', 0.7, 'dummy_fst_model',
nbest=3)

def testTranslateWord(self):
Expand Down

0 comments on commit 717908c

Please sign in to comment.