Beispiel #1
0
    def run(self):
        salutation = (u"%s,我能为您做什么?" % config.get("first_name", u'主人'))

        persona = config.get("robot_name", 'DINGDANG')
        conversation = Conversation(persona, self.mic)

        # create wechat robot
        if config.get('wechat', False):
            self.wxBot = WechatBot.WechatBot(conversation.brain)
            self.wxBot.DEBUG = True
            self.wxBot.conf['qr'] = 'tty'
            conversation.wxbot = self.wxBot
            t = threading.Thread(target=self.start_wxbot)
            t.start()

        self.mic.say(salutation, cache=True)
        conversation.handleForever()
Beispiel #2
0
    def run(self):
        salutation = (u"%s,我能为您做什么?" % config.get("first_name", u'主人'))

        persona = config.get("robot_name", 'HUIMEIJINGLING')
        conversation = Conversation(persona, self.mic)

        # create wechat robot
        if config.get('wechat', False):
            self.wxBot = WechatBot.WechatBot(conversation.brain)
            self.wxBot.DEBUG = True
            self.wxBot.conf['qr'] = 'tty'
            conversation.wxbot = self.wxBot
            t = threading.Thread(target=self.start_wxbot)
            t.start()

        self.mic.say(salutation, cache=True)
        conversation.handleForever()
Beispiel #3
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        config.init()

        stt_engine_slug = config.get('stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        slug = config.get('stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(slug)

        tts_engine_slug = config.get('tts_engine',
                                     tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Beispiel #4
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        config.init()

        stt_engine_slug = config.get('stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        slug = config.get('stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(slug)

        tts_engine_slug = config.get('tts_engine',
                                     tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(
            tts_engine_class.get_instance(),
            stt_passive_engine_class.get_passive_instance(),
            stt_engine_class.get_active_instance())
    def run(self):
        salutation = (u"%s,我能为您做什么?" % config.get("first_name", u'主人'))

        persona = config.get("robot_name", 'DINGDANG')
        conversation = Conversation(persona, self.mic)

        # create wechat robot
        if config.get('wechat', False):
            self.wxBot = WechatBot.WechatBot(conversation.brain)
            self.wxBot.DEBUG = True
            self.wxBot.conf['qr'] = 'tty'
            conversation.wxbot = self.wxBot
            t = threading.Thread(target=self.start_wxbot)
            t.start()

        #self.mic.say(salutation, cache=True)
        self.mic.say(u"叮咚叮咚,我能为你做什么", cache=True)
        #self.mic.music_play('/home/pi/123.mp3')
        conversation.handleForever()
Beispiel #6
0
 def handle_msg_all(self, msg):
     # ignore the msg when handling plugins
     profile = config.get()
     if (msg['msg_type_id'] == 1
             and (msg['to_user_id'] == self.my_account['UserName']
                  or msg['to_user_id'] == u'filehelper')):
         from_user = profile['first_name'] + '说:'
         msg_data = from_user + msg['content']['data']
         if msg['content']['type'] == 0:
             if msg_data.startswith(profile['robot_name_cn'] + ": "):
                 return
             if self.music_mode is not None:
                 return self.handle_music_mode(msg_data)
             self.brain.query([msg_data], self, True)
         elif msg['content']['type'] == 4:
             mp3_file = os.path.join(dingdangpath.TEMP_PATH,
                                     'voice_%s.mp3' % msg['msg_id'])
             # echo or command?
             if 'wechat_echo' in profile and not profile['wechat_echo']:
                 # 执行命令
                 mic = self.brain.mic
                 wav_file = mp3_to_wav(mp3_file)
                 with open(wav_file) as f:
                     command = mic.active_stt_engine.transcribe(f)
                     if command:
                         if self.music_mode is not None:
                             return self.handle_music_mode(msg_data)
                         self.brain.query(command, self, True)
                     else:
                         mic.say("什么?")
             else:
                 # 播放语音
                 player.get_music_manager().play_block(mp3_file)
     elif msg['msg_type_id'] == 4:
         if 'wechat_echo_text_friends' in profile and \
            (
                msg['user']['name'] in profile['wechat_echo_text_friends']
                or
                'ALL' in profile['wechat_echo_text_friends']
            ) and msg['content']['type'] == 0:
             from_user = msg['user']['name'] + '说:'
             msg_data = from_user + msg['content']['data']
             self.brain.query([msg_data], self, True)
         elif 'wechat_echo_voice_friends' in profile and \
              (
                 msg['user']['name'] in profile['wechat_echo_voice_friends']
                 or
                 'ALL' in profile['wechat_echo_voice_friends']
              ) and msg['content']['type'] == 4:
             mp3_file = os.path.join(dingdangpath.TEMP_PATH,
                                     'voice_%s.mp3' % msg['msg_id'])
             player.get_music_manager().play_block(mp3_file)
Beispiel #7
0
 def handle_msg_all(self, msg):
     # ignore the msg when handling plugins
     profile = config.get()
     if (msg['msg_type_id'] == 1 and
        (msg['to_user_id'] == self.my_account['UserName'] or
             msg['to_user_id'] == u'filehelper')):
         from_user = profile['first_name'] + '说:'
         msg_data = from_user + msg['content']['data']
         if msg['content']['type'] == 0:
             if msg_data.startswith(profile['robot_name_cn']+": "):
                 return
             if self.music_mode is not None:
                 return self.handle_music_mode(msg_data)
             self.brain.query([msg_data], self, True)
         elif msg['content']['type'] == 4:
             mp3_file = os.path.join(dingdangpath.TEMP_PATH,
                                     'voice_%s.mp3' % msg['msg_id'])
             # echo or command?
             if 'wechat_echo' in profile and not profile['wechat_echo']:
                 # 执行命令
                 mic = self.brain.mic
                 wav_file = mp3_to_wav(mp3_file)
                 with open(wav_file) as f:
                     command = mic.active_stt_engine.transcribe(f)
                     if command:
                         if self.music_mode is not None:
                             return self.handle_music_mode(msg_data)
                         self.brain.query(command, self, True)
                     else:
                         mic.say("什么?")
             else:
                 # 播放语音
                 player.get_music_manager().play_block(mp3_file)
     elif msg['msg_type_id'] == 4:
         if 'wechat_echo_text_friends' in profile and \
            (
                msg['user']['name'] in profile['wechat_echo_text_friends']
                or
                'ALL' in profile['wechat_echo_text_friends']
            ) and msg['content']['type'] == 0:
             from_user = msg['user']['name'] + '说:'
             msg_data = from_user + msg['content']['data']
             self.brain.query([msg_data], self, True)
         elif 'wechat_echo_voice_friends' in profile and \
              (
                 msg['user']['name'] in profile['wechat_echo_voice_friends']
                 or
                 'ALL' in profile['wechat_echo_voice_friends']
              ) and msg['content']['type'] == 4:
             mp3_file = os.path.join(dingdangpath.TEMP_PATH,
                                     'voice_%s.mp3' % msg['msg_id'])
             player.get_music_manager().play_block(mp3_file)