本示例主要用于展示乐鑫中文语音合成库的使用方法。示例可通过URAT串口输入中文文本,回车后播放合成的语音数据。
参考components/esp-tts
目录下的 README.md 来获取更多有关乐鑫中文语言合成库的信息。
- 一只外接喇叭(4~6 欧姆)
-
进入
idf.py menuconfig
-
通过
Serial Flasher Options
设置串口信息
# Name, Type, SubType, Offset, Size
factory, app, factory, 0x010000, 4M
voice_data, data, fat, , 3M
目前支持两种声音, 任选一个进行烧写:
- esp_tts_voice_data_xiaole.dat: 2900K
- esp_tts_voice_data_xiaoxin.dat: 2800K, 该voice data专为数字播报优化
source flash_voicedata.sh ../../components/esp-sr/esp-tts/esp_tts_chinese/esp_tts_voice_data_xiaole.dat /dev/ttyUSB0
source flash_voicedata.sh ../../components/esp-sr/esp-tts/esp_tts_chinese/esp_tts_voice_data_xiaoxin.dat /dev/ttyUSB0
3)代码中voice data的初始化方法如下:
// method2: initial voice set from separate voice data partition
const esp_partition_t* part=esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, "voice_data");
if (part==0) {
printf("Couldn't find voice data partition!\n");
return 0;
}
spi_flash_mmap_handle_t mmap;
uint16_t* voicedata;
esp_err_t err=esp_partition_mmap(part, 0, 3*1024*1024, SPI_FLASH_MMAP_DATA, (const void**)&voicedata, &mmap);
if (err != ESP_OK) {
printf("Couldn't map voice data partition!\n");
return 0;
}
esp_tts_voice_t *voice=esp_tts_voice_set_init(&esp_tts_voice_template, voicedata);
idf.py flash monitor
上电后,开发板会播放提示音:“欢迎使用乐鑫语音合成”
并输出以下打印:
欢迎使用乐鑫语音合成
I (266) tts_parser: unicode:0x6b22 -> huan1
I (266) tts_parser: unicode:0x8fce -> ying2
I (276) tts_parser: unicode:0x4f7f -> shi3
I (276) tts_parser: unicode:0x7528 -> yong4
I (286) tts_parser: unicode:0x4e50 -> le4
I (286) tts_parser: unicode:0x946b -> xin1
I (296) tts_parser: unicode:0x8bed -> yu3
I (296) tts_parser: unicode:0x97f3 -> yin1
I (306) tts_parser: unicode:0x5408 -> he2
I (306) tts_parser: unicode:0x6210 -> cheng2
请输入短语:
通过串口工具输入文本,回车播放。 注意:部分串口工具不支持中文输入。
如果使用minicom,运行minicom -s
进入设置页面, 进行以下设置:
- Serial port setup -> Serial Device -> /dev/ttyUSB0 (设置串口号)
- Serial port setup -> Hardware Flow Control -> No
- Screen and keyboard -> Local echo -> No
minicom显示有一些bug,但可以正确输入中文字符, 比如输入: “大家好”,回车出现以下打印:
uart input: ��大��家��好
tts input:��大��家��好
I (5266) tts_parser: unicode:0x5927 -> da4
I (5266) tts_parser: unicode:0x5bb6 -> jia1
I (5276) tts_parser: unicode:0x597d -> hao3
��请��输��入��短��语
如果大家有更好的串口工具,欢迎留言。