Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Wont Stream to Alexa Devies #2729

Closed
Abe-Telo opened this issue Dec 6, 2024 · 6 comments
Closed

Media Wont Stream to Alexa Devies #2729

Abe-Telo opened this issue Dec 6, 2024 · 6 comments

Comments

@Abe-Telo
Copy link

Abe-Telo commented Dec 6, 2024

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

When attempting to play music from ytubeMediaPlayer (YouTube) i get a announcement: To send TTS, please set Announce=true. Music can't be played this way.

System details

  • Home Assistant version:
    Core 2024.12.0
    Supervisor 2024.11.4
    Operating System 14.0
    Frontend 20241127.4

Here is the log.
Logger: custom_components.alexa_media.media_player
Source: custom_components/alexa_media/media_player.py:1436
integration: Alexa Media Player (documentation, issues)
First occurred: 2:37:58 AM (4 occurrences)
Last logged: 2:39:13 AM
To send TTS, please set Announce=true. Music can't be played this way.

@Reachushere
Copy link

Same issue using Music Assistant

@sayam93
Copy link
Contributor

sayam93 commented Dec 8, 2024

I believe this Custom Integration acts as a middleman that allows Home Assistant to communicate with Amazon servers over the cloud by interacting with the APIs available from Amazon side. The amazon servers act as gatekeepers to the Alexa ecosystem and have to let through the data received from Home Assistant (or ytubeMediaPlayer) using the API to the Alexa device.

So, being the gatekeeper of what is allowed to be played on the Alexa device, Amazon has to provide a method to allow it to stream content other than TTS which I believe it no longer does.

The other approach involve using an Alexa skill but it only allows you to ask your Alexa device to play music using that skill. It still does not allow you to stream directly from the service providing the skill (like Spotify) to the Alexa device.

I hope that helps understand things better.

@Sinaloit
Copy link

Sinaloit commented Dec 8, 2024

if media_type == "music":
if public_url:
await self.async_play_tts_cloud_say(public_url, media_id, **kwargs)
else:
await self.async_send_tts(
"To send TTS, set public url in integration configuration"
)

The above seems to send music requests to async_play_tts_cloud_say which at the bottom sends out the error message mentioned in this issue. Not sure why the actual play_music call is only the default action and not used when the media_type is music.
else:
_LOGGER.debug(
"%s: %s:Playing music %s on %s with queue_delay %s",
hide_email(self._login.email),
self,
media_id,
media_type,
queue_delay,
)
if self.hass:
self.hass.async_create_task(
self.alexa_api.play_music(
media_type,
media_id,
customer_id=self._customer_id,
queue_delay=queue_delay,
timer=kwargs.get("extra", {}).get("timer", None),
**kwargs,
)
)
else:
await self.alexa_api.play_music(
media_type,
media_id,
customer_id=self._customer_id,
queue_delay=queue_delay,
timer=kwargs.get("extra", {}).get("timer", None),
**kwargs,
)

@sayam93
Copy link
Contributor

sayam93 commented Dec 8, 2024

if media_type == "music":
if public_url:
await self.async_play_tts_cloud_say(public_url, media_id, **kwargs)
else:
await self.async_send_tts(
"To send TTS, set public url in integration configuration"
)

The above seems to send music requests to async_play_tts_cloud_say which at the bottom sends out the error message mentioned in this issue. Not sure why the actual play_music call is only the default action and not used when the media_type is music.

else:
_LOGGER.debug(
"%s: %s:Playing music %s on %s with queue_delay %s",
hide_email(self._login.email),
self,
media_id,
media_type,
queue_delay,
)
if self.hass:
self.hass.async_create_task(
self.alexa_api.play_music(
media_type,
media_id,
customer_id=self._customer_id,
queue_delay=queue_delay,
timer=kwargs.get("extra", {}).get("timer", None),
**kwargs,
)
)
else:
await self.alexa_api.play_music(
media_type,
media_id,
customer_id=self._customer_id,
queue_delay=queue_delay,
timer=kwargs.get("extra", {}).get("timer", None),
**kwargs,
)

The first blob is simply a way to gracefully handle the error that arises when the media type is music instead of leaving the users clueless without a response at all. "Sorry folks! Amazon doesn't allow streaming music like this." would be a more appropriate TTS response for this I think.

Regarding the second blob, I think Amazon previously allowed this functionality and Alexa Media Player was able to use it (I started using Home Assistant only about a year ago so not sure) but the support no longer exists and this is just remnants of the old code that allowed it. It could also be some placeholder code they could use if Amazon allows/re-allows this functionality in the future.

In fact, I have created a small PR for this (#2736) so that users get hear a more accurate error message while trying to play music using this integration instead of something vague.

EDIT: I checked out the code for play_music function (https://gitlab.com/keatontaylor/alexapy/-/blob/dev/alexapy/alexaapi.py?ref_type=heads#L728) in alexaapi file in alexapy from where this function is actually imported. Seems like the function is simply meant to do something like "Alexa, play on ". So there doesn't seem to be anything that can actually control the playback or cast local music to the Alexa device since Amazon's 'walled garden' doesn't have any support for casting local music at all.

@Sinaloit
Copy link

Sinaloit commented Dec 8, 2024

That play_music function in gitlab indicates you can pass a provider and search string, which should work:
https://gitlab.com/keatontaylor/alexapy/-/blob/dev/alexapy/alexaapi.py?ref_type=heads#L740-L741

Granted we'd need to pass some sort of valid provider, which would not likely work for local media but could be used for several services such as:

  • Amazon Music
  • Apple Music
  • iHeartRadio
  • Pandora
  • TuneIn

@sayam93
Copy link
Contributor

sayam93 commented Dec 8, 2024

That play_music function in gitlab indicates you can pass a provider and search string, which should work: https://gitlab.com/keatontaylor/alexapy/-/blob/dev/alexapy/alexaapi.py?ref_type=heads#L740-L741

Granted we'd need to pass some sort of valid provider, which would not likely work for local media but could be used for several services such as:

  • Amazon Music
  • Apple Music
  • iHeartRadio
  • Pandora
  • TuneIn

Thanks for explaining it in a better manner. You're right, it simply executes a search query which could be done with an automation like the one I am using (#2208 (comment)).

Maybe the Music Assistant team could implement a way to pass a search query with 'custom' content type to the media player device created by AMP to create an illusion of the music being cast on the Alexa media device but even in that case, Alexa device would only be able to play the track if it is available on one of its supported services.

Therefore, this method still won't allow the media_player entity created by this Integration to be used like a proper media player using Music Assistant since this approach will limit the ability to control playback fully or cast local media.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants