为使用I²S扬声器创建音频片段文件
.. audio_clips_for_i2s:
可以创建音频片段以包含在您的构建中,用于I²S扬声器。无需媒体播放器组件!
- 使用 Audacity,将音频转换为WAV、单声道、16kHz、无符号8位PCM

- 再次转换,这次使用 SOX。
sox startup.wav --bits 8 --encoding signed-integer --endian little startup_again.raw
- 现在将其转换为十六进制字符串,使用 xxd 转换到C++文件。
xxd -i startup_again.raw startup.c
- 生成的文件需要在起始行进行修改:
在编辑器中打开并更改
unsigned char startup_again_raw[] = {…[SNIP]…}
为std::vector<unsigned char> startup_raw = {…[SNIP]…}
.
现在您可以将文件重命名为 startup.h,将其放在 esphome 配置目录中,并在您的设备配置中包含它,如下所示:
esphome:
includes:
- startup.h
现在您可以使用以下方式定义音频片段:
- speaker.play:
id: speaker
data: !lambda return startup_raw;
享受!
HowTo by [NUT].