Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import environ, path
- import pyaudio
- from pocketsphinx.pocketsphinx import *
- from sphinxbase.sphinxbase import *
- from pocketsphinx import get_model_path
- MODELDIR = get_model_path()
- config = Decoder.default_config()
- config.set_string('-hmm', path.join(MODELDIR, 'ru-ru\\zero_ru.cd_cont_4000'))
- config.set_string('-lm', path.join(MODELDIR, 'ru-ru\\ru.lm'))
- config.set_string('-dict', path.join(MODELDIR, 'ru-ru\\ru.dic'))
- config.set_string('-logfn', 'nul')
- print('Загрузка...')
- decoder = Decoder(config)
- 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()
- print('Готово.')
- end = False
- while True:
- if end:
- break
- print('Распознана команда выхода, завершение работы.')
- end = False
- 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()
- for word in decoder.hyp().hypstr.split():
- print(word)
- if word == 'выход':
- end = True
- decoder.start_utt()
- else:
- break
- decoder.end_utt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement