def waiting(handler_input, msg): request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) speech = SpeakDirective(speech=msg) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = handler_input.service_client_factory.get_directive_service( ) directive_service_client.enqueue(directive_request)
def progressive_response(self, handler_input, sentence): request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) speech = SpeakDirective(speech=sentence) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = handler_input.service_client_factory.get_directive_service( ) directive_service_client.enqueue(directive_request) # time.sleep(1) return
def get_progressive_response(handler_input): # type: (HandlerInput) -> None request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) speech = SpeakDirective(speech="Ok, give me a minute") directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = handler_input.service_client_factory.get_directive_service( ) directive_service_client.enqueue(directive_request) time.sleep(5) return
def _progressive_response_(handler_input, speech): #Call Alexa Directive Service. requestEnvelope = handler_input.request_envelope directiveServiceClient = handler_input.service_client_factory.get_directive_service(); requestId = requestEnvelope.request.request_id; endpoint = handler_input.request_envelope.context.system.api_endpoint accessToken = handler_input.request_envelope.context.system.api_access_token directive = SendDirectiveRequest( header = Header(requestId), directive = SpeakDirective( speech = speech ) ) #send directive return directiveServiceClient.enqueue(directive)
def handle(self, handler_input): # type: (HandlerInput) -> Response logger.info("In PlayGeneratedMusicHandler") request = handler_input.request_envelope.request slots = request.intent.slots song_name = self.get_song_resolved_value(slots) tmp_mma_file_name = os.path.join( "song_data", self.__get_file_name_underscore(song_name)) logger.info("Looking for file path: {}".format(tmp_mma_file_name)) if os.path.exists(tmp_mma_file_name): request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) speech = SpeakDirective(speech=random.choice( data.PROGRESSIVE_RESPONSE).format(song_name)) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = handler_input.service_client_factory.get_directive_service( ) directive_service_client.enqueue(directive_request) user_id = handler_input.request_envelope.session.user.user_id tempo = slots.get("Tempo").value key = slots.get("Key").value backing_track_url = BackingTrackGenerator().get_backing_track( slots) self.save_context(backing_track_url, user_id, song_name, tempo, key) generated_song_text = data.GENERATED_SONG.format(song_name) if key: generated_song_text += data.GENERATED_SONG_KEY.format(key) if tempo: generated_song_text += data.GENERATED_SONG_TEMPO.format(tempo) return util.play(url=backing_track_url, offset=0, text=generated_song_text, card_data=util.audio_data(request)["card"], response_builder=handler_input.response_builder) else: return handler_input.response_builder.speak( "Sorry, I couldn't find a lead sheet called {}".format( song_name)).response
def handle(self, handler_input): session_attr = handler_input.attributes_manager.session_attributes speech_text = ("you spelt it incorrectly. The correct spelling is {}").format(get_word_spelling(session_attr['word'])) if "word" in session_attr: if ((session_attr['word'] == 'word' and ask_utils.is_intent_name("WordSpellingIntent")(handler_input)) or (session_attr['word'] == 'apple' and ask_utils.is_intent_name("AppleSpellingIntent")(handler_input)) or (session_attr['word'] == 'ball' and ask_utils.is_intent_name("BallSpellingIntent")(handler_input))): speech_text = ("you spelt it correctly as {}").format(get_word_spelling(session_attr['word'])) request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) speech = SpeakDirective(speech="Ok, give me a minute") directive_request = SendDirectiveRequest( header=directive_header, directive=speech) directive_service_client = handler_input.service_client_factory.get_directive_service() directive_service_client.enqueue(directive_request) # Adding a 2 second sleep for testing time.sleep(2) return handler_input.response_builder.speak(speech_text).response
def stand_handler(handler_input): request_id_holder = handler_input.request_envelope.request.request_id directive_header = Header(request_id=request_id_holder) if game_functions.isbust(gm.player_hand): output = f"""Sorry you bust with a total of {gm.player_hand.value}. My Turn, I have {gm.alexa_hand.hand_held()} for a total of {gm.alexa_hand.value}""" speech = SpeakDirective(speech=output) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = ( handler_input.service_client_factory.get_directive_service()) directive_service_client.enqueue(directive_request) print("alexa: ", gm.alexa_hand.holding()) print("player: ", gm.player_hand.holding()) hit_or_stand = game_functions.say_hit_or_stand(gm.player_hand, gm.alexa_hand) output = f""" I have {gm.alexa_hand.hand_held()}, for a total of {gm.alexa_hand.value}, hmm I think I will {hit_or_stand}""" speech = SpeakDirective(speech=output) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = ( handler_input.service_client_factory.get_directive_service()) directive_service_client.enqueue(directive_request) while game_functions.should_alexa_hit(gm.player_hand, gm.alexa_hand): gm.alexa_hand.hit(gm.deck) current_hand = gm.alexa_hand.hand_held() output = f""" I have {current_hand}, for a total of {gm.alexa_hand.value}""" speech = SpeakDirective(speech=output) directive_request = SendDirectiveRequest(header=directive_header, directive=speech) directive_service_client = ( handler_input.service_client_factory.get_directive_service()) directive_service_client.enqueue(directive_request) print("alexa: ", gm.alexa_hand.holding()) print("player: ", gm.player_hand.holding()) print("chips: ", gm.player_chips.total) # check if alexa has bust if gm.alexa_hand.value > 21: gm.player_chips.win_bet() output = f"I bust so You won. Play again?" print("chips : ", gm.player_chips.total) return (handler_input.response_builder.speak( output).set_should_end_session(False).response) # if alexa is less than player, player wins, add winnings, draw new cards if gm.alexa_hand.value < gm.player_hand.value and not game_functions.isbust( gm.player_hand): gm.player_chips.win_bet() output = f"You won. Play again?" print("alexa: ", gm.alexa_hand.holding()) print("player: ", gm.player_hand.holding()) print("chips: ", gm.player_chips.total) return (handler_input.response_builder.speak( output).set_should_end_session(False).response) elif gm.alexa_hand.value >= gm.player_hand.value: gm.player_chips.lose_bet() output = f"I have a total of {gm.alexa_hand.value} so you lose. Play again?" print("alexa: ", gm.alexa_hand.holding()) print("player: ", gm.player_hand.holding()) print("chips: ", gm.player_chips.total) return (handler_input.response_builder.speak( output).set_should_end_session(False).response) else: output = f"A draw. Play again?" print("alexa: ", gm.alexa_hand.holding()) print("player: ", gm.player_hand.holding()) print("chips: ", gm.player_chips.total) return (handler_input.response_builder.speak( output).set_should_end_session(False).response)