Created
February 18, 2016 14:28
-
-
Save Perlence/482021283fecca48414a to your computer and use it in GitHub Desktop.
Basic usage of PocketSphinx via Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| from os import path | |
| from sphinxbase import sphinxbase # noqa | |
| from pocketsphinx import pocketsphinx | |
| MODELDIR = "pocketsphinx/model" | |
| DATADIR = "pocketsphinx/test/data" | |
| # Create a decoder with certain model | |
| config = pocketsphinx.Decoder.default_config() | |
| config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us')) | |
| config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin')) | |
| config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict')) | |
| # Decode streaming data. | |
| decoder = Decoder(config) | |
| decoder.start_utt() | |
| stream = open(path.join(DATADIR, 'goforward.raw'), 'rb') | |
| while True: | |
| buf = stream.read(1024) | |
| if not buf: | |
| break | |
| decoder.process_raw(buf, False, False) | |
| decoder.end_utt() | |
| print('Best hypothesis segments: ', [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