Exemplo n.º 1
0
    def speak(self):
        ''' 用于正在说话的动画 '''
        image_path = dingdangpath.data('images', 'free4.gif')

        def f():
            self._DisplayGIF(image_path=image_path)

        self.next.set()
        self.queue.put(f)
Exemplo n.º 2
0
    def listen(self):
        ''' 用于正在监听的动画 '''
        image_path = dingdangpath.data('images', 'free6.gif')

        def f():
            self._DisplayGIF(image_path=image_path)

        self.next.set()
        self.queue.put(f)
Exemplo n.º 3
0
    def wakeup(self):
        ''' 用于唤醒动画或启动动画 '''
        a = ['1', '2', '3']
        b = random.sample(a, 1)
        name = "welcome" + str(b[0]) + ".gif"
        image_path = dingdangpath.data('images', name)

        def f():
            self._DisplayGIFOnce(image_path=image_path)

        self.next.set()
        self.queue.put(f)
Exemplo n.º 4
0
    def sys_info(self, text1, text2, text3, text4):
        ''' 用于显示系统信息文本 '''
        font_path = dingdangpath.data('fonts', 'C&C Red Alert [INET].ttf')

        def f():
            self._DisplayText(font_path=font_path,
                              text1=text1,
                              text2=text2,
                              text3=text3,
                              text4=text4)

        self.next.set()
        self.queue.put(f)
Exemplo n.º 5
0
def afterListen(mic, profile, wxbot=None):
    mic.play_no_block(dingdangpath.data('audio', 'beep_lo.wav'))
Exemplo n.º 6
0
def beforeListen(mic, profile, wxbot=None):
    mic.play(dingdangpath.data('audio', 'beep_hi.wav'))
Exemplo n.º 7
0
def handle(text, mic, profile, wxbot=None, pixels=None, oled=None):
    """
        Reports the current time based on the user's timezone.

        Arguments:
        text -- user-input, typically transcribed speech
        mic -- used to interact with the user (for both input and output)
        profile -- contains information related to the user (e.g., phone
                   number)
        wxbot -- wechat bot instance
    """
    sys.path.append(dingdangpath.LIB_PATH)
    from app_utils import sendToUser

    quality = 100
    count_down = 3
    dest_path = os.path.expanduser('~/pictures')
    vertical_flip = False
    horizontal_flip = False
    send_to_user = True
    sound = True
    usb_camera = False
    # read config
    if profile[SLUG] and 'enable' in profile[SLUG] and \
       profile[SLUG]['enable']:
        if 'count_down' in profile[SLUG] and \
           profile[SLUG]['count_down'] > 0:
            count_down = profile[SLUG]['count_down']
        if 'quality' in profile[SLUG] and \
           profile[SLUG]['quality'] > 0:
            quality = profile[SLUG]['quality']
        if 'dest_path' in profile[SLUG] and \
           profile[SLUG]['dest_path'] != '':
            dest_path = profile[SLUG]['dest_path']
        if 'vertical_flip' in profile[SLUG] and \
           profile[SLUG]['vertical_flip']:
            vertical_flip = True
        if 'horizontal_flip' in profile[SLUG] and \
           profile[SLUG]['horizontal_flip']:
            horizontal_flip = True
        if 'send_to_user' in profile[SLUG] and \
           not profile[SLUG]['send_to_user']:
            send_to_user = False
        if 'sound' in profile[SLUG] and \
           not profile[SLUG]['sound']:
            sound = False
        if 'usb_camera' in profile[SLUG] and \
                profile[SLUG]['usb_camera']:
            usb_camera = True
        if any(word in text for word in [u"安静", u"偷偷", u"悄悄"]):
            sound = False
        try:
            if not os.path.exists(dest_path):
                os.makedirs(dest_path)
        except Exception:
            mic.say(u"抱歉,照片目录创建失败", cache=True)
            return
        dest_file = os.path.join(dest_path, "%s.jpg" % time.time())
        if usb_camera:
            command = "fswebcam --no-banner -r 640x480 -q "
            if vertical_flip:
                command = command + ' -s v '
            if horizontal_flip:
                command = command + '-s h '
            command = command + dest_file
        else:
            command = ['raspistill', '-o', dest_file, '-q', str(quality)]
            if count_down > 0 and sound:
                command.extend(['-t', str(count_down * 1000)])
            if vertical_flip:
                command.append('-vf')
            if horizontal_flip:
                command.append('-hf')
        if sound and count_down > 0:
            mic.say(u"收到,%d秒后启动拍照" % (count_down), cache=True)
            if usb_camera:
                time.sleep(count_down)

        process = subprocess.Popen(command, shell=usb_camera)
        res = process.wait()
        if res != 0:
            if sound:
                mic.say(u"拍照失败,请检查相机是否连接正确", cache=True)
            return
        if sound:
            mic.play(dingdangpath.data('audio', 'camera.wav'))
        # send to user
        if send_to_user:
            target = '邮箱'
            if wxbot is not None and wxbot.my_account != {} and \
               ('prefers_email' not in profile or
               not profile['prefers_email']):
                target = '微信'
            if sound:
                mic.say(u'拍照成功!正在发送照片到您的%s' % target, cache=True)
            if sendToUser(profile, wxbot, u"这是刚刚为您拍摄的照片", "", [], [dest_file]):
                if sound:
                    mic.say(u'发送成功', cache=True)
            else:
                if sound:
                    mic.say(u'发送失败了', cache=True)
    else:
        mic.say(u"请先在配置文件中开启相机拍照功能", cache=True)
Exemplo n.º 8
0
def afterListen(mic, profile, wxbot=None):
    mic.play_no_block(dingdangpath.data('audio', 'beep_lo.wav'))
Exemplo n.º 9
0
def beforeListen(mic, profile, wxbot=None):
    mic.play(dingdangpath.data('audio', 'beep_hi.wav'))