示例#1
0
文件: music.py 项目: noenif/zimei
        def th_control(pygame, nei_conn, music_pid):
            global this_play_id
            while True:
                enjson = nei_conn.recv()
                log.info('音乐收到通知', enjson)

                if type(enjson) is dict:
                    if enjson['control'] == 'pause':
                        pygame.mixer.music.pause()
                    elif enjson['control'] == 'unpause':
                        if enjson['newlist'] == 1:
                            pygame.mixer.music.stop()
                            this_play_id = 0
                        else:
                            pygame.mixer.music.unpause()
                    elif enjson['control'] == 'stop':
                        pygame.mixer.music.pause()
                        pygame.mixer.quit()
                        pygame.quit()
                        os.system('sudo kill -9 ' + str(music_pid))

                    elif enjson['control'] == 'next':
                        pygame.mixer.music.stop()

                    elif enjson['control'] == 'previous':
                        this_play_id -= 2
                        pygame.mixer.music.stop()
示例#2
0
    def command_execution(self, sbobj):
        log.info("进入主控", sbobj)

        #语音识别成功
        if sbobj["state"]:

            #发送到前面屏幕
            if sbobj['data']:

                if sbobj['enter'] == "mqtt":
                    send_txt = {'obj': 'zhuren', 'msg': "移动端控制模块已启动"}
                else:
                    send_txt = {'obj': 'zhuren', 'msg': sbobj['data']}

                self.public_obj.sw.send_info(send_txt)

            #=========================================================================
            #发送通知给技能
            sbobj['optype'] = 'action'
            self.public_obj.master_conn.send(sbobj)

        else:
            self.is_snowboy.value = 0
            self.command_success(sbobj)

        if sbobj['enter'] != 'voice':
            self.is_snowboy.value = 0
示例#3
0
    def __init__(self):
        token_file = os.path.join(self.config["root_path"],
                                  'runtime/token/face_token.txt')

        self.renlian_conf = self.config['BAIDUAPI'][
            'renlian_conf']  #读取配置里人脸识别参数
        self.renlian_conf['token_file'] = token_file

        self.huoqu_token = key.Token(self.renlian_conf)
        log.info("在线人脸对比初始化完成")
示例#4
0
    def start_yuyin(self, is_one=0):
        log.info("开始进入语音进程")
        if self.hx_yuyinpid.value > 0:
            os.system("sudo kill -9 {}".format(self.hx_yuyinpid.value))
        self.hx_yuyinpid.value = 0

        #启动新进程开始录音+识别
        self.p2 = mp.Process(target=self.Luyin_shibie.main,
                             args=(self.hx_yuyinpid, is_one,
                                   self.command_execution, self.pyaudio_obj,
                                   self.public_obj))
        self.p2.start()
示例#5
0
 def main(self,audio_data):
     try:
         resp = self.__yuyin_shibie_api(audio_data)
         del audio_data
         log.info('识别结果',resp)
         if resp['state'] == False:
             return resp
         else:
             return resp
     except :
         resp = {'enter':'voice','state': False,'data':'','msg':'识别失败。'}
         return resp
示例#6
0
文件: visual.py 项目: noenif/zimei
    def __init__(self):
        log.info("初始化人脸对比")

        self.temp_photo = os.path.join(self.config['root_path'],
                                       "runtime/shijue/photos.jpg")

        self.is_video = False  # 是否启动人脸识别
        self.video_i = 0
        self.video_max = 5

        self.opencv = Opencv()  #人脸识别类
        self.opencv.success = self.success_max

        self.contrast = contrast.Contrast_face()  #人脸在线对比
示例#7
0
文件: visual.py 项目: noenif/zimei
    def main(self):

        self.user_info = self.data.user_list_get()
        if self.user_info == False:
            log.info('暂无用户数据,人脸对比停止!')
            return
        if len(self.user_info) > 0:
            for x in self.user_info:
                if x['facepath'] == None: continue
                if len(x['facepath']) > 0:
                    if os.path.isfile(x['facepath']):
                        self.is_video = True
            if self.is_video:
                self.start_video()
示例#8
0
    def command_success(self, reobj={}):
        log.info("命令动作执行_成功", reobj)

        if reobj['state'] is True and reobj['data']:
            #发送到前面屏幕
            send_txt = {'obj': 'mojing', 'msg': reobj['data']}
            self.public_obj.sw.send_info(send_txt)
            del send_txt
            yuyin.Hecheng_bofang(self.is_snowboy, self.public_obj).main(reobj)

        elif type(reobj['msg']) is dict:
            msg = reobj['msg']
            if 'errtype' in msg.keys():
                yuyin.Hecheng_bofang(self.is_snowboy,
                                     self.public_obj).error(msg['errtype'])
示例#9
0
文件: token.py 项目: noenif/zimei
    def __lianwang_huoqutoken(self):
        log.info('正在网络请求:access_token')
        #获取token秘钥
        url = self.conf_info['token_url']
        body = self.conf_info['body']

        try:
            r = requests.post(url, data=body, verify=True, timeout=5)
            respond = json.loads(r.text)
            return {
                'state': True,
                'access_token': respond["access_token"],
                'msg': '获取access_token成功'
            }
        except:
            return {'state': False, 'access_token': '', 'msg': '网络连接超时'}
示例#10
0
文件: visual.py 项目: noenif/zimei
    def start_contrast_face(self, user_info, i=0):
        if i >= len(user_info): return {}
        this_info = user_info[i]
        facepath = this_info['facepath']

        #log.info('facepath',facepath)
        #log.info('temp_photo',self.temp_photo)

        if facepath != None:
            if os.path.isfile(facepath):
                bjz = self.contrast.main(facepath, self.temp_photo)
                log.info('对比值:', this_info['uid'], bjz)
                if bjz >= 80:
                    return this_info
        i += 1
        time.sleep(0.2)
        return self.start_contrast_face(user_info, i)
示例#11
0
文件: bofang.py 项目: noenif/zimei
    def __paly_windows_wav(self, name):
        ding_wav = wave.open(name, 'rb')
        ding_data = ding_wav.readframes(ding_wav.getnframes())
        audio = pyaudio.PyAudio()
        stream_out = audio.open(format=audio.get_format_from_width(
            ding_wav.getsampwidth()),
                                channels=ding_wav.getnchannels(),
                                rate=ding_wav.getframerate(),
                                input=False,
                                output=True)
        stream_out.start_stream()
        stream_out.write(ding_data)
        #time.sleep(0.2)
        stream_out.stop_stream()
        stream_out.close()
        audio.terminate()

        log.info('播放结束')
示例#12
0
文件: token.py 项目: noenif/zimei
    def __huancun_token(self):
        token_file = self.conf_info['token_file']
        jiancha = os.path.exists(token_file)  #检查

        log.info('是否存在本地缓存access_token', jiancha)

        if jiancha == False:  #没有该文件的话,创建一下,并写入,在返回token
            p_path = os.path.dirname(token_file)
            if os.path.isdir(p_path) == False:
                os.system('sudo mkdir -p ' + p_path)

            token = self.__lianwang_huoqutoken()
            if token['state'] == False:
                return token
            with open(token_file, 'w', encoding='utf-8') as of:
                of.write(token['access_token'])  #初始化写入的是tokenk
                return {
                    'state': True,
                    'access_token': token["access_token"],
                    'msg': '获取access_token成功'
                }

        else:  #如果有的话,过滤获取得到tokenk在返回
            if self.wenjian_guoqi(token_file) == True:
                log.warning('本地缓存已过期')
                os.remove(token_file)
                #time.sleep(1)
                return self.__huancun_token()
            else:
                log.info('正在读取本地缓存access_token')
                f_token = ''
                with open(token_file, 'r', encoding='utf-8') as of:
                    f_token = of.read()

                if f_token == '':
                    os.remove(token_file)
                    #time.sleep(1)
                    return self.__huancun_token()
                else:
                    return {
                        'state': True,
                        'access_token': f_token,
                        'msg': '获取access_token成功'
                    }
示例#13
0
    def main(self):
        try:
            self.hello = 0  #记录主人是否存在#设置为1 就不会一开始和你打招呼
            self.on1 = time.time()
            self.key = 0

            while 1:
                self.key += GPIO.input(self.channel)
                #print( self.key,time.time())
                #刷新率
                time.sleep(1)
                #周期秒#可以设置检测周期 几分钟都可以。自定义
                if time.time() - self.on1 >= 120:
                    #刷新计时时间
                    self.on1 = time.time()

                    if self.key != 0:
                        #print('主人还在')
                        self.key = 0
                    else:
                        #记录是否存在有人
                        #print('主人不在')
                        self.key = 0
                        self.hello = 0
                #发现有人存在,记录里也没有人就再次欢迎
                if self.key == 1 and self.hello == 0:
                    self.hello = 1

                    #os.system("sudo aplay  -q "+ os.path.join(self.config['root_path'], "data/yuyin/Probe_people.wav"))
                    self.visual = visual.Visual()
                    self.visual.success = self.success
                    self.visual.main()
        except:
            #防止树莓派系统莫名其妙的错误
            log.info("人体探测" * 10)
            time.sleep(1)
            self.main()
示例#14
0
 def error(self, bug='bug'):
     log.info(bug)
示例#15
0
文件: hecheng.py 项目: noenif/zimei
    def main(self, reobj):
        log.info('语音合成', reobj)

        re_type = reobj['type']  # system -- 系统回答,录音文件缓存,tuling -- 图灵机器不缓存
        re_text = reobj['data']

        #计算re_text字符串的md5
        md5 = self.md5_(re_text) + "." + self.FORMAT

        #在文件夹里查找.WAV文件
        audio_fill_ = os.path.join(self.audio_file, md5)

        if os.path.isfile(audio_fill_):
            #log.info("本地声音文件存在.....")
            self.success(position=audio_fill_)
            return True  #如果本地存在则不在执行下面代码

        try:
            if self.mylib.typeof(re_text) != 'str':
                return '参数1,需要输入合成语音的文字。字符串类型'

            token = self.huoqu_token.main()
            if token['state'] == False:
                return token

            tex = quote_plus(re_text)  # 此处re_text需要两次urlencode
            params = {
                'tok': token['access_token'],
                'tex': tex,
                'per': self.PER,
                'spd': self.SPD,
                'pit': self.PIT,
                'vol': self.VOL,
                'aue': self.AUE,
                'cuid': self.CUID,
                'lan': 'zh',
                'ctp': 1
            }  # lan ctp 固定参数
            data = urlencode(params)

            req = Request(self.TTS_URL, data.encode('utf-8'))

            try:
                f = urlopen(req, timeout=10)  #合成时间不多,识别最耗时
                result_str = f.read()
                if re_type == 'system':
                    save_file = audio_fill_
                else:
                    save_file = os.path.join(self.audio_file,
                                             'result.' + self.FORMAT)

                #log.info('保存地址:', save_file )
                with open(save_file, 'wb') as of:
                    of.write(result_str)

                self.success(position=save_file)

            except Exception as bug:
                self.error(bug)
                return {'state': False, 'data': '', 'msg': '可能是网络超时。'}

        except:
            return {'state': False, 'data': '', 'msg': '可能是网络超时。'}
示例#16
0
    def __init__(self, public_obj):

        log.info("人体探测启动")
        self.public_obj = public_obj
        self.start({})
示例#17
0
文件: check.py 项目: noenif/zimei
    def main(self, public_obj):
        log.info('启动监视进程')
        self.public_obj = public_obj

        #启动监视进程
        mp.Process(target=self.start_detect).start()
示例#18
0
 def success(self, jieguo):
     log.info(jieguo)
示例#19
0
    def __init__(self, public_obj):

        self.start()
        log.info("空间管理已启动")