diff --git a/components/speaker/index.rst b/components/speaker/index.rst index a96b685459..045d3bab07 100644 --- a/components/speaker/index.rst +++ b/components/speaker/index.rst @@ -92,4 +92,6 @@ Platforms See Also -------- +- :doc:`/guides/audio_clips_for_i2s` +- :doc:`/components/speaker/i2s_audio` - :ghedit:`Edit` diff --git a/guides/audio_clips_for_i2s.rst b/guides/audio_clips_for_i2s.rst new file mode 100644 index 0000000000..9f73674b0f --- /dev/null +++ b/guides/audio_clips_for_i2s.rst @@ -0,0 +1,58 @@ +.. audio_clips_for_i2s: + +Create audio clip files for use with I²S Speakers +================================================= + +It is possible to create sound clips to include in your build to use with I²S speakers. No need for a media player component! + +- Using `Audacity `__, convert audio to WAV, mono, 16kHz, Unsigned 8bit PCM + +.. figure:: /guides/images/save_as_wav.png + :alt: Audacity export dialog + :height: 200 + :align: center + +- Convert again, this time with `SOX `__. + +.. code-block:: console + + sox startup.wav --bits 8 --encoding signed-integer --endian little startup_again.raw + +- Now convert it into a hexadecimal string using `xxd `__ into a C++ file. + +.. code-block:: console + + xxd -i startup_again.raw startup.c + +- The resulting file needs a modification in the start line: + Open in an editor and change + ``unsigned char startup_again_raw[] = {…[SNIP]…}`` + to + ``std::vector startup_raw = {…[SNIP]…}``. + +Now you can rename the file to startup.h, put it inside the esphome configuration directory and put it in a include in your device config like this: + +.. code-block:: yaml + + esphome: + includes: + - startup.h + +Now you can define using the audio clip using the following: + +.. code-block:: yaml + + - speaker.play: + id: speaker + data: !lambda return startup_raw; + +Enjoy! + +HowTo by [NUT]. + +See also +-------- + +- :doc:`/components/speaker/index` +- :doc:`/components/speaker/i2s_audio` +- :ghedit:`Edit` diff --git a/guides/images/save_as_wav.png b/guides/images/save_as_wav.png new file mode 100644 index 0000000000..2de3da61f3 Binary files /dev/null and b/guides/images/save_as_wav.png differ