music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.37k stars 52 forks source link

[feature request] Integration with Alexa Media Player? #101

Closed dm7500 closed 2 years ago

dm7500 commented 2 years ago

Trying to play music from Spotify to my Alexa devices, which are set as media devices using Alexa Media Player. Alexa gives an error stating that the proper service calls must be made.

If this could be integrated in some way, it would be a game changer for playing music via HA. Happy to test anything as needed.

marcelveldt commented 2 years ago

I've inspected this today and so far I see no easy way to make that work. The Alexa Media Player does not allow to just send a stream URL to play which is what this integration needs. The only way to make this work properly is if somebody creates a custom Alexa skill that communicates with this integration.

I do not own a Alexa device so I can't do that.

A little googleing I just did quickly led me to several 3rd party solutions you could use to turn the Echo device into a unpnp receiver or squeezebox player. For example: https://www.amazon.com/ComputeQ-UG-Haftungsbeschr-Roomskills-Squeezebox/dp/B0983C2377

I'm happy to work with somebody to make this work but without an actual Alexa/Echo device to test with, this is not something I can start with alone

adocampo commented 2 years ago

I would gladly help, I'm not a developer, but I would help by testing it on my echos, unfortunately I'm located in Spain and the skill you pointed can be only installable on US echos (perhaps on DE as well, as per language selection)

mabrochu-helpox commented 2 years ago

I don't know how the SpotCast integration works but I'm able to play music from spotify on my alexa devices from Home Assistant, I don't believe a skill is needed.

dm7500 commented 2 years ago

@mabrochu-helpox how do you bring the Alexa's into HA as media players though?

mabrochu-helpox commented 2 years ago

Whith the alexa integration image

bdr99 commented 2 years ago

To be clear, this is not the official Alexa integration built into HA. This is a custom integration known as Alexa Media Player. It is found here: https://github.com/custom-components/alexa_media_player

marcelveldt commented 2 years ago

eveloper, but I would help by testing it on my echos, unfortunately I'm located in Spain and the skill you pointed can be only installable on US echos (perhaps on DE as well, as per language selection)

For Music Assistant to work it is required that the enddevice (the speaker) supports "play from url". So basically we just want to send a url to a speaker. Just like a radio stream....

Music Assistant is not about playing Spotify on a speaker. Music Assistant is about playing all your online en offline media to a collection of speakers. The Spotcast implementation (and others like the alexa custom integration) send Spotify commands to the Echo speaker, not plain urls

janstadt commented 2 years ago

Its hacky but you can send urls like this:

service: notify.alexa_media
data:
  message: <audio src='https://url-to-mp3.mp3' />
  target: media_player.the_kitchen
  data:
    type: tts
  title: Happy Halloween

Probably not the intended use but im curious if there is another api we that could be leveraged ?

flexage commented 2 years ago

Enjoyed the Open Home Audio stream with you all! Very impressive stuff all around!

@marcelveldt Music Assistant seems great, and opens a world of possibilities!

I just wanted to offer up a potential path forward for supporting Echo devices, and that would be using them as a bluetooth audio target.

I regularly pair my Echo with my Macbook via bluetooth, and set it as my output device.

No special hardware of configuration needed, just the Amazon Alexa app: Devices -> Echo & Alexa -> Select Device -> Bluetooth Connections -> Connect a Device

Imagepipe_1

The simplest solution is to pair your Echo(s) with the host OS, and use them as system output device(s) - of course, that may incur limitations regarding targeting specific connected devices/groups (or it may not... I can't purport myself to be an expert on linux audio, perhaps @pvizeli [Pascal] is better suited to answer that).

Traditionally, Bluetooth radios have supported a single audio streaming device per chip (except for a few specialist radios) - so 1 dongle = 1 speaker, 2 dongles = 2 speakers, etc....

However, the recent Bluetooth LE specification also adds "multi device audio streaming" from a single radio, I believe using the LC3 codec.

Here's some reference links:

https://embeddedcomputing.com/application/networking-5g/short-range-wireless-pan/le-audio-the-next-generation-of-bluetooth-audio-technology

https://www.bluetooth.com/learn-about-bluetooth/recent-enhancements/le-audio/

Note: It would not be the best solution in terms of making direct use of the PCM stream url you described in the video presentation, and it may not support the speaker latency/sync feature you have planned for the future - however, it is an option that maintains local-control, and I do not believe invokes the cloud once configured.

For that, I believe the only current 'official' option to request Alexa devices to play an url is using their custom skill API- and that of course requires an internet accessible url, so goes against the local-control philosophy, so is less than ideal - However Nabu Casa already provides a Home Assistant custom skill for Alexa, so I'd imagine some of the groundwork is already laid...

The relevant documentation appears to be available here: https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#audio-stream-requirements

flexage commented 2 years ago

Additional: I came across an article from last year on Mark Lewis's Blog, in which he configures audio with a bluetooth dongle on Home Assistant OS, seemed fairly simple: https://marklewis.blog/2021/02/25/home-assistant-bluetooth-speaker/

Mark was using a "Local VLC" community addon as a player, but I'm sure there's other things that can be done

gromgsxr commented 2 years ago

would we possibly be able to use something like this: https://www.youtube.com/watch?v=NoCPUypkimc&ab_channel=DabbleLab as a base for a custom skill to be able to play media from a url on amazon devices?

erkr commented 2 years ago

Moved to discussions, raise your votes!