예제 #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)
예제 #2
0
def test_can_pull_down_cache_folder():
    s3 = boto3.resource('s3')
    s3.create_bucket(Bucket="test-bucket")
    with patch('__builtin__.open', mock_open(read_data="TestData"),
               create=True) as m:
        with open('file') as h:
            s3.Bucket('test-bucket').put_object(Key='chimes/file1', Body=h)
            s3.Bucket('test-bucket').put_object(Key='chimes/file2', Body=h)
            s3.Bucket('test-bucket').put_object(Key='chimes/file3', Body=h)
    cache_manager = CacheManager(BucketName="test-bucket", CacheName="chimes")
    with patch.object(boto3.s3.transfer.S3Transfer,
                      "download_file",
                      return_value=None) as m:
        cache_manager.sync_remote_folder()
    assert len(m.mock_calls) == 3
예제 #3
0
def teach(no_audio, voice_id):
    try:
        c = ConfigHelper().config
        cache_manager = CacheManager(BucketName='pollexy-media',
                                     CacheName='chimes')
        cache_manager.sync_remote_folder()
        chime = c['teach_chime']
        speech = random.choice(c['teach_phrases'])
        speaker = Speaker(NoAudio=no_audio)
        logging.info('Teach phrase={}'.format(speech))
        speaker.generate_audio(Message=speech, TextType='text',
                               VoiceId=voice_id)
        speaker.speak(IncludeChime=True, Chime=chime)
        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)
예제 #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)