Beispiel #1
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        # go to beginning of track
        logger.info("In StartOverHandler")
        persistence_attr = handler_input.attributes_manager.persistent_attributes
        track_number = int(persistence_attr["track_number"])

        audio_key = trackInfo.track_info[track_number]["url"]
        audio_url = create_presigned_url(audio_key)
        persistence_attr["playback_settings"]["offset_in_milliseconds"] = 0
        persistence_attr["playback_settings"]["url"] = audio_url
        persistence_attr["playback_settings"]["token"] = audio_key

        persistence_attr["playback_settings"]["next_stream_enqueued"] = False

        handler_input.attributes_manager.persistent_attributes = persistence_attr

        card = StandardCard(title=trackInfo.track_info[track_number]["title"],
                            text=trackInfo.track_info[track_number]["artist"],
                            image=Image(small_image_url=small_image_url,
                                        large_image_url=large_image_url))

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ALL,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))

        handler_input.response_builder.set_card(card).add_directive(
            directive).set_should_end_session(True)

        return handler_input.response_builder.response
 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)
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In PlaybackNearlyFinishedHandler")
     logger.info("Playback nearly finished")
     request = handler_input.request_envelope.request
     presignedUrl = utils.create_presigned_url(utils.get_random_song())
     logger.info("Song to play: " + presignedUrl)
     return util.play_later(url=presignedUrl,
                            card_data="",
                            response_builder=handler_input.response_builder)
 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)
Beispiel #5
0
    def post(self):
        data = request.files
        image = data.get("image")
        print(image)
        print(dir(image))
        print(image.content_type)
        print(image.filename)
        print(image.name)
        print(image.mimetype)
        print(image.mimetype_params)
        print(image.stream)

        # s3 = boto3.resource('s3',
        #                     aws_access_key_id=os.environ["ACCESS_KEY"],
        #                     aws_secret_access_key=os.environ["SECRETE_KEY"],
        #                     config=Config(signature_version="s3v4"))
        bucket = os.environ["BUCKET"]
        region = os.environ["REGION"]
        key = image.filename.split('.')[
            0]  #"".join(str(uuid.uuid4()).split("-"))
        extension = image.filename.split('.')[-1]
        full_file_name = '.'.join([key, extension])
        # opening a file
        f = open('Machine.jpg', 'r+')
        jpgdata = f.read()
        # print("extension ",extension)
        # print(type(key))
        # obj = s3.Bucket(bucket).put_object(Key=full_file_name,Body=image, ContentType=image.content_type)
        # print(obj)

        # image_url = f"https://s3-{region}.amazonaws.com/{bucket}/{'.'.join([key,extension])}"
        # return {"status": "Ok","url": image_url}, 201
        response = create_presigned_url(bucket, 'Machine.jpg')

        files = {'file': ('Machine.jpg', jpgdata)}
        http_response = requests.post(response['url'],
                                      data=response['fields'],
                                      files=files)
        # If successful, returns HTTP status code 204
        print("response fields ", response['fields'])
        logging.info(
            f'File upload HTTP status code: {http_response.status_code}')

        print(dir(http_response))
        print(http_response.json)
        # print(http_response.data)
        print(http_response.text)

        return response
Beispiel #6
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlaybackNearlyFinishedHandler")

        audio_key = "Media/RemovalMen_Borderline.mp3"

        audio_url = create_presigned_url(audio_key)

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ENQUEUED,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))
        handler_input.response_builder.set_card(card).add_directive(
            directive).set_should_end_session(True)
        return handler_input.response_builder.response
Beispiel #7
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("in AudioPlayIntent")
        speech_text = "Welcome to my audio player"
        audio_key = "Media/RemovalMen_Borderline.mp3"

        audio_url = create_presigned_url(audio_key)

        directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ALL,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=None),
                                                       metadata=None))
        handler_input.response_builder.speak(speech_text).set_card(
            card).add_directive(directive).set_should_end_session(True)

        return handler_input.response_builder.response
Beispiel #8
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("In PlaybackNearlyFinishedHandler")
        persistence_attr = handler_input.attributes_manager.persistent_attributes
        track_number = int(persistence_attr["track_number"])
        next_track = (track_number + 1) % len(trackInfo.track_info)
        previous_token = persistence_attr["playback_settings"]["token"]
        # this the previous token for the next track, i.e. at the moment - it's the current one
        # see https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#playlist-progression

        track_number = next_track  # for consistency

        audio_key = trackInfo.track_info[track_number]["url"]
        audio_url = create_presigned_url(audio_key)

        persistence_attr["playback_settings"]["offset_in_milliseconds"] = 0
        persistence_attr["playback_settings"]["token"] = audio_key
        persistence_attr["playback_settings"]["url"] = audio_url
        # if i update persistence_attr["track_number"] here, then start over (and resume and play?) picks up wrong track (the next one)
        # if not how does the next track know what to play after automatically playing next track from enqueue?
        # persistence_attr["track_number"] = track_number
        persistence_attr["playback_settings"]["next_stream_enqueued"] = True
        # check this in playbackfinished. If true, then increment next track

        handler_input.attributes_manager.persistent_attributes = persistence_attr

        directive = PlayDirective(play_behavior=PlayBehavior.ENQUEUE,
                                  audio_item=AudioItem(stream=Stream(
                                      token=audio_key,
                                      url=audio_url,
                                      offset_in_milliseconds=0,
                                      expected_previous_token=previous_token),
                                                       metadata=None))
        # but next track will have new url, but track_number will be wrong

        handler_input.response_builder.add_directive(
            directive).set_should_end_session(True)

        return handler_input.response_builder.response
Beispiel #9
0
from ask_sdk_model import Response

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

from ask_sdk_core.utils import is_intent_name
from ask_sdk_core.utils import get_intent_name
from ask_sdk_core.utils import is_request_type
from ask_sdk_model.ui import StandardCard, Image, SimpleCard
from ask_sdk_model.interfaces.audioplayer import (PlayDirective, PlayBehavior,
                                                  AudioItem, Stream,
                                                  AudioItemMetadata,
                                                  StopDirective)
from ask_sdk_model.interfaces import display

small_image_url = create_presigned_url("Media/Note108.png")
large_image_url = create_presigned_url("Media/Note512.png")

audio_data = {
    "card": {
        "title": 'My music',
        "text": 'I like music',
    }
}
card = StandardCard(title=audio_data["card"]["title"],
                    text=audio_data["card"]["text"],
                    image=Image(small_image_url=small_image_url,
                                large_image_url=large_image_url))


class LaunchRequestHandler(AbstractRequestHandler):
Beispiel #10
0
def generate_presigned_url():
    # creating signed url via S3
    url = create_presigned_url(environ.get('AWS_S3_BUCKET'),
                               environ.get('AWS_S3_RESOURCE_URL'))
    return {'url': url}
Beispiel #11
0
def playlist():
    return [{
        "url": create_presigned_url("Media/Jellyfish.mp4"),
        "title": "The Jellyfish Video",
        "subtitle": "Just a random subtitle"
    }]
Beispiel #12
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        logger.info("in AudioPlayIntent")
        persistence_attr = handler_input.attributes_manager.persistent_attributes

        if (is_intent_name("PlayAudio")(handler_input)):
            logger.info("play Audio")
            # first time - set track to zero
            track_number = 0
            persistence_attr["track_number"] = track_number

            card = StandardCard(
                title=trackInfo.track_info[track_number]["title"],
                text=trackInfo.track_info[track_number]["artist"],
                image=Image(small_image_url=small_image_url,
                            large_image_url=large_image_url))

            audio_key = trackInfo.track_info[track_number]["url"]
            audio_url = create_presigned_url(audio_key)
            persistence_attr["playback_settings"]["url"] = audio_url
            persistence_attr["playback_settings"]["token"] = audio_key
            persistence_attr["playback_settings"]["offset_in_milliseconds"] = 0
            persistence_attr["playback_settings"][
                "next_stream_enqueued"] = False

            speech_text = "Playing your music"
            directive = PlayDirective(play_behavior=PlayBehavior.REPLACE_ALL,
                                      audio_item=AudioItem(stream=Stream(
                                          token=audio_key,
                                          url=audio_url,
                                          offset_in_milliseconds=0,
                                          expected_previous_token=None),
                                                           metadata=None))
            handler_input.response_builder.speak(speech_text).set_card(
                card).add_directive(directive).set_should_end_session(True)

        else:
            # resume
            logger.info("Resume")
            track_number = int(persistence_attr["track_number"])

            audio_key = trackInfo.track_info[track_number]["url"]
            audio_url = create_presigned_url(audio_key)
            persistence_attr["playback_settings"]["url"] = audio_url
            persistence_attr["playback_settings"]["token"] = audio_key

            card = StandardCard(
                title=trackInfo.track_info[track_number]["title"],
                text=trackInfo.track_info[track_number]["artist"],
                image=Image(small_image_url=small_image_url,
                            large_image_url=large_image_url))

            directive = PlayDirective(
                play_behavior=PlayBehavior.REPLACE_ALL,
                audio_item=AudioItem(stream=Stream(
                    token=audio_key,
                    url=audio_url,
                    offset_in_milliseconds=persistence_attr[
                        "playback_settings"]["offset_in_milliseconds"],
                    expected_previous_token=None),
                                     metadata=None))

            handler_input.response_builder.set_card(card).add_directive(
                directive).set_should_end_session(True)

        handler_input.attributes_manager.persistent_attributes = persistence_attr
        return handler_input.response_builder.response