class Scene(): def __init__(self): self.speek = Speeker() #logger.info("初始化【Scene】") def get_scene(self,content): """ # 获取会话场景 # content 当前会话语句 """ scene_local = True # 标示是否为本地场景 scene_code = "" # 标示场景关键字 local_keyword = {'音乐':'音乐','室内温度':'室内温度','暂停':'暂停','播放':'播放'} if '音乐' in content: scene_code = '音乐' elif '暂停' in content: scene_code = '暂停' elif '播放' in content: scene_code = '播放' elif '下一曲' in content: scene_code = '下一曲' elif '上一曲' in content: scene_code = '上一曲' elif '室内温度' in content: scene_code = '室内温度' elif '原样输出' in content: # 调用语音接口,输出语音。 self.speek.speek({},content.split(':')[1]) else: scene_local = False data = {'state':True,'scene_local':scene_local,'code':scene_code} return data
class LocalWorker(): def __init__(self): self.speeker = Speeker() def handle(self,scener = {}): # scene为场景元素 if scener.get("code") == "音乐": player = DownLoadMusic() player.setDaemon(True) player.start() player.join() self.speeker.speek({},u"正在为您下载虾米音乐top10") p=subprocess.Popen("python worker/music/playMusic.py", shell=True) p.wait() set_config(values={'state':'play'}) playmusic() if scener.get("code") == "暂停": #print open(os.getcwdu() + os.sep + "setting.cfg", 'r').read( ) set_config(values={'state':'pause'}) if scener.get("code") == "播放": #print open(os.getcwdu() + os.sep + "setting.cfg", 'r').read( ) set_config(values={'state':'play'}) if scener.get("code") == "下一曲": #print open(os.getcwdu() + os.sep + "setting.cfg", 'r').read( ) set_config(values={'state':'next'}) if scener.get("code") == "上一曲": #print open(os.getcwdu() + os.sep + "setting.cfg", 'r').read( ) set_config(values={'state':'last'})
def __init__(self): self.speeker = Speeker()
def tulingCallBack(self, buf): buf = json.loads(buf) if buf.get("code"): # 调用【机器反馈模块】给以语音的返回。 speek = Speeker() code = buf.get("code") logger.info(("margin : " + buf.get("text").encode("utf8"))) # 将内容说出来 if code == 100000: # 如果是普通文字 # 语音反馈 speek.speek({}, buf.get("text")) elif code == 200000: # 如果是链接类的 speek.speek({}, u"已经给你找到了以下内容,内容打印在屏幕上了。") logger.info(("margin : " + buf.get("url")).encode("utf8")) elif code == 302000: # 如果是新闻类的 speek.speek({}, u"已经给你找到了以下内容。") news = [n["article"] for n in buf["list"]] speek.speek({}, str(news)) elif code == 305000: # 如果是列车类的 msg = [buffer.get("text")] for buffer in buf.get("list"): msg_ = ( buffer.get("trainnum") + ",从," + buffer.get("start") + ",到," + buffer.get("terminal") + ",发车时间," + buffer.get("starttime") + ",到站时间," + buffer.get("endtime") ) msg.append(msg_) speek.speek({}, str(msg)) elif code == 306000: # 如果是航班类的 msg = [buffer.get("text")] for buffer in buf.get("list"): msg_ = buffer.get("flight") + ",起飞时间," + buffer.get("starttime") + ",到达时间," + buffer.get("endtime") msg.append(msg_) speek.speek({}, str(msg)) elif code == 308000: # 如果是菜谱类的 msg = [buffer.get("text")] for buffer in buf.get("list"): msg_ = buffer.get("name") + ",做法为:" + buffer.get("info") msg.append(msg_) speek.speek({}, str(msg)) else: speek.speek({}, u"亲,我不知该做什么事情了。")