pyatv icon indicating copy to clipboard operation
pyatv copied to clipboard

Support other formats

Open esteban-uo opened this issue 2 years ago • 5 comments

What feature would you like?

Following the closed threat here https://github.com/home-assistant/core/issues/71569#issuecomment-1170475026 and due the possibility to stream now different formats https://github.com/home-assistant/core/pull/71230 It would be awesome if there would be the chance to support some other formats ie AAC.

Many many thanks!

Describe the solution you'd like

None

Any other information to share?

None

esteban-uo avatar Jul 03 '22 19:07 esteban-uo

@esteban-uo i've followed your entire thread ytube -> atv bug -> here. I'm in the same boat - ytube music won't work with HomePods...

apadua avatar Nov 15 '22 23:11 apadua

Not sure when this problem first started ocurring, but I now get "failed to init decoder" "File "/usr/local/lib/python3.9/site-packages/miniaudio.py", line 1216, in stream_any" when trying to play MP3 files on my wall tablet. Nothing has changed about the tablet and I wasn't aware that the break has coincided with an upgrade of my HA Core version but this must be the cause. Any ideas how to resolve? Googling doesn't show much! thank you

26tajeen avatar Dec 31 '22 10:12 26tajeen

Also seeing the same issue when using the TTS Service:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/apple_tv/media_player.py:292
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 12:31:18 PM (2 occurrences)
Last logged: 12:31:39 PM

[140186529052752] Error handling message: Unknown error (unknown_error) from (omitted) (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 646, in handle_execute_script
    await script_obj.async_run(msg.get("variables"), context=context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1524, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 409, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 453, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/tts/__init__.py", line 217, in async_say_handle
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 681, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 721, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/apple_tv/media_player.py", line 292, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/usr/local/lib/python3.10/site-packages/pyatv/core/facade.py", line 392, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/__init__.py", line 371, in stream_file
    audio_file = await open_source(
  File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/audio_source.py", line 483, in open_source
    return await InternetSource.open(source, sample_rate, channels, sample_size)
  File "/usr/local/lib/python3.10/site-packages/pyatv/protocols/raop/audio_source.py", line 362, in open
    stream_generator = await loop.run_in_executor(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/miniaudio.py", line 1265, in stream_any
    raise DecodeError("failed to init decoder", result)
miniaudio.DecodeError: ('failed to init decoder', -17)

magno101 avatar Feb 03 '23 18:02 magno101

Is this an unresolved issue? I also have the same symptoms and it does not run on HomePod.

WindowsHyun avatar Mar 25 '23 15:03 WindowsHyun

I think the situation should be a lot better now, so hopefully you don't see problems with MP3 now. Currently pyatv only supports formats that are supported by miniaudio and I don't think that will change for a while. You can however feed raw samples into pyatv from a buffer, e.g. via another process. So you can use ffmpeg to convert any supported format to raw PCM and play it that way. You have some examples here:

https://pyatv.dev/development/stream/#stream-a-file

You can do it with atvremote as well:

https://pyatv.dev/documentation/atvremote/#streaming

postlund avatar Jul 13 '23 07:07 postlund