Created
March 1, 2019 15:57
-
-
Save shohei/aa2a0c3fbca07acdaa3b10ec312edc74 to your computer and use it in GitHub Desktop.
pocketsphinx
This file contains 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
#!/usr/bin/python | |
from os import environ, path | |
from pocketsphinx.pocketsphinx import * | |
from sphinxbase.sphinxbase import * | |
MODELDIR = "../../../model" | |
DATADIR = "../../../test/data" | |
config = 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')) | |
config.set_string('-logfn', '/dev/null') | |
decoder = Decoder(config) | |
import pyaudio | |
p = pyaudio.PyAudio() | |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024) | |
stream.start_stream() | |
in_speech_bf = False | |
decoder.start_utt() | |
while True: | |
buf = stream.read(1024) | |
if buf: | |
decoder.process_raw(buf, False, False) | |
if decoder.get_in_speech() != in_speech_bf: | |
in_speech_bf = decoder.get_in_speech() | |
if not in_speech_bf: | |
decoder.end_utt() | |
print('Result:', decoder.hyp().hypstr) | |
decoder.start_utt() | |
else: | |
break | |
decoder.end_utt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment