def callback(self, cmd, action, target, msg): if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) elif msg.endswith(u"秒"): t = int(Util.cn2dig(msg[:-1])) elif msg.endswith(u"分钟"): t = int(Util.cn2dig(msg[:-2]))*60 elif msg.endswith(u"小时"): t = int(Util.cn2dig(msg[:-2]))*60*60 else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None DEBUG("thread wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play( Res.get_res_path("sound/com_bell") , True, count) self._home.setResume(False) return True
def callback(self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new": path = "usr/memo/" try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: ERROR(exc) self._home.publish_msg(cmd, u"录音错误") return False self._home.setResume(True) filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3" record = self._global_context["recorder"] self._home.publish_msg(cmd, u"录音开始...") record(filepath) self._home.publish_msg(cmd, u"录音结束") Sound.play( Res.get_res_path("sound/com_stop") ) self._home.setResume(False) return True
def callback(self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new" or pre_value == "set": if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None INFO("alarm wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play( Res.get_res_path("sound/com_bell") , True, count) self._home.setResume(False) return True
def callback(self, cmd, msg): self._home.publish_msg(cmd, u"正在截图...") Sound.notice(Res.get_res_path("sound/com_shoot")) save_path="data/capture/" save_name, thumbnail_name = CameraHelper().take_a_photo(save_path) # for test # save_name = "2015_05_02_164052.jpg" if save_name is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True img_url, thumbnail_url = self._upload_image( save_path + save_name, save_path + thumbnail_name, ) if img_url is None: self._home.publish_msg(cmd, u"截图失败") INFO("upload capture faild.") return True else: self._home.publish_msg( cmd, msg=img_url, cmd_type="capture" ) return True
def on_start_sound(cmd: pcmd.Command, args: List[str], parameters: List[str], json: bool) -> None: """Callback for `start sound` - adds a sound effect""" for i, a in enumerate(parameters): if re.match(r'^[\d\.]*$', a): continue if not os.path.isfile(a): a = os.path.join(params.BPATH, 'res', 'sounds', a) if not os.path.isfile(a): if not json: utils.printerr(f'File "{a}" doesn\'t exist ... ') continue else: print( JSON.dumps({ 'error': f'File "{a}" doesn\'t exist ... "', })) return try: if i + 1 < len(args) and re.match(r'^[\d\.]+$', args[i + 1]): ch.add_sound(Sound(a, float(args[i + 1]))) continue ch.add_sound(Sound(a)) except Exception as e: if not json: utils.printerr(str(e)) else: print(JSON.dumps({ 'error': str(e), })) if json: print(JSON.dumps({}))
def _stop_callback(self, command, stop): DEBUG(" _stop_callback: %s" % command) Sound.play(Res.get_res_path("sound/com_stop"), inqueue=True) if "stop" in self._registered_callbacks: callbacks = self._registered_callbacks["stop"] if stop in callbacks: callbacks[stop](stop=stop)
def callback(self, action=None, target=None, msg=None, pre_value=None): INFO("action:stop_play_callback invoke") if "player" in self._global_context: INFO("clear audio queue.") Sound.clear_queue() del self._global_context["player"] return True, "stop_playing"
def callback(self, cmd, action, target, msg, pre_value): if pre_value == "show" or pre_value == "get": volume = Sound.get_volume() if volume is None: self._home.publish_msg(cmd, u"设置音量值失败") return False if pre_value == "show": self._home.publish_msg(cmd, u"当前音量值为:%s" % volume) return True, int(volume) elif pre_value == "set": if msg is None or len(msg) == 0: self._home.publish_msg(cmd, u"请输入音量值") return False ret = Sound.set_volume(msg) if ret is None: self._home.publish_msg(cmd, u"设置音量值失败") return False if ret == "-2": self._home.publish_msg(cmd, u"音量值必须为整数") return False elif ret == "-3": self._home.publish_msg(cmd, u"音量值无效:%s" % msg) return False self._home.publish_msg(cmd, u"设置音量值为:%s" % msg) return True, int(msg) else: return False
def callback(self, cmd, msg): self._home.publish_msg(cmd, u"正在截图...") Sound.play(Res.get_res_path("sound/com_shoot")) save_path="data/capture/" save_name, thumbnail_name = CameraHelper().take_a_photo(save_path) # for test # save_name = "2015_05_02_164052.jpg" if save_name is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True img_url, thumbnail_url = self._upload_image( save_path + save_name, save_path + thumbnail_name, ) if img_url is None: self._home.publish_msg(cmd, u"截图失败") INFO("capture faild.") return True else: self._home.publish_msg( cmd, msg=img_url, cmd_type="capture" ) return True
def callback(self, cmd, action, target, msg): if msg is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None if msg.endswith(u'点') or \ msg.endswith(u'分'): t = Util.gap_for_timestring(msg) elif msg.endswith(u"秒"): t = int(Util.cn2dig(msg[:-1])) elif msg.endswith(u"分钟"): t = int(Util.cn2dig(msg[:-2])) * 60 elif msg.endswith(u"小时"): t = int(Util.cn2dig(msg[:-2])) * 60 * 60 else: self._home.publish_msg(cmd, u"时间格式错误") return False if t is None: self._home.publish_msg(cmd, u"时间格式错误") return False, None DEBUG("thread wait for %d sec" % (t, )) self._home.publish_msg(cmd, action + target + msg) threading.current_thread().waitUtil(t) if threading.current_thread().stopped(): return False self._home.setResume(True) count = 7 Sound.play(Res.get_res_path("sound/com_bell"), True, count) self._home.setResume(False) return True
def callback(self, action = None, target = None, msg = None, pre_value = None): INFO("action:stop_play_callback invoke") if "player" in self._global_context: INFO("clear audio queue.") Sound.clear_queue() del self._global_context["player"] return True, "stop_playing"
def callback(self, cmd, action, target, msg, pre_value): volume = Sound.get_volume() if volume is None: self._home.publish_msg(cmd, u"系统错误,静音失败") return False self._home._storage.set("lehome:last_volume", volume) ret = Sound.set_volume(0) if ret is None: self._home.publish_msg(cmd, u"设置音量值失败") return False self._home.publish_msg(cmd, u"音量已设置为0") return True, "mute"
def on_start_sound(cmd: pcmd.Command, args: List[str], params: List[str]) -> None: """Callback for `start sound` - adds a sound effect""" for i, a in enumerate(params): if re.match(r'^[\d\.]*$', a): continue if not os.path.isfile(a): utils.printerr('File "{}" doesn\'t exist ... '.format(a)) try: if i + 1 < len(args) and re.match(r'^[\d\.]+$', args[i + 1]): ch.add_sound(Sound(a, float(args[i + 1]))) continue ch.add_sound(Sound(a)) except Exception as e: utils.printerr(str(e))
def __load(self, path, limit): with open(path, newline='') as metadatacsv: reader = csv.DictReader(metadatacsv) for row in reader: s = Sound(row) if limit == -1 or len(list(filter(lambda x: x.folder == s.folder and x.sound_class == s.sound_class,self.__metadata))) < limit: self.__metadata.append(s)
def callback( self, cmd, action=None, target=None, msg=None, pre_value=None): if pre_value == "new": path = "usr/message/" try: os.makedirs(path) except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: ERROR(exc) return False self._home.setResume(True) filepath = path + datetime.now().strftime("%m_%d_%H_%M") + ".mp3" Sound.play(Res.get_res_path("sound/com_stop")) record = self._global_context["recorder"] self._home.publish_msg(cmd, u"录音开始...") record(filepath) self._home.publish_msg(cmd, u"录音结束") self._home.setResume(False) elif pre_value == "play": self._home.setResume(True) play = self._global_context["player"] for idx, filepath in enumerate(glob.glob("usr/message/*.mp3")): # self._speaker.speak(u'第%d条留言' % (idx + 1)) INFO(u'第%d条留言:%s' % (idx + 1, filepath)) play(filepath) play(Res.get_res_path("sound/com_stop")) self._home.setResume(False) elif pre_value == "remove": filelist = glob.glob("usr/message/*.mp3") for f in filelist: os.remove(f) INFO("remove:%s" % (f, )) Sound.play( Res.get_res_path("sound/com_trash") ) return True
def callback(self, cmd, action, target, msg, pre_value): if pre_value == "show" or pre_value == "get": volume = Sound.get_volume() if Util.empty_str(volume): self._home.publish_msg(cmd, u"获取音量值失败") return False if pre_value == "show": self._home.publish_msg(cmd, u"当前音量值为:%s" % volume) return True, int(volume) elif pre_value == "set" or pre_value == "resume": if pre_value == "resume": msg = self._home._storage.get("lehome:last_volume") if msg is None or len(msg) == 0: self._home.publish_msg(cmd, u"请输入音量值") return False # remember last volume value for resume volume volume = Sound.get_volume() if not Util.empty_str(volume): INFO("save last volume:%s" % volume) self._home._storage.set("lehome:last_volume", volume) ret = Sound.set_volume(msg) if ret is None: self._home.publish_msg(cmd, u"设置音量值失败") return False if ret == "-2": self._home.publish_msg(cmd, u"音量值必须为整数") return False elif ret == "-3": self._home.publish_msg(cmd, u"音量值无效:%s" % msg) return False self._home.publish_msg(cmd, u"设置音量值为:%s" % msg) return True, int(msg) else: return False
def _init_res(self): super()._init_res() self.key_sound = Sound(os.path.join(self.sound_dir, 'pew.wav')) self.bg_image = Image( os.path.join(self.image_dir, 'blackboard_1024_768.png')).image self.right_image = Image( os.path.join(self.image_dir, 'right_140_147.png')).image self.wrong_image = Image( os.path.join(self.image_dir, 'wrong_140_177.png')).image ball_path = os.path.join(self.image_dir, 'basketball_50_50.png') speed = 13 rand = ((0.1 * (random.randint(5, 8)))) vector = (0.47, speed) basketball = BasketBall(path=ball_path, vector=vector) self.basketball = pygame.sprite.RenderPlain(basketball) # self._init_db() self.voicer_name = 'ada' self.voice_path = os.path.join(self.sound_dir, self.voicer_name) self.voicer = Voicer(path=self.voice_path)
def play(path=None, inqueue=True, loop=-1): if not path: return Sound.play(path, inqueue, loop) INFO("%s going to audio queue." % (path, ))
def play(path = None, inqueue=True, channel='default', loop=-1): if not path: return Sound.play(path, inqueue, channel, loop) INFO("%s going to audio queue." % (path, ))
def process(s:Sound): s.feature_extraction(params)