Hi all,
Just wanted to share my findings on this topic and a possible solution to stream from Youtube Music to Echo devices. The overall flow would be like this;
- Music Source: Install Youtube Music integration: GitHub - KoljaWindeler/ytube_music_player: YouTube music player for homeassistant
- Music Target: Install Owntone add-on.
- Alexa Skill: Create one basic skill on Alexa Skill Portal to handle requests to echo devices start streaming.
So, Youtube Music Player sends the music output to Owntone add-on and Owntone has a streaming endpoint which you should expose through HTTPS and you are creating a new skill to stream from respective MP3 endpoint. You should initiate the stream over Echo devices such as Alexa Play local media
or you can send this command over Home Assistant to Echo devices.
# -*- coding: utf-8 -*-
# This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK for Python.
# Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
# session persistence, api calls, and more.
# This sample is built using the handler classes approach in skill builder.
import logging
import ask_sdk_core.utils as ask_utils
import json
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model.interfaces.audioplayer import (
PlayDirective, PlayBehavior, AudioItem, Stream, AudioItemMetadata,
StopDirective, ClearQueueDirective, ClearBehavior)
from ask_sdk_model import Response
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
class IntentRequestHandler(AbstractRequestHandler):
"""Handler for Hello World Intent."""
def can_handle(self, handler_input):
return ask_utils.is_request_type("IntentRequest")(handler_input) or ask_utils.is_request_type("LaunchRequest")(handler_input) or ask_utils.is_request_type("GetPla")(handler_input)
def handle(self, handler_input):
return (
handler_input.response_builder
.speak("starting Local Radio")
.add_directive(
PlayDirective(
play_behavior=PlayBehavior.REPLACE_ALL,
audio_item=AudioItem(
stream=Stream(
token="token",
url="https://HERE.GOES.YOUR.ENDPOINT/owntone/stream.mp3",
offset_in_milliseconds=0,
expected_previous_token=None
),
metadata=None
)
)
)
.response
)
class CatchAllExceptionHandler(AbstractExceptionHandler):
def can_handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> bool
return True
def handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> Response
logger.error(exception, exc_info=True)
speak_output = "Sorry, I had trouble doing what you asked. Please try again."
return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)
sb = SkillBuilder()
sb.add_request_handler(IntentRequestHandler())
sb.add_exception_handler(CatchAllExceptionHandler())
lambda_handler = sb.lambda_handler()