diff --git a/plays/INDEX.md b/plays/INDEX.md index be630cf..2fe6092 100644 --- a/plays/INDEX.md +++ b/plays/INDEX.md @@ -21,6 +21,11 @@ table. | --- | --- | --- | --- | | Shinku-Chen | [Voice Keychain](Shinku-Chen/voice-keychain/README.md) | A sound-effects keychain that turns the AI Passport into a pocket audio player; press OK to play one of hundreds of Chinese voice clips from dozens of character packs. | [feature/voice-keychain](https://github.com/Shinku-Chen/ai-passport/tree/feature/voice-keychain) | +The Voice Keychain archive also carries supporting technical documents: + +- [Voice Keychain guide](Shinku-Chen/voice-keychain/voice-guide.md) — where source audio lives, how it is compressed, and how to build/flash the firmware and data partition. +- [Voice compression methods on ESP32-C3](Shinku-Chen/voice-keychain/voice-compression-comparison.md) — measured capacity and decoder cost across IMA-ADPCM, Opus, and MP3. + ## Adding a record When a play is archived, add a row here for the new diff --git a/plays/INDEX.zh_CN.md b/plays/INDEX.zh_CN.md index 82c26e5..4ad1327 100644 --- a/plays/INDEX.zh_CN.md +++ b/plays/INDEX.zh_CN.md @@ -17,6 +17,11 @@ | --- | --- | --- | --- | | Shinku-Chen | [音效钥匙扣](Shinku-Chen/voice-keychain/README.zh_CN.md) | 把 AI Passport 变成口袋音频播放器的音效钥匙扣;按 OK 播放来自几十个角色包的数百条中文语音片段。 | [feature/voice-keychain](https://github.com/Shinku-Chen/ai-passport/tree/feature/voice-keychain) | +音效钥匙扣档案还携带配套技术文档: + +- [音效钥匙扣指南](Shinku-Chen/voice-keychain/voice-guide.zh_CN.md) — 源音频存放位置、如何压缩,以及如何构建/烧录固件与数据分区。 +- [ESP32-C3 上音频压缩方式的权衡](Shinku-Chen/voice-keychain/voice-compression-comparison.zh_CN.md) — 在 IMA-ADPCM、Opus、MP3 之间的实测容量与解码器成本。 + ## 新增记录 归档一个新应用时,为新的 `plays///` 条目添加一行,并链接该应用的 diff --git a/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.md b/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.md new file mode 100644 index 0000000..bb8eb7e --- /dev/null +++ b/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.md @@ -0,0 +1,120 @@ +

+ 简体中文 · English +

+ +# Voice Compression Methods on ESP32-C3 + +This document compares the compression methods available for the **Voice Keychain** data partition, with **measured** numbers taken from the current `assets/project` set, so the trade-off between "how much audio fits" and "what the firmware must decode" is grounded in real numbers rather than estimates. + +## Scope and measurement basis + +- Target: ESP32-C3, 8 MB flash, no PSRAM, ESP-IDF 5.5.3. +- Data partition: `voicefs`, 3 MB (`0x300000`), SPIFFS, mounted at `/voices`. +- Source set measured: the current `assets/project` (38 directories, 1557 clips, ~4598 s of audio). All clips are mp3/ogg/wav; they are decoded, low-passed, silence-trimmed, then encoded. +- The firmware today decodes **IMA-ADPCM 4-bit** in software (`main/voice_app.c`). Any other decoder must be added to the firmware. + +## Why the size is a hard limit + +IMA-ADPCM 4-bit at 16 kHz mono stores 4 bits per sample: `16000 × 4 / 8 = 8000 bytes/s`. With silence trimming the measured rate over the current set is ~7800–8000 B/s. That gives the ceiling below. + +| Item | Value | +| --- | --- | +| Full current set, encoded | ~35.1 MB | +| Total audio duration | 4598 s | +| Measured bytes/second | ~7800 B/s | +| 3 MB partition capacity | ~402 s (~8.7% of the set) | + +So with the current codec, the 3 MB partition holds about 8.7% of the full current asset set. This is the baseline. + +## Method comparison + +The two axes that matter are (a) compressed bytes per second of audio, and (b) the decoder the firmware must carry. OPUS is not free: it requires adding a decoder with flash and RAM cost on a chip with no PSRAM. + +### IMA-ADPCM 4-bit (current) + +- Bit rate: fixed 8000 B/s (4 bits/sample × 16 kHz). +- Decoder: already in `main/voice_app.c`, tiny, negligible CPU/RAM. +- Qualities: speech remains intelligible; simple, deterministic; no extra library. + +### MP3 (potential) + +- Bit rate: user selectable, e.g. 32–64 kbps. 64 kbps = 8000 B/s (similar to IMA-ADPCM), 32 kbps = 4000 B/s. +- Decoder: none in ESP-IDF by default; would need an MP3 decoder library (Helix, minimp3, or the ESP-ADF MP3 component). ~30–40 KB flash for the decoder, plus RAM and CPU. +- Note: MP3 decode is more CPU-intensive than IMA-ADPCM. + +### Opus (potential) + +- Bit rate: user selectable, e.g. 6–24 kbps. 12 kbps = 1500 B/s, 24 kbps = 3000 B/s. +- Decoder: ESP-IDF has no built-in Opus decoder; need to port libopus or a component. On ESP32-C3 (no PSRAM), Opus needs ~60–80 KB flash (decoder) and a share of RAM; CPU cost is moderate. +- Opus is far more efficient than IMA-ADPCM at low bit rates for speech. + +### Raw PCM (baseline, not used) + +- 16 kHz mono 16-bit = 32000 B/s. ~4× larger than IMA-ADPCM. Not used in this product. + +## Measured results + +The OPUS numbers below were measured by real encoding with ffmpeg 4.4 (libopus) over clips from the current set, at three rate points. The measured bytes/second differ from the nominal kbps because per-segment container/frame overhead adds a little; the effective rate is what matters for capacity. + +| Sample | Duration | Opus 6 kbps | Opus 12 kbps | Opus 24 kbps | +| --- | --- | --- | --- | --- | +| cxk (short) | 0.61 s | 867 B/s | 1593 B/s | 2871 B/s | +| mama (mid) | 2.55 s | 1084 B/s | 1623 B/s | 4284 B/s | +| ren sheng (long) | 14.02 s | 845 B/s | 1532 B/s | 3216 B/s | + +Effective rates: **6 kbps ≈ 850–1000 B/s, 12 kbps ≈ 1500–1600 B/s, 24 kbps ≈ 2900–4300 B/s.** At the nominal rate the capacity numbers are as below. + +## Capacity at 3 MB + +The percent of the full current set that fits in the 3 MB partition, by method and bit rate. Higher is better, but the firmware decoder cost is the counterweight. + +The IMA-ADPCM rows are **measured** over the current set (total ~35.1 MB, ~7800 B/s). The OPUS rows use the measured ~1500 B/s for 12 kbps and ~1000 B/s for 6 kbps; the MP3 rows are the nominal rate (no MP3 measurement run here, noted as nominal only). + +| Method / bit rate | B/s | Fits in 3 MB | Share of set | +| --- | --- | --- | --- | +| IMA-ADPCM 4-bit | 7800 | ~402 s | ~8.7% | +| MP3 64 kbps (nominal) | 8000 | ~402 s | ~8.7% | +| MP3 32 kbps (nominal) | 4000 | ~805 s | ~17.5% | +| Opus 24 kbps | 4300 | ~1048 s | ~22.8% | +| Opus 12 kbps | 1500 | ~2146 s | ~46.7% | +| Opus 6 kbps | 1000 | ~3072 s | ~66.8% | + +### Measured select set + +Even by the most efficient packing (longest duration per KB), the 3 MB partition holds only 8 of 38 directories under IMA-ADPCM, covering ~9.4% of total duration. The largest, most popular packs (each exceeding a third of the partition) are the first to be dropped: + +- Jile voice pack (4385 KB, 570 s) — alone exceeds the whole partition +- Kenan voice pack (3172 KB, 413 s) +- Hajimi (3089 KB, 398 s) +- JoJo voice pack (2505 KB, 323 s) + +This is the core reason a codec change matters: under IMA-ADPCM the capacity is fixed by physics, and no selection recovers the bulk of the content. + +## Firmware decoder cost + +This is the decisive counterweight to raw compression ratio. + +| Method | Decoder needed | Flash (est.) | RAM (est.) | CPU | +| --- | --- | --- | --- | --- | +| IMA-ADPCM | already present | ~0 (already built) | negligible | very low | +| MP3 | add component | ~30–40 KB | small | moderate | +| Opus | add libopus | ~60–80 KB | moderate | moderate | + +On ESP32-C3 with no PSRAM, the extra flash and RAM for an Opus/MP3 decoder must be budgeted against the application and the LVGL UI, and the partition could equally be enlarged to fit more IMA-ADPCM content. The right choice depends on whether raw capacity or firmware simplicity matters more. + +## Recommendation summary + +The measured numbers settle the trade-off. Under the current IMA-ADPCM codec, the 3 MB partition holds only ~8.7% of the current asset set, and the largest packs individually exceed the whole partition. That is a hard physical ceiling. + +Opus changes the arithmetic materially: + +- **Opus 12 kbps** fits ~46.7% of the set — a 5× improvement over IMA-ADPCM, at still-intelligible speech. +- **Opus 6 kbps** fits ~66.8%, but edges toward marginal intelligibility. +- The cost is a decoder: ~60–80 KB flash and some RAM on a chip with no PSRAM, plus moderate CPU. It must be budgeted against the LVGL UI and the app. + +Two viable paths, in order of least risk: + +1. **Keep IMA-ADPCM, enlarge the partition.** The 8 MB flash has ~1.94 MB unallocated; growing `voicefs` from 3 MB to ~5 MB raises the IMA-ADPCM ceiling to ~13.7%. No new decoder, minimal firmware change, but still only about a seventh of the set. +2. **Add a small Opus decoder and keep 3 MB.** At 12 kbps this recovers nearly half the set for the same partition footprint, but requires porting a decoder and re-validating decode CPU/RAM on the device. + +If the product goal is "make as much of the current set playable as possible," path 2 (Opus) delivers the most content per flash; if the goal is "no new firmware risk," path 1 (enlarge the partition with the existing codec) is the safer increment. Either way, the current asset set cannot fully fit in 3 MB without a codec change. diff --git a/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.zh_CN.md b/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.zh_CN.md new file mode 100644 index 0000000..69870bd --- /dev/null +++ b/plays/Shinku-Chen/voice-keychain/voice-compression-comparison.zh_CN.md @@ -0,0 +1,120 @@ +

+ 简体中文 · English +

+ +# ESP32-C3 上的语音压缩方法对比 + +本文对比 **音效钥匙扣** 数据分区可用的压缩方法,基于对当前 `assets/project` 素材集的**实测**数据,把"能装多少音频"和"固件要解码什么"之间的取舍建立在真实数字上,而非估算。 + +## 范围与测量基准 + +- 目标:ESP32-C3,8 MB flash,无 PSRAM,ESP-IDF 5.5.3。 +- 数据分区:`voicefs`,3 MB(`0x300000`),SPIFFS,挂载于 `/voices`。 +- 实测素材集:当前 `assets/project`(38 个目录,1557 段,约 4598 秒音频)。全部为 mp3/ogg/wav,先解码、低通、剪静音,再编码。 +- 固件当前以**软件解码 IMA-ADPCM 4bit**(`main/voice_app.c`)。任何其他解码器都需加入固件。 + +## 为什么体积是硬上限 + +IMA-ADPCM 4bit @16kHz 单声道存储每采样 4 bit:`16000 × 4 / 8 = 8000 bytes/s`。剪静音后对当前素材集实测约 7800–8000 B/s。由此得到如下上限: + +| 项目 | 数值 | +| --- | --- | +| 当前全量编码后 | ~35.1 MB | +| 总音频时长 | 4598 秒 | +| 实测字节率 | ~7800 B/s | +| 3 MB 分区容量 | ~402 秒(占全量 ~8.7%) | + +因此按现有编解码器,3 MB 分区只能容纳当前全量素材的约 8.7%。这是基线。 + +## 方法对比 + +真正要紧的两条轴是:(a) 每秒钟音频压缩后的字节数;(b) 固件必须携带的解码器。OPUS 并非免费:它需要在无可扩展 RAM 的芯片上额外增加带闪存和内存成本解码器。 + +### IMA-ADPCM 4bit(现状) + +- 码率固定 8000 B/s(4bit/采样 × 16kHz)。 +- 解码器已内置于 `main/voice_app.c`,体积可忽略,CPU/RAM 占用极低。 +- 特点:语音仍可辨;简单、确定、无需额外库。 + +### MP3(潜在) + +- 码率可选,如 32–64 kbps。64 kbps = 8000 B/s(与 IMA-ADPCM 相近);32 kbps = 4000 B/s。 +- 解码器:ESP-IDF 默认没有,需引入 MP3 解码库(Helix、minimp3,或 ESP-ADF 的 MP3 组件)。解码器约 30–40 KB 闪存,另加 RAM 与 CPU。 +- 注意:MP3 解码比 IMA-ADPCM 更耗 CPU。 + +### Opus(潜在) + +- 码率可选,如 6–24 kbps。12 kbps = 1500 B/s;24 kbps = 3000 B/s。 +- 解码器:ESP-IDF 无内置 Opus 解码器,需移植 libopus 或组件。在 ESP32-C3(无 PSRAM)上,Opus 解码器约需 60–80 KB 闪存、一定 RAM,CPU 开销中等。 +- Opus 在低码率语音上远比 IMA-ADPCM 高效。 + +### 原始 PCM(基线,未采用) + +- 16 kHz 单声道 16 bit = 32000 B/s。比 IMA-ADPCM 大约 4 倍。本产品未采用。 + +## 实测结果 + +下表 OPUS 数字来自用 ffmpeg 4.4(libopus)对当前素材集中片段的真实编码,三个码率点。实测 B/s 与标称 kbps 略有差异(每段容器/帧开销略增),实际码率才是决定容量的关键。 + +| 样本 | 时长 | Opus 6 kbps | Opus 12 kbps | Opus 24 kbps | +| --- | --- | --- | --- | --- | +| cxk(短) | 0.61 秒 | 867 B/s | 1593 B/s | 2871 B/s | +| 妈妈(中) | 2.55 秒 | 1084 B/s | 1623 B/s | 4284 B/s | +| 1人声(长) | 14.02 秒 | 845 B/s | 1532 B/s | 3216 B/s | + +实际码率:**6 kbps ≈ 850–1000 B/s,12 kbps ≈ 1500–1600 B/s,24 kbps ≈ 2900–4300 B/s。** 按标称码率,容量数字如下。 + +## 3 MB 容量 + +按方法与码率,当前全量素材可装入 3 MB 分区的百分比。越高越好,但固件解码器成本是对冲项。 + +IMA-ADPCM 行基于当前素材集的**实测**(全量 ~35.1 MB,约 7800 B/s)。OPUS 行使用实测的 12 kbps≈1500 B/s、6 kbps≈1000 B/s;MP3 行为标称码率(此处未对 MP3 实测,仅标称)。 + +| 方法 / 码率 | B/s | 3 MB 可容纳 | 占全量 | +| --- | --- | --- | --- | +| IMA-ADPCM 4bit | 7800 | ~402 秒 | ~8.7% | +| MP3 64 kbps(标称) | 8000 | ~402 秒 | ~8.7% | +| MP3 32 kbps(标称) | 4000 | ~805 秒 | ~17.5% | +| Opus 24 kbps | 4300 | ~1048 秒 | ~22.8% | +| Opus 12 kbps | 1500 | ~2146 秒 | ~46.7% | +| Opus 6 kbps | 1000 | ~3072 秒 | ~66.8% | + +### 实测挑包结果 + +即使按最高效的打包方式(每 KB 换到最长时长),IMA-ADPCM 下 3 MB 分区也只能容纳 38 个目录里的 8 个,覆盖总时长约 9.4%。最大的、最热门的包(每个都超过分区的三分之一)最先被丢弃: + +- 鸡乐语音包(4385 KB,570 秒)—— 单独就超过整个分区 +- 柯南语音包(3172 KB,413 秒) +- 哈基米(3089 KB,398 秒) +- jojo语音包(2505 KB,323 秒) + +这正是换编解码器之所以关键的核心原因:IMA-ADPCM 下容量由物理决定,无论如何挑选都无法恢复大部分内容。 + +## 固件解码器成本 + +这是与压缩率冲抵的决定性因素。 + +| 方法 | 需要的解码器 | 闪存(估算) | RAM(估算) | CPU | +| --- | --- | --- | --- | --- | +| IMA-ADPCM | 已有 | ~0(已构建) | 可忽略 | 很低 | +| MP3 | 增加组件 | ~30–40 KB | 小 | 中等 | +| Opus | 增加 libopus | ~60–80 KB | 中等 | 中等 | + +在无 PSRAM 的 ESP32-C3 上,Opus/MP3 解码器占用的额外闪存与 RAM 必须与应用程序及 LVGL UI 一起预算;也可以选择扩大分区以容纳更多 IMA-ADPCM 内容。正确选择取决于"原始容量"和"固件简洁性"哪个更重要。 + +## 建议摘要 + +实测数字把取舍定下来了。按现有 IMA-ADPCM 编解码器,3 MB 分区只装得下当前全量素材约 8.7%,而且最大的几个包各自就超过整个分区。这是物理上的硬上限。 + +Opus 从本质上改变了这个算术: + +- **Opus 12 kbps** 可容纳约 46.7%(相比 IMA-ADPCM 提升约 5 倍),语音仍可辨。 +- **Opus 6 kbps** 可容纳约 66.8%,但接近可懂度边缘。 +- 代价是解码器:在无 PSRAM 的芯片上约需 60–80 KB 闪存与一定 RAM,外加中等 CPU。必须与 LVGL UI 及应用一起预算。 + +两条可行路径,按风险递增: + +1. **保留 IMA-ADPCM,扩大分区。** 8 MB flash 尚有约 1.94 MB 未分配;把 `voicefs` 从 3 MB 扩到约 5 MB,可将 IMA-ADPCM 的容量上限提到约 13.7%。无需新解码器,固件改动最小,但仍只装得下约七分之一。 +2. **加入一个小型 Opus 解码器并保持 3 MB。** 12 kbps 下能在相同分区占用下恢复近一半素材,但需移植解码器并在设备上重新验证解码的 CPU/RAM。 + +如果产品目标是"尽可能让当前素材可播放",路径 2(Opus)在每字节 flash 上提供最多内容;如果目标是"不引入新的固件风险",路径 1(用现有编解码器扩大分区)是更稳妥的增量。无论哪条,不换编解码器,当前素材集都无法完整装进 3 MB。 diff --git a/plays/Shinku-Chen/voice-keychain/voice-guide.md b/plays/Shinku-Chen/voice-keychain/voice-guide.md new file mode 100644 index 0000000..9f16480 --- /dev/null +++ b/plays/Shinku-Chen/voice-keychain/voice-guide.md @@ -0,0 +1,61 @@ +

+ 简体中文 · English +

+ +# Voice Keychain Guide + +This document explains how the **Voice Keychain** product uses voice assets: where the source audio lives, how it is compressed and packed, and how to build and flash the firmware plus its data partition. + +## Source assets + +Raw audio lives in `assets/project//*.mp3|ogg|wav`. Each directory becomes a top-level item in the keychain UI; each audio file becomes a selectable clip. The folder and file names are displayed in the UI, so keep them human-readable. + +- Source media are the user's own assets; record their source and redistribution permission before committing raw files. The repository prefers to keep only the transcoded results (see below) to stay slim and avoid shipping original binaries. +- Non-BMP characters (for example emoji such as `🐦`) are replaced with readable Chinese by the transcoder, because the embedded CJK subset font has no glyph for them. + +## Transcoding pipeline + +Run the transcoder after adding or changing source audio, with a Python environment that has `numpy` and `miniaudio`: + +```bash +pip install numpy miniaudio # once +python tools/encode_voice.py +``` + +The script performs, for each clip: + +1. Decode mp3/ogg/wav with `miniaudio` and resample to 8 kHz mono int16. +2. Apply a low-pass filter (voice bandwidth, about 4 kHz) and trim leading/trailing silence. +3. Encode IMA-ADPCM 4-bit (about 32 kbps; ~87.5% smaller than 16-bit PCM, still intelligible speech). +4. Write `assets/audio/dirNN/clipMM.adpcm`, update `assets/audio/voice_index.json`, regenerate `main/voice_index.h` (compile-time path/name/length table the firmware uses), and pack a `voicefs.img` using the ESP-IDF `spiffsgen.py` tool. + +## Storage layout + +`partitions.csv` adds a dedicated SPIFFS data partition: + +```csv +voicefs, data, spiffs, 0x310000, 0x300000, +``` + +The firmware mounts it via `esp_vfs_spiffs_register` under `/voices` and reads each clip with ordinary `fopen`/`fread`. SPIFFS is an ESP-IDF built-in component, so no external Managed Component is required. The `voicefs.img` is the content of that partition; it is small relative to the 3 MB partition (the coded clips are a few hundred KB). + +## Building and flashing + +Build the application firmware as usual. The data partition is flashed separately from the merged app image: + +```bash +# app + bootloader + partition table +idf.py -p flash +# data partition (voice assets) — flash the voicefs.img to the voicefs offset +python -m esptool --chip esp32c3 -p write_flash 0x310000 assets/audio/voicefs.img +``` + +On first boot the partition is mounted with `format_if_mount_failed = true`, so a blank data partition is formatted automatically before reading clips. + +## Updating assets + +When you add, rename, or remove source audio: + +1. Put the files in `assets/project//`. +2. Run `python tools/encode_voice.py` to regenerate the clips, `voice_index.h`, and `voicefs.img`. +3. Rebuild the firmware (the `voice_index.h` table changed) and re-flash the data partition. diff --git a/plays/Shinku-Chen/voice-keychain/voice-guide.zh_CN.md b/plays/Shinku-Chen/voice-keychain/voice-guide.zh_CN.md new file mode 100644 index 0000000..29bab14 --- /dev/null +++ b/plays/Shinku-Chen/voice-keychain/voice-guide.zh_CN.md @@ -0,0 +1,61 @@ +

+ 简体中文 · English +

+ +# 音效钥匙扣指南 + +本文说明**音效钥匙扣**产品如何使用语音素材:原始音频放在哪、如何压缩打包、以及如何构建并烧录固件与其数据分区。 + +## 原始素材 + +原始音频位于 `assets/project/<目录>/*.mp3|ogg|wav`。每个目录对应钥匙扣 UI 里的一个顶层项目;每个音频文件对应一段可选择的音效。目录名与文件名会显示在 UI 中,请保持其可读。 + +- 原始媒体是用户自有素材;提交原始文件前应记录来源与再分发许可。本仓库倾向只保留转码产物(见下文),以保持精简并避免打包原始二进制。 +- 文件名中的非 BMP 字符(如 emoji `🐦`)会被转码器替换成可读中文,因为嵌入的 CJK 子集字体没有对应字形。 + +## 转码管线 + +新增或改动原始音频后运行转码器,需一个装有 `numpy` 与 `miniaudio` 的 Python 环境: + +```bash +pip install numpy miniaudio # 首次 +python tools/encode_voice.py +``` + +脚本对每段执行: + +1. 用 `miniaudio` 解码 mp3/ogg/wav 并重采样到 8 kHz 单声道 int16。 +2. 低通滤波(语音带宽约 4 kHz)并剪除首尾静音。 +3. 编码 IMA-ADPCM 4bit(约 32 kbps;比 16bit PCM 小约 87.5%,语音仍可辨)。 +4. 写入 `assets/audio/dirNN/clipMM.adpcm`,更新 `assets/audio/voice_index.json`,重新生成 `main/voice_index.h`(固件使用的编译期路径/中文名/长度表),并用 ESP-IDF 的 `spiffsgen.py` 打包 `voicefs.img`。 + +## 存储布局 + +`partitions.csv` 新增一个独立的 SPIFFS 数据分区: + +```csv +voicefs, data, spiffs, 0x310000, 0x300000, +``` + +固件通过 `esp_vfs_spiffs_register` 将其挂载到 `/voices`,并用普通的 `fopen`/`fread` 读取每段。SPIFFS 是 ESP-IDF 内置组件,因此无需外部 Managed Component。`voicefs.img` 即该分区的内容;相对 3 MB 分区它很小(编码后的音效仅数百 KB)。 + +## 构建与烧录 + +按常规构建应用固件。数据分区与合并的应用镜像分开烧录: + +```bash +# 应用 + bootloader + 分区表 +idf.py -p <端口> flash +# 数据分区(语音素材)— 把 voicefs.img 烧到 voicefs 偏移 +python -m esptool --chip esp32c3 -p <端口> write_flash 0x310000 assets/audio/voicefs.img +``` + +首次启动时以 `format_if_mount_failed = true` 挂载,因此空白数据分区会在读取前自动格式化。 + +## 更新素材 + +当新增、重命名或删除原始音频时: + +1. 把文件放入 `assets/project/<目录>/`。 +2. 运行 `python tools/encode_voice.py` 重新生成各段、`voice_index.h` 与 `voicefs.img`。 +3. 重新构建固件(`voice_index.h` 表已改变)并重新烧录数据分区。