本文整理汇总了Python中context.Context.getAudio方法的典型用法代码示例。如果您正苦于以下问题:Python Context.getAudio方法的具体用法?Python Context.getAudio怎么用?Python Context.getAudio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context.Context
的用法示例。
在下文中一共展示了Context.getAudio方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decodeOnline
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import getAudio [as 别名]
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: listen
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import getAudio [as 别名]
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: int
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import getAudio [as 别名]
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: int
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import getAudio [as 别名]
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)