Exemple #1
0
def speak(person_name, location_name, ignore_motion, ignore_confirmation,
          voice_id, no_audio, simulate, fail_confirm):
    try:
        while True:
            click.echo("Checking for messages . . .")

            lm = LocationManager()
            loc = lm.get_location(location_name)
            if not ignore_motion and not loc.is_motion:
                print 'Exiting. No motion detected at ' + location_name
                exit(1)
            speaker = Speaker(NoAudio=no_audio)
            message_manager = MessageManager(LocationName=location_name)
            click.echo('getting files')
            cache_manager = CacheManager(BucketName='pollexy-media',
                                         CacheName='chimes')
            cache_manager.sync_remote_folder()
            print 'Writing speech'
            vid, speech = message_manager.write_speech(PersonName=person_name)
            if vid:
                voice_id = vid
            if not speech:
                print "I have nothing to say"
                message_manager.delete_sqs_msgs()
            else:
                print "Speech:\n\n%s" % speech
                try:
                    pm = PersonManager()
                    p = pm.get_person(person_name)
                    do_speech = True
                    if fail_confirm:
                        logging.warning("FORCE FAILING confirmation")
                        reason, do_speech = "NoResponse", False

                    elif not no_audio and p.require_physical_confirmation and \
                            not ignore_confirmation:
                        lv = LocationVerification(PersonName=person_name,
                                                  LocationName=location_name,
                                                  VoiceId=voice_id)
                        do_speech, retry_count, timeout = \
                            lv.verify_person_at_location(SpeechMethod=say)

                    if do_speech:
                        speaker = Speaker(NoAudio=no_audio)
                        speaker.generate_audio(Message=speech,
                                               TextType='ssml',
                                               VoiceId=voice_id)
                        speaker.speak(IncludeChime=True)
                        message_manager.succeed_speech(dont_delete=simulate)
                    else:
                        message_manager.fail_speech(Reason=reason)
                finally:
                    speaker.cleanup()

    except Exception as exc:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print repr(
            traceback.format_exception(exc_type, exc_value, exc_traceback))
        click.echo("Error: %s" % str(exc))
        exit(2)
Exemple #2
0
def test_verify_switch_with_press_returns_true():
    rpi_mock.GPIO.setmode.return_value = None
    rpi_mock.GPIO.setup.return_value = None
    rpi_mock.GPIO.input.return_value = False
    pm = PersonManager()
    p = Person(Name='calvin')
    p.require_physical_confirmation = True
    pm.update_window_set(p)
    l = LocationAvailability(LocationName='kitchen')
    id = 12
    l.with_switch(HardwareId=id, Color='Red', Name='Test', Style='Circle')
    lm = LocationManager()
    lm.update_input_capabilities(l)
    lv = LocationVerification(LocationName='kitchen', PersonName='calvin')

    done, count, timeout = lv.verify_person_at_location()
    print done, count, timeout
    assert done and count == 1 and timeout < 3
Exemple #3
0
def message_say(person_name, location_name, message, voice_id):
    try:
        lv = LocationVerification(PersonName=person_name,
                                  LocationName=location_name,
                                  VoiceId=voice_id)
        done, retry_count, timeout = \
            lv.verify_person_at_location(SpeechMethod=say)

        if done:
            say(Message=message, VoiceId=voice_id)
        else:
            print "Can't verify {} at location".format(person_name)

    except Exception as exc:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print repr(traceback.format_exception(exc_type, exc_value,
                   exc_traceback))
        click.echo("Error: %s" % str(exc))
        exit(2)
Exemple #4
0
def speak(person_name,
          location_name,
          ignore_motion,
          ignore_confirmation,
          voice_id,
          no_audio,
          simulate,
          fail_confirm,
          verbose):
    log = logging.getLogger('PollexyCli')
    if verbose:
        os.environ['LOG_LEVEL'] = 'DEBUG'
        log.setLevel(logging.DEBUG)
    try:
        while True:
            lm = LocationManager()
            loc = lm.get_location(location_name)
            if not ignore_motion and not loc.is_motion:
                print 'Exiting. No motion detected at ' + location_name
                exit(1)
            speaker = Speaker(NoAudio=no_audio)
            message_manager = MessageManager(LocationName=location_name)
            bm = message_manager.get_messages(MessageType='Bot',
                                              PersonName=person_name)
            if bm and len(bm) > 0:
                log.debug('Bot count = {}'.format(len(bm)))
                for bot in bm:
                    username = str(uuid.uuid4())
                    try:
                        lp = LexPlayer(
                            BotNames=bot.bot_names,
                            Alias="$LATEST",
                            Username=username,
                            VoiceId=voice_id,
                            IceBreaker=bot.ice_breaker,
                            Introduction=bot.introduction,
                            NoAudio=no_audio,
                            BotsRequired=bot.required_bots)
                        while (not lp.is_done):
                            lp.get_user_input()
                    except Exception as e:
                        print 'Bot failed: {}'.format(e)
                        raise
                message_manager.succeed_messages(dont_delete=simulate)

            cache_manager = CacheManager(BucketName='pollexy-media',
                                         CacheName='chimes')
            cache_manager.sync_remote_folder()
            vid, speech = message_manager.write_speech(PersonName=person_name)
            if vid:
                voice_id = vid
            if not speech:
                message_manager.succeed_messages(dont_delete=simulate)
                message_manager.delete_sqs_msgs()
            else:
                try:
                    pm = PersonManager()
                    p = pm.get_person(person_name)
                    do_speech = True
                    if fail_confirm:
                        log.warn("FORCE FAILING confirmation")
                        reason, do_speech = "NoResponse", False

                    elif not no_audio and p.require_physical_confirmation and \
                            not ignore_confirmation:
                        lv = LocationVerification(PersonName=person_name,
                                                  LocationName=location_name,
                                                  VoiceId=voice_id)
                        do_speech, retry_count, timeout = \
                            lv.verify_person_at_location(SpeechMethod=say)
                    log.debug('do_speech={}'.format(bool(do_speech)))
                    if fail_confirm:
                        message_manager.fail_messages(Reason=reason)
                    else:
                        if do_speech:
                            log.debug('starting speech')
                            speaker = Speaker(NoAudio=no_audio)
                            speaker.generate_audio(Message=speech,
                                                   TextType='ssml',
                                                   VoiceId=voice_id)
                            speaker.speak(IncludeChime=True)
                        log.debug('Succeeding messages')
                        message_manager.succeed_messages(dont_delete=simulate)
                finally:
                    speaker.cleanup()

    except Exception as exc:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print repr(traceback.format_exception(exc_type, exc_value,
                   exc_traceback))
        click.echo("Error: %s" % str(exc))
        exit(2)