コード例 #1
0
 def handle(self, handler_input):
     presignedUrl = utils.create_presigned_url(utils.get_random_song())
     logger.info("Song to play: " + presignedUrl)
     return util.play(url=presignedUrl,
                      offset=0,
                      text="Let's play",
                      card_data="",
                      response_builder=handler_input.response_builder)
コード例 #2
0
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In NextOrPreviousIntentHandler")
     presignedUrl = utils.create_presigned_url(utils.get_random_song())
     logger.info("Song to play: " + presignedUrl)
     return util.play(url=presignedUrl,
                      offset=0,
                      text="",
                      card_data="",
                      response_builder=handler_input.response_builder)
コード例 #3
0
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In PlaybackFailedHandler")
     request = handler_input.request_envelope.request
     logger.info("Playback failed: {}".format(request.error))
     return util.play(url=util.audio_data(request)["url"],
                      offset=0,
                      text=None,
                      card_data=None,
                      response_builder=handler_input.response_builder)
コード例 #4
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlayCommandHandler")
        _ = handler_input.attributes_manager.request_attributes["_"]
        request = handler_input.request_envelope.request

        return util.play(url=util.audio_data(request)["url"],
                         offset=0,
                         text=None,
                         card_data=None,
                         response_builder=handler_input.response_builder)
コード例 #5
0
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In ResumeIntentHandler")
     request = handler_input.request_envelope.request
     _ = handler_input.attributes_manager.request_attributes["_"]
     speech = _(data.RESUME_MSG).format(
         util.audio_data(request)["card"]["title"])
     return util.play(url=util.audio_data(request)["url"],
                      offset=0,
                      text=speech,
                      card_data=util.audio_data(request)["card"],
                      response_builder=handler_input.response_builder)
コード例 #6
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In LaunchRequestOrPlayAudioHandler")

        _ = handler_input.attributes_manager.request_attributes["_"]
        request = handler_input.request_envelope.request

        return util.play(url=util.audio_data(request)["url"],
                         offset=0,
                         text=_(data.WELCOME_MSG).format(
                             util.audio_data(request)["card"]["name"]),
                         card_data=util.audio_data(request)["card"],
                         response_builder=handler_input.response_builder)
コード例 #7
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
コード例 #8
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        request = handler_input.request_envelope.request
        user_id = handler_input.request_envelope.session.user.user_id
        song_data = self.get_context(user_id)

        generated_song_text = data.GENERATED_SONG.format(
            song_data["song_name"])
        if song_data["key"]:
            generated_song_text += data.GENERATED_SONG_KEY.format(
                song_data["key"])
        if song_data["tempo"]:
            generated_song_text += data.GENERATED_SONG_TEMPO.format(
                song_data["tempo"])
        return util.play(url=song_data["backing_track_url"],
                         offset=0,
                         text=generated_song_text,
                         card_data=util.audio_data(request)["card"],
                         response_builder=handler_input.response_builder)
コード例 #9
0
    def handle(self, handler_input):
        stream = get_working_station(get_local_stations())
        logger.info(stream)
        if stream == None:
            handler_input.response_builder.speak(
                "Could not find a live station")
            logger.info("STREAM IS NONE")
            return handler_input.response_builder.response

        stream_url = stream['streams']['secure_hls_stream']
        try:
            currently_playing = get_recent_station_track(stream['id'])
            logger.info(f"{currently_playing} | {stream['id']}")
            echo_response = f"Now playing {currently_playing} on {stream['pronouncements'][0]['utterance']}"
        except:
            echo_response = f"Now playing {stream['pronouncements'][0]['utterance']}"
            logger.info(f"In exception | {stream['id']}")

        return util.play(stream_url, 0, echo_response, util.data.en['card'],
                         handler_input.response_builder)
コード例 #10
0
    def handle(self, handler_input):
        genreID = get_genre_id(favGenre())
        stream = get_genre_stream(genreID)

        return util.play(stream, 0, "Playing...", util.data.en['card'],
                         handler_input.response_builder)
コード例 #11
0
def launch_request_handler(handler_input):
    """
    Launch request
    :param handler_input: from the alexa skill
    :return: Response object with speech and audio and APL
    """
    # Calculation of page number for DG API, leap year and current date effects index of page
    try:
        context = handler_input.request_envelope.to_dict()['context']
        device_id = context['system']['device']['device_id']
        api_access_token = context['system']['api_access_token']
        settings_api_url = 'https://api.amazonalexa.com'
        r = requests.get(
            settings_api_url + '/v2/devices/' + device_id +
            '/settings/System.timeZone',
            headers={'Authorization': 'Bearer ' + api_access_token})
        zone = r.text
        now = datetime.now(pytz.timezone(zone.replace('"', '')))
    except Exception as err:
        now = datetime.now(pytz.timezone('America/New_York'))
        logging.error('Could\'nt get user time zone error:{0}'.format(
            str(err)))
    is_leap_year = calendar.isleap(now.year)
    if is_leap_year or now < pytz.UTC.localize(
            datetime.strptime('02-27-' + str(now.year) + ' 23:59:59.99',
                              '%m-%d-%Y %H:%M:%S.%f'), now):
        index = now.timetuple().tm_yday
    else:
        index = now.timetuple().tm_yday + 1
    # Get information using index from DG API
    data = get_sermon_of_the_day(index)
    apl_enabled = \
        handler_input.request_envelope.context.system.device.supported_interfaces.alexa_presentation_apl is not None
    speech_text = "Playing Sermon of the day from Desiring God, titled: " + data[
        'title']
    data_sources = {
        "bodyTemplate3Data": {
            "type": "object",
            "objectId": "bt3Sample",
            "textContent": {
                "title": {
                    "type": "PlainText",
                    "text": data['title']
                },
                "scripturalRef": {
                    "type": "PlainText",
                    "text": data['scriptural_ref']
                }
            },
            "hintText": "Try, \"Alexa, start over.\""
        }
    }
    info = {
        'title': data['title'],
        'subtitle': 'Desiring God',
        'icon_url': ICON_URL
    }
    response = util.play(url=data['sound_url'],
                         offset=0,
                         text=speech_text,
                         data=info,
                         response_builder=handler_input.response_builder,
                         document='alexa/APLTemplate.json',
                         datasources=data_sources,
                         apl_enabled=apl_enabled)
    # Persistance atributes to make playback requests easier and faster
    persistence_attr = handler_input.attributes_manager.persistent_attributes
    persistence_attr['url'] = data['sound_url']
    persistence_attr['data'] = info
    persistence_attr['document'] = 'alexa/APLTemplate.json'
    persistence_attr['datasources'] = data_sources
    persistence_attr['apl_enabled'] = apl_enabled
    persistence_attr['playing'] = True
    return response