Пример #1
0
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)
Пример #2
0
    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
Пример #4
0
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)
Пример #5
0
    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
Пример #6
0
def bet_handler(handler_input):
    # handles that a bet has been set and remembers amount
    request_id_holder = handler_input.request_envelope.request.request_id
    directive_header = Header(request_id=request_id_holder)
    slots = handler_input.request_envelope.request.intent.slots

    bet = slots["amount"].value
    gm.player_chips.bet = int(bet)
    if not game_functions.can_bet(gm.player_chips.bet, gm.player_chips):
        output = f"""Sorry but you do not have enough for that bet.  You have a total of 
        {gm.player_chips.total}, how much would you like to bet?"""
        # 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)

        return (handler_input.response_builder.speak(output).add_directive(
            ElicitSlotDirective(
                slot_to_elicit="amount",
                updated_intent=Intent(
                    name="Betting",
                    confirmation_status=IntentConfirmationStatus.NONE,
                    slots={
                        "amount":
                        Slot(
                            name="amount",
                            confirmation_status=SlotConfirmationStatus.NONE,
                        )
                    },
                ),
            )).response)

    p_hand = gm.player_hand.hand_held()
    a_hand = gm.alexa_hand.holding()
    print("alexa: ", gm.alexa_hand.holding())
    print("player: ", gm.player_hand.holding())
    print("chips : ", gm.player_chips.total, "bet :", gm.player_chips.bet)
    output = f"""Okay you bet {bet}. You have {p_hand}.
    I have a {a_hand[1][1]} of {a_hand[1][0]} showing. What you like to  Hit or Stand?"""

    return (handler_input.response_builder.speak(
        output).set_should_end_session(False).response)
Пример #7
0
    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
Пример #8
0
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)