Exemplo n.º 1
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     # input param
     self.conf_path = conf_path
     self.conf = getConf(self.conf_path, root_key='audio')
     if self.conf['target'] == 'pi':
         self.t2s = Text2SpeechBaidu(self.conf_path)  # sync
     else:
         self.t2s = Text2SpeechXunFei(self.conf_path)  # sync
     self.executor_t2s = concurrent.futures.ProcessPoolExecutor(2)  # async
     if self.conf['use_custom_manager']:
         # create proxy manager
         mgr = SyncManager(
             (get_lan_ip(), self.conf['custom_manager_port']),
             self.conf['custom_manager_authkey'].encode('utf8'))
         sleep(0.5)  # wait for manager to start
         mgr.connect()
     else:
         mgr = multiprocessing.Manager()
     self.q_audio = mgr.Queue()
     #-#        debug('audio data queue created. %s', self.q_audio)
     self.event_exit = mgr.Event()
     multiprocessing.current_process(
     ).authkey = self.conf['custom_manager_authkey'].encode(
         'utf8')  # https://bugs.python.org/issue7503
     self.proc_play = multiprocessing.Process(target=self.playAudioFromQ,
                                              args=(self.q_audio,
                                                    self.event_exit))
     self.proc_play.start()
     #-#        debug('play background proc start. %s', self.proc_play)
     # 触发进程池worker进程创建, 貌似提前创建的占用内存小些
     self.executor_t2s.map(noop_func, (None, None))
Exemplo n.º 2
0
    def __init__(self, conf_path='config/pn_conf.yaml'):
        global attachment_dir
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path, root_key='itchat')

        attachment_dir = os.path.abspath(self.conf['attachment_dir'])

        self.thread_id = None

        self.gid = None  # 记录我们群的UserName
        if self.conf['use_custom_manager']:
            # create proxy manager
            class MySyncManager(SyncManager):
                pass

            MySyncManager.register('get_wx_send_q')
            mgr = MySyncManager(
                (get_lan_ip(), self.conf['custom_manager_port']),
                self.conf['custom_manager_authkey'].encode('utf8'))
            #-#            sleep(0.5)  # wait for manager to start
            mgr.connect()

            self.q_send = mgr.get_wx_send_q()
        else:
            mgr = multiprocessing.Manager()
            self.q_send = mgr.Queue()
        self.event_exit = mgr.Event()
        multiprocessing.current_process(
        ).authkey = self.conf['custom_manager_authkey'].encode(
            'utf8')  # https://bugs.python.org/issue7503
        self.proc_wx = multiprocessing.Process(target=self.run,
                                               args=(self.event_exit,
                                                     self.q_send))
        self.proc_wx.start()
Exemplo n.º 3
0
 def __init__(self, conf_path='config/pn_conf.yaml'):
     # input param
     self.conf_path = conf_path
     self.conf = getConf(self.conf_path, root_key='remote_manager')
     # create remote manager
     p_mgr = multiprocessing.Process(
         target=server_manager,
         args=((get_lan_ip(), self.conf['custom_manager_port']),
               self.conf['custom_manager_authkey'].encode('utf8')))
     p_mgr.start()
Exemplo n.º 4
0
    def __init__(self, conf_path='config/pn_conf.yaml'):
        self.conf_path = os.path.abspath(conf_path)
        self.conf = getConf(self.conf_path)
        self.mgr = None
        self.send_q = None
        if self.conf['prom_notify']['enable_wx']:
            itchat_conf = self.conf['itchat']
            if itchat_conf['use_custom_manager']:
                # create proxy manager
                class MySyncManager(SyncManager):
                    pass

                MySyncManager.register('get_wx_send_q')
                self.mgr = MySyncManager(
                    (get_lan_ip(), itchat_conf['custom_manager_port']),
                    itchat_conf['custom_manager_authkey'].encode('utf8'))
                self.mgr.connect()
                self.send_q = self.mgr.get_wx_send_q()  # 获取到了发送队列
            else:
                warn(
                    'itchat not use custom manager, can\'t send msg via wx !!!'
                )
        else:
            warn('wx not enabled, can\'t send msg via wx !!!')