Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os
- from pocketsphinx.pocketsphinx import *
- from sphinxbase.sphinxbase import *
- import pyaudio
- # modeldir = "../../../model"
- # datadir = "../../../test/data"
- modeldir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//en-us"
- dictdir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//cmudict-en-us.dict"
- lmdir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//en-us.lm.bin"
- # Create a decoder with certain model
- config = Decoder.default_config()
- config.set_string('-hmm', modeldir)
- config.set_string('-lm', lmdir )
- config.set_string('-dict', dictdir)
- config.set_string('-keyphrase', 'forward')
- config.set_float('-kws_threshold', 1e+20)
- p = pyaudio.PyAudio()
- stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
- stream.start_stream()
- # Process audio chunk by chunk. On keyword detected perform action and restart search
- decoder = Decoder(config)
- decoder.start_utt()
- while True:
- buf = stream.read(1024)
- if buf:
- decoder.process_raw(buf, False, False)
- else:
- break
- if decoder.hyp() != None:
- #print(decoder.hyp().hypstr)
- if decoder.hyp().hypstr == 'forward':
- print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
- print ("Detected keyword, restarting search")
- decoder.end_utt()
- decoder.start_utt()
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the
- the da
- the head
- the bed
- the bedding
- the heading of
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and
- the bedding and well
- the bedding and well
- the bedding and well
- the bedding and butler
- the bedding and what lingus
- the bedding and what lingus
- the bedding and what lingus
- the bedding and what lingus ha
- the bedding and blessed are
- the bedding and blessed are
- the bedding and what lingus on
- the bedding and what lingus want
- the bedding and what lingus want
- the bedding and what lingus want
- the bedding and what lingus want
- the bedding and what lingus want or
- the bedding and what lingus want to talk
- the bedding and what lingus current top
- the bedding and what lingus want to talk
- the bedding and what lingus want to talk
- the bedding and what lingus want to talk
- the bedding and what lingus want to talk
- the bedding and what lingus want to talk to her
- the bedding and what lingus want to talk to her
- the bedding and what lingus want to talk to her
- the bedding and what lingus want to talk to her
- import os
- import pyaudio
- import pocketsphinx as ps
- modeldir = "C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//"
- # Create a decoder with certain model
- config = ps.Decoder.default_config()
- config.set_string('-hmm', os.path.join(modeldir, 'en-us'))
- config.set_string('-lm', os.path.join(modeldir, 'en-us.lm.bin'))
- config.set_string('-dict', os.path.join(modeldir, 'cmudict-en-us.dict'))
- config.set_string('-keyphrase', 'forward')
- config.set_float('-kws_threshold', 1e+20)
- p = pyaudio.PyAudio()
- stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
- stream.start_stream()
- # Process audio chunk by chunk. On keyword detected perform action and restart search
- decoder = ps.Decoder(config)
- decoder.start_utt()
- while True:
- buf = stream.read(1024)
- if buf:
- decoder.process_raw(buf, False, False)
- else:
- break
- if decoder.hyp() is not None:
- print(decoder.hyp().hypstr)
- if 'forward' in decoder.hyp().hypstr:
- print([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
- print("Detected keyword, restarting search")
- decoder.end_utt()
- decoder.start_utt()
- config.set_string('-lm', lmdir )
Add Comment
Please, Sign In to add comment