Skip to content

Instantly share code, notes, and snippets.

@mbritton
Created February 6, 2023 06:35
Show Gist options
  • Save mbritton/8787ac6cb5576a11b1631c2b21020d8a to your computer and use it in GitHub Desktop.
Save mbritton/8787ac6cb5576a11b1631c2b21020d8a to your computer and use it in GitHub Desktop.
from os import environ, path
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
MODELDIR = "../../../model"
DATADIR = "../../../test/data"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-allphone', path.join(MODELDIR, 'en-us/en-us-phone.lm.dmp'))
config.set_float('-lw', 2.0)
config.set_float('-beam', 1e-10)
config.set_float('-pbeam', 1e-10)
# Decode streaming data.
decoder = Decoder(config)
decoder.start_utt()
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
decoder.end_utt()
hypothesis = decoder.hyp()
print ('Phonemes: ', [seg.word for seg in decoder.seg()])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment