有没有办法在 pocketsphinx python 中 return 整个字典条目(单词 + 音素)?

Is there a way to return entire dictionary entry (word + phoneme) in pocketsphinx python?

这是我的代码:

#!/usr

/bin/env python
import os

import sphinxbase as sb
import pocketsphinx as ps

MODELDIR = 'deps/pocketsphinx/model'
DATADIR = 'deps/pocketsphinx/test/data'

# Create a decoder with certain model
config = ps.Decoder.default_config()
config.set_string('-hmm', os.path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-lm', os.path.join(MODELDIR, 'en-us/en-us.lm.bin'))
config.set_string('-dict', os.path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
decoder = ps.Decoder(config)

# Decode streaming data.
decoder.start_utt()
stream = open(os.path.join(DATADIR, 'hello_world.wav'), 'rb')
while True:
    buf = stream.read(1024)
    if buf:
        decoder.process_raw(buf, False, False)
    else:
        break
decoder.end_utt()
stream.close()
print('Best hypothesis segments:', [seg.word for seg in decoder.seg()])

我在

中找到的

音频文件hello_world.wav正确输出:'Best hypothesis segments: hello world'

这是我的问题。我正在查看位于 /Library/Python/2.7/site-packages/speech_recognition/pocketsphinx-data/en-US 的 pronunciation-dictionary.dict 文件,它似乎将英语单词映射到音素。

'hello' 和 'world' 的条目是:

hello HH AH L OW 
world W ER L D

我想 return 字典中的整行。所以,我想要 'hello HH AH L OW' 而不是 'hello'。有办法吗?

得到结果后可以查单词读音:

 print ('Best hypothesis segments: ', [(seg.word, decoder.lookup_word(seg.word)) for seg in decoder.seg()])