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)
def test_can_prevent_deletion_of_message(self): message1 = "Hey there 1" message2 = "Hey there 2" final_speech = "<speak><p>Hey there 1</p><p>Hey there 2</p></speak>" message_manager_under_test = MessageManager(DeviceName="TEST") message_manager_under_test.publish_message( UUID="test", ExpirationDateTimeInUtc="2018-01-01 11:00", Body=message1) message_manager_under_test.publish_message( UUID="test", ExpirationDateTimeInUtc="2018-01-01 11:00", Body=message2) self.assertEqual(message_manager_under_test.write_speech(True), final_speech) self.assertEqual(message_manager_under_test.write_speech(False), final_speech)
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)