Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 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,12 +79,13 @@ 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__)

self.executable = executable
self.version = version

self.fst_model = os.path.abspath(fst_model)
self._logger.debug("Using FST model: '%s'", self.fst_model)
Expand Down Expand Up @@ -107,7 +113,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 +124,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 = 1.0

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', 1.0, 'dummy_fst_model',
nbest=3)

def testTranslateWord(self):
Expand Down