예제 #1
0
파일: dec_module.py 프로젝트: merzod/mirror
def decodeOnline(data):
    stt_url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=%s&key=%s' % (Context.getGoogle('locale'), Context.getGoogle('app.key'))
    fout = StringIO.StringIO()

    c = pycurl.Curl()
    c.setopt(pycurl.VERBOSE, 0)
    c.setopt(pycurl.URL, stt_url)
    c.setopt(pycurl.WRITEFUNCTION, fout.write)
    c.setopt(pycurl.POST, 1)
    c.setopt(pycurl.HTTPHEADER, ['Content-Type: audio/l16; rate=%s' % Context.getAudio('rate')])
    c.setopt(pycurl.POSTFIELDSIZE, len(data))
    c.setopt(pycurl.READFUNCTION, StringIO.StringIO(data).read)
    c.perform()

    response_data = fout.getvalue()
    logging.debug(response_data)

    start_loc = response_data.find("transcript")
    temp_str = response_data[start_loc + 13:]
    end_loc = temp_str.find("\"")
    final_result = temp_str[:end_loc]
    c.close()
    return final_result
예제 #2
0
파일: voice.py 프로젝트: merzod/mirror
 def listen(self, sec):
     reccmd = ["arecord", "-D", "plughw:0,0", "-f", "cd", "-c", "1", "-t", "wav", "-d", "%d" % sec, "-q", "-r",
               Context.getAudio('rate')]
     proc = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
     return proc.stdout.read()
예제 #3
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:
예제 #4
0
파일: mirror.py 프로젝트: merzod/mirror
from weather import *
from timer import *
from context import Context
from song import *
from threshold import ThresholdTuner
import sys

sys.path.append("../hardware/")
import screen

logging.basicConfig(
    level=logging.DEBUG, format="%(asctime)s %(levelname)s\t(%(threadName)-10s) %(filename)s:%(lineno)d\t%(message)s"
)
logging.getLogger("requests").setLevel(logging.WARNING)

LISTEN = int(Context.getAudio("listen"))
MAX_SAMPLES = int(Context.getAudio("max.samples"))
threshold = ThresholdTuner(
    maxlen=int(Context.getAudio("threshold.samples")),
    defthreshold=Context.getAudio("threshold"),
    margin=int(Context.getAudio("threshold.margin")),
)

core = Core()

# build active processors
proc = WeatherProcessor()
proc.append(TomorrowWeatherProcessor())
proc.append(NowWeatherProcessor())
core.append(proc)