Reputation: 1322
Here is my code:
#!/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()])
Which I found in this stack overflow question
The audio file hello_world.wav correctly outputs: 'Best hypothesis segments: hello world'
Here's my question. I'm looking in the pronunciation-dictionary.dict file located in: /Library/Python/2.7/site-packages/speech_recognition/pocketsphinx-data/en-US, where it seems to be mapping english words to phonemes.
The entries for 'hello' and 'world' are:
hello HH AH L OW
world W ER L D
I would like to return the entire line from the dictionary. So, rather than just 'hello', I would like 'hello HH AH L OW'. Is there a way to do this?
Upvotes: 1
Views: 567
Reputation: 25220
You can lookup the pronunciation of the word once you get the results:
print ('Best hypothesis segments: ', [(seg.word, decoder.lookup_word(seg.word)) for seg in decoder.seg()])
Upvotes: 2