Reputation: 11
I've tried very hard to figure out how to make my Alexa skill to play audio but I cannot find a solution. I emailed the amazon developer support and they sent me the following code. I would love it if someone could explain to me the logic behind this code. Also, how would I make this code into a fully functional Alexa skill? Thank you.
import logging
import typing
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import (
AbstractRequestHandler, AbstractRequestInterceptor, AbstractExceptionHandler)
import ask_sdk_core.utils as ask_utils
from ask_sdk_core.utils import is_intent_name, is_request_type
from ask_sdk_core.api_client import DefaultApiClient
from ask_sdk_core.skill_builder import SkillBuilder, CustomSkillBuilder
from ask_sdk_core.dispatch_components import AbstractRequestInterceptor
from ask_sdk_core.dispatch_components import AbstractResponseInterceptor
from ask_sdk_model.services.service_exception import ServiceException
if typing.TYPE_CHECKING:
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
WELCOME_MESSAGE = "This is Alexa regular speech, followed by the sound effect named Bear Groan Roar <audio src='soundbank://soundlibrary/animals/amzn_sfx_bear_groan_roar_01'/>"
WHAT_DO_YOU_WANT = "What do you want to ask?"
class LaunchRequestHandler(AbstractRequestHandler):
"""Handler for Skill Launch."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
return handler_input.response_builder.speak(WELCOME_MESSAGE).ask(WHAT_DO_YOU_WANT).response
sb = CustomSkillBuilder(api_client=DefaultApiClient())
sb.add_request_handler(LaunchRequestHandler())
Upvotes: 1
Views: 985
Reputation: 304
I understand you are trying to play a streaming music station, if this is the case, this will be implemented using AudioPlayer interface, please find more information on the link below: https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html
There is an AudioPlayer sample skill which actually streams from a radio station already to which you can refer. That can be found here: https://github.com/alexa-samples/skill-sample-nodejs-audio-player , also in python https://github.com/alexa-samples/skill-sample-python-audio-player . You will need to change the url stream and add your own.
Please take into account that the URL you provide in the audioItem.stream.url property must meet these requirements: https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#audio-stream-requirements
Upvotes: 1