Skip to content

Commit 827497b

Browse files
Kevin Ahrendtjesserockz
authored andcommitted
[speaker] Document enqueue parameter and add a troubleshooting section (#4658)
1 parent b3f534e commit 827497b

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

components/media_player/speaker.rst

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Speaker Audio Media Player
77

88
The ``speaker`` media player platform allows you to play on-device and online audio media via :doc:`speaker components </components/speaker/index>`.
99

10-
This platform greatly benefits from having external PSRAM. See the :ref:`performance section <speaker_media_player-performance>` for details.
10+
This platform greatly benefits from having external PSRAM. See the :ref:`performance section <media_player-speaker-performance>` for details.
1111

1212
It natively supports decoding ``FLAC``, ``MP3``, and ``WAV`` audio files. Home Assistant (since version 2024.10) can proxy any media it sends and transcode it to a specified format and sample rate to minimize the device's computational load.
1313

@@ -58,23 +58,12 @@ Configuration variables:
5858
- **on_volume** (*Optional*, :ref:`Automation <automation>`): An automation to perform when the volume is changed.
5959
- All other options from :ref:`Media Player <config-media_player>`
6060

61-
.. _speaker_media_player-performance:
62-
63-
Performance
64-
-----------
65-
66-
Decoding audio files is CPU and memory intensive. PSRAM external memory is strongly recommended. To use the component on a memory constrained device, define only the announcement pipeline, decrease the buffer size, set ``codec_support_enabled`` to false, and set the pipeline transcode setting format to ``WAV`` with a low sample rate and only 1 channel.
67-
68-
In general, decoding FLAC has the lowest CPU usage, but requires a strong WiFi connection. Decoding MP3 requires less data to be sent over WiFi but is more CPU intensive to decode. Decoding WAV is only recommended at low sample rates if streamed over a network connection.
69-
70-
Increasing the buffer size may reduce stuttering, but do not set it to the entire size of the external memory. Each pipeline allocates the configured amount, and this setting also does not take into account other smaller buffers allocated throughout the audio stack.
71-
72-
.. _speaker_media_player-examples:
61+
.. _media_player-speaker-examples:
7362

7463
Example Configuration
7564
---------------------
7665

77-
This example outputs audio to an :doc:`I²S Audio Speaker </components/speaker/i2s_audio>` configured with a 48000 Hz sample rate. It uses a ``mixer`` speaker component to handle combining the two differnet pipelines, and it uses ``resampler`` speaker components to ensure the source speakers uses the same sample rate.
66+
This example outputs audio to an :doc:`I²S Audio Speaker </components/speaker/i2s_audio>` configured with a 48000 Hz sample rate. It uses a ``mixer`` speaker component to handle combining the two different pipelines, and it uses ``resampler`` speaker components to ensure the source speakers uses the same sample rate.
7867

7968
It adds a switch for playing an on-device file for an alarm notification. Any playing media is ducked while the alarm is activated. After the alarm is turned off, the media ducking will gradually stop.
8069

@@ -83,6 +72,7 @@ It adds a switch for playing an on-device file for an alarm notification. Any pl
8372
i2s_audio:
8473
i2s_lrclk_pin: GPIOXX
8574
i2s_bclk_pin: GPIOXX
75+
sample_rate: 48000
8676
speaker:
8777
- platform: i2s_audio
8878
id: speaker_id
@@ -176,11 +166,39 @@ Configuration variables:
176166

177167
- **media_file** (**Required**, :ref:`config-id`): The ID of the media file.
178168
- **announcement** (*Optional*, boolean): Whether to play back the file as an announcement or media stream. Defaults to ``false``.
169+
- **enqueue** (*Optional*, boolean): Whether to add the media file to the end of the pipeline's internal playlist. Defaults to ``false``.
170+
171+
.. _media_player-speaker-performance:
172+
173+
Performance
174+
-----------
175+
176+
Decoding audio files is CPU and memory intensive. PSRAM external memory is strongly recommended. To use the component on a memory constrained device, define only the announcement pipeline, decrease the buffer size, set ``codec_support_enabled`` to false, and set the pipeline transcode setting format to ``WAV`` with a low sample rate and only 1 channel.
177+
178+
In general, decoding FLAC has the lowest CPU usage, but requires a strong WiFi connection. Decoding MP3 requires less data to be sent over WiFi but is more CPU intensive to decode. Decoding WAV is only recommended at low sample rates if streamed over a network connection.
179+
180+
Increasing the buffer size may reduce stuttering, but do not set it to the entire size of the external memory. Each pipeline allocates the configured amount, and this setting also does not take into account other smaller buffers allocated throughout the audio stack.
181+
182+
Only set ``task_stack_in_psram`` to true if you have many components configured and your logs show that memory allocation failed. It is slower, especially if your PSRAM doesn't support ``octal`` mode.
183+
184+
.. _media_player-speaker-troubleshooting:
185+
186+
Troubleshooting
187+
---------------
188+
189+
While you are troubleshooting, simplify your setup as much as possible . Only configure the ``announcement_pipeline`` and do not use ``resampler`` or ``mixer`` speakers.
190+
191+
If you can't hear anything, check whether your hardware requires a GPIO pin to be high or low to enable the speaker. Verify you have the correct speaker channel configured: try setting your speaker configuration to stereo if you are unsure which channels are available.
192+
193+
If the audio quality is poor, check your output speaker configuration. Experiment with the bits per sample, channels, and sample rate settings. In general, higher sample rates improve audio quality: try using ``44100`` Hz or ``48000`` Hz instead of ``16000`` Hz.
179194

195+
If there is a noticeable delay before a pause command takes effect, reduce the buffer duration in the output speaker. Be sure to adjust both the hardware speaker component settings and the ``mixer`` speaker component settings, if used.
180196

181197
See also
182198
--------
183199

184200
- :doc:`/components/speaker/index`
201+
- :doc:`/components/speaker/mixer`
202+
- :doc:`/components/speaker/resampler`
185203
- :doc:`index`
186204
- :ghedit:`Edit`

0 commit comments

Comments
 (0)