mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
你的提交说明
This commit is contained in:
parent
8fd4a4d648
commit
c166f9b992
10 changed files with 91 additions and 1 deletions
|
|
@ -0,0 +1,32 @@
|
||||||
|
-- liquibase formatted sql
|
||||||
|
|
||||||
|
-- changeset xiaozhi:202512120922
|
||||||
|
-- 添加 AnimalSound 动物叫声 TTS 供应器
|
||||||
|
DELETE FROM `ai_model_provider` WHERE id = 'SYSTEM_TTS_AnimalSound';
|
||||||
|
INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `fields`, `sort`, `creator`, `create_date`, `updater`, `update_date`)
|
||||||
|
VALUES ('SYSTEM_TTS_AnimalSound', 'TTS', 'animal_sound', '动物叫声',
|
||||||
|
'[{"key":"base_path","label":"音频文件目录","type":"string"},{"key":"emotion_files","label":"情绪音频映射","type":"dict","dict_name":"emotion_files"},{"key":"default_file","label":"默认音频文件","type":"string"},{"key":"emotion_keywords","label":"情绪关键词映射","type":"dict","dict_name":"emotion_keywords"}]',
|
||||||
|
24, 1, NOW(), 1, NOW());
|
||||||
|
|
||||||
|
-- 添加 AnimalSound TTS 模型配置
|
||||||
|
DELETE FROM `ai_model_config` WHERE id = 'TTS_AnimalSound';
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('TTS_AnimalSound', 'TTS', 'AnimalSound', '动物叫声', 0, 1,
|
||||||
|
'{"type": "animal_sound", "base_path": "config/assets/animal_sounds", "emotion_files": {"happy": "cat_happy.wav", "sad": "cat_sad.wav", "angry": "cat_angry.wav", "afraid": "cat_afraid.wav", "helpless": "cat_helpless.wav", "coquetry": "cat_coquetry.wav", "default": "cat_neutral.wav"}, "emotion_keywords": {"happy": ["开心", "高兴", "快乐", "喜悦"], "sad": ["悲伤", "难过", "伤心", "沮丧"], "angry": ["生气", "愤怒", "气愤"], "afraid": ["害怕", "恐惧", "紧张"], "helpless": ["无奈", "唉", "叹气"], "coquetry": ["撒娇", "卖萌", "黏人"]}}',
|
||||||
|
NULL, NULL, 24, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
-- 更新 AnimalSound 配置说明
|
||||||
|
UPDATE `ai_model_config` SET
|
||||||
|
`doc_link` = 'https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/docs/animal-sound-mode.md',
|
||||||
|
`remark` = '动物叫声模式配置说明:
|
||||||
|
1. 此模式用于模仿动物和人的交互,根据LLM输出的情绪标签播放对应的动物叫声音频。
|
||||||
|
2. 需要在 base_path 目录下放置对应的音频文件(建议 16k/mono 的 wav 或 mp3 格式)。
|
||||||
|
3. 支持的情绪类型:开心、悲伤、生气、害怕、无奈、撒娇。
|
||||||
|
4. 如果LLM输出中包含情绪关键词,会自动匹配对应的音频文件。
|
||||||
|
5. 如果找不到对应情绪的音频,会使用 default 音频文件。
|
||||||
|
6. 详细使用说明请参考文档:docs/animal-sound-mode.md
|
||||||
|
' WHERE `id` = 'TTS_AnimalSound';
|
||||||
|
|
||||||
|
-- 添加默认音色(虽然动物叫声不需要音色,但为了兼容性添加)
|
||||||
|
DELETE FROM `ai_tts_voice` WHERE tts_model_id = 'TTS_AnimalSound';
|
||||||
|
INSERT INTO `ai_tts_voice` VALUES ('TTS_AnimalSound_0000', 'TTS_AnimalSound', '默认', 'default', '中文', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
39
main/xiaozhi-server/config/assets/animal_sounds/README.md
Normal file
39
main/xiaozhi-server/config/assets/animal_sounds/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# 动物叫声音频文件目录
|
||||||
|
|
||||||
|
此目录用于存放动物叫声的音频文件,用于"动物互动"模式。
|
||||||
|
|
||||||
|
## 文件命名规范
|
||||||
|
|
||||||
|
根据情绪类型,音频文件应命名为:
|
||||||
|
|
||||||
|
- `cat_happy.wav` - 开心情绪(对应关键词:开心、高兴、快乐、喜悦)
|
||||||
|
- `cat_sad.wav` - 悲伤情绪(对应关键词:悲伤、难过、伤心、沮丧)
|
||||||
|
- `cat_angry.wav` - 生气情绪(对应关键词:生气、愤怒、气愤)
|
||||||
|
- `cat_afraid.wav` - 害怕情绪(对应关键词:害怕、恐惧、紧张)
|
||||||
|
- `cat_helpless.wav` - 无奈情绪(对应关键词:无奈、唉、叹气)
|
||||||
|
- `cat_coquetry.wav` - 撒娇情绪(对应关键词:撒娇、卖萌、黏人)
|
||||||
|
- `cat_neutral.wav` - 默认情绪(当无法匹配到其他情绪时使用)
|
||||||
|
|
||||||
|
## 音频格式要求
|
||||||
|
|
||||||
|
- 建议格式:WAV 或 MP3
|
||||||
|
- 采样率:16kHz
|
||||||
|
- 声道:单声道(mono)
|
||||||
|
- 比特率:建议 16-bit
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
|
||||||
|
1. 将准备好的音频文件放入此目录
|
||||||
|
2. 在智控台的TTS模型配置中选择"动物叫声"模型
|
||||||
|
3. 确保LLM输出的文本中包含情绪关键词,系统会自动匹配对应的音频文件
|
||||||
|
4. 如果找不到对应情绪的音频,会使用默认音频文件(`cat_neutral.wav`)
|
||||||
|
|
||||||
|
## 自定义配置
|
||||||
|
|
||||||
|
可以在智控台的模型配置中自定义:
|
||||||
|
- 音频文件路径(`base_path`)
|
||||||
|
- 情绪到音频文件的映射(`emotion_files`)
|
||||||
|
- 情绪关键词映射(`emotion_keywords`)
|
||||||
|
|
||||||
|
详细配置说明请参考:`docs/animal-sound-mode.md`
|
||||||
|
|
||||||
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_afraid.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_afraid.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_angry.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_angry.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_coquetry.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_coquetry.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_happy.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_happy.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_helpless.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_helpless.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_neutral.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_neutral.wav
Normal file
Binary file not shown.
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_sad.wav
Normal file
BIN
main/xiaozhi-server/config/assets/animal_sounds/cat_sad.wav
Normal file
Binary file not shown.
|
|
@ -84,11 +84,30 @@ class TTSProvider(TTSProviderBase):
|
||||||
logger.bind(tag=TAG).warning(
|
logger.bind(tag=TAG).warning(
|
||||||
f"未找到对应的动物音频,emotion={emotion}, path={audio_path}"
|
f"未找到对应的动物音频,emotion={emotion}, path={audio_path}"
|
||||||
)
|
)
|
||||||
|
# 即使找不到音频,也要发送一个空的音频数据,避免客户端等待
|
||||||
|
self.tts_audio_queue.put(
|
||||||
|
(SentenceType.MIDDLE, b"", label_for_log)
|
||||||
|
)
|
||||||
|
|
||||||
|
elif message.content_type == ContentType.FILE:
|
||||||
|
# 处理文件类型的消息
|
||||||
|
if message.content_file and os.path.exists(message.content_file):
|
||||||
|
logger.bind(tag=TAG).info(
|
||||||
|
f"播放音频文件: {message.content_file}"
|
||||||
|
)
|
||||||
|
if not self._session_started:
|
||||||
|
self.tts_audio_queue.put(
|
||||||
|
(SentenceType.FIRST, None, message.content_detail or "")
|
||||||
|
)
|
||||||
|
self._session_started = True
|
||||||
|
self._process_audio_file_stream(
|
||||||
|
message.content_file, callback=self.handle_opus
|
||||||
|
)
|
||||||
|
|
||||||
if message.sentence_type == SentenceType.LAST:
|
if message.sentence_type == SentenceType.LAST:
|
||||||
# 一句话结束
|
# 一句话结束
|
||||||
self.tts_audio_queue.put(
|
self.tts_audio_queue.put(
|
||||||
(SentenceType.LAST, [], message.content_detail)
|
(SentenceType.LAST, [], message.content_detail or "")
|
||||||
)
|
)
|
||||||
self._session_started = False
|
self._session_started = False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue