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())