예제 #1
0
파일: analyser.py 프로젝트: merzod/mirror
 def __init__(self):
     # Create and configure decoder
     self.config = Decoder.default_config()
     self.config.set_string('-hmm', path.join(Analyser.MODELDIR, Analyser.HMM))
     self.config.set_string('-lm', path.join(Analyser.MODELDIR, Analyser.HMM, '%s.lm' % Context.getPocketsphinx('dict')))
     self.config.set_string('-dict', path.join(Analyser.MODELDIR, Analyser.HMM, '%s.dic' % Context.getPocketsphinx('dict')))
     self.config.set_string('-logfn', '/dev/null')
     self.decoder = Decoder(self.config)
예제 #2
0
파일: dec_module.py 프로젝트: merzod/mirror
import scikits.audiolab, numpy, subprocess, sys, logging, audioop, time, pycurl, StringIO, os
from context import Context
from pocketsphinx import *
from os import path

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s\t(%(threadName)-10s) %(filename)s:%(lineno)d\t%(message)s')
MODELDIR = Context.getPocketsphinx('model.dir')
HMM = Context.getPocketsphinx('hmm')
THRESHOLD = int(Context.getAudio('threshold'))
SEC2LISTEN = Context.getAudio('sec2listen')

# Create and configure decoder
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, HMM))
config.set_string('-lm', path.join(MODELDIR, HMM, '%s.lm' % Context.getPocketsphinx('dict')))
config.set_string('-dict', path.join(MODELDIR, HMM, '%s.dic' % Context.getPocketsphinx('dict')))
config.set_string('-logfn', '/dev/null')
decoder = Decoder(config)

# function run 'arecord' console cmd for 'sec' seconds and gives back it's stdout
def listen(sec):
    reccmd = ["arecord", "-D", "plughw:0,0", "-f", "cd", "-c", "1", "-t", "wav", "-d", "%s"%sec, "-q", "-r", Context.getAudio('rate')]
    proc = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
    return proc.stdout.read()

# function decode data using decoder, and return decoded string or None
def decodeOffline(decoder, data):
    decoder.start_utt()
    decoder.process_raw(data, False, False)
    decoder.end_utt()
    if decoder.hyp() is not None and decoder.hyp().hypstr: