1 Commits

Author SHA1 Message Date
6fd916f57c feat: TTS语音播放优化
- 退出对话界面时自动停止语音播放
- 优化TTS文本清理:添加更多Markdown特殊字符过滤
- 新增:任务列表、图片语法、删除线、表格、脚注引用清理
- 新增:更完整的emoji范围清理(200+个符号)
- 新增:数学符号、货币符号、版权符号清理
2026-04-29 17:38:25 +08:00

View File

@@ -518,6 +518,10 @@ function savePinnedAgents() {
// ==================== 主页(底部导航栏) ====================
function showMainPage() {
// 退出对话界面时停止语音播放
stopTTSQueue();
enableTTS = false;
currentConversation = null;
currentAgent = null;
@@ -4817,9 +4821,18 @@ function cleanTTSText(text) {
// 移除数字列表1.、2.等)
cleaned = cleaned.replace(/^\d+\.\s+/gm, '');
// 移除任务列表([ ]、[x]
cleaned = cleaned.replace(/^\s*\[[x ]\]\s*/gmi, '');
// 处理图片语法 ![alt](url) -> 移除整个图片标记
cleaned = cleaned.replace(/!\[[^\]]*\]\([^)]+\)/g, '');
// 处理链接 [text](url) -> 只保留text
cleaned = cleaned.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
// 移除删除线(~~text~~
cleaned = cleaned.replace(/~~([^~]+)~~/g, '$1');
// 移除粗体/斜体符号(**text**、*text*、__text__、_text_
cleaned = cleaned.replace(/\*\*([^*]+)\*\*/g, '$1');
cleaned = cleaned.replace(/\*([^*]+)\*/g, '$1');
@@ -4829,10 +4842,18 @@ function cleanTTSText(text) {
// 移除引用符号(>
cleaned = cleaned.replace(/^>\s*/gm, '');
// 移除分割线(---、***
// 移除分割线(---、***、___
cleaned = cleaned.replace(/^[\-\*]{3,}$/gm, '');
cleaned = cleaned.replace(/^_{3,}$/gm, '');
// 移除表情符号常见emoji范围
// 移除表格分隔符(| 和 ---|--|--
cleaned = cleaned.replace(/^\|.*\|$/gm, ''); // 表格行
cleaned = cleaned.replace(/^\s*[\-\:]+\s*\|[\s\-\:]+\|[\s\-\:]+\s*$/gm, ''); // 表格分隔行
// 移除脚注引用([^1]
cleaned = cleaned.replace(/\[\^[^\]]+\]/g, '');
// 移除表情符号完整emoji范围
cleaned = cleaned.replace(/[\u{1F600}-\u{1F64F}]/gu, ''); // 表情
cleaned = cleaned.replace(/[\u{1F300}-\u{1F5FF}]/gu, ''); // 符号和图形
cleaned = cleaned.replace(/[\u{1F680}-\u{1F6FF}]/gu, ''); // 交通和地图
@@ -4846,11 +4867,74 @@ function cleanTTSText(text) {
cleaned = cleaned.replace(/[\u{2700}-\u{27BF}]/gu, ''); // 装饰符号
cleaned = cleaned.replace(/[\u{FE00}-\u{FE0F}]/gu, ''); // 变体选择符
cleaned = cleaned.replace(/[\u{1F1E0}-\u{1F1FF}]/gu, ''); // 旗帜
cleaned = cleaned.replace(/[\u{1F004}\u{1F0CF}]/gu, ''); // 麻将牌
cleaned = cleaned.replace(/[\u{231A}-\u{231B}]/gu, ''); // 时钟
cleaned = cleaned.replace(/[\u{23E9}-\u{23F3}]/gu, ''); // 其他符号
cleaned = cleaned.replace(/[\u{23F8}-\u{23FA}]/gu, ''); // 暂停/播放等
cleaned = cleaned.replace(/[\u{25AA}-\u{25AB}]/gu, ''); // 小方块
cleaned = cleaned.replace(/[\u{25B6}]/gu, ''); // 播放按钮
cleaned = cleaned.replace(/[\u{25C0}]/gu, ''); // 反向播放
cleaned = cleaned.replace(/[\u{25FB}-\u{25FE}]/gu, ''); // 白色方块
cleaned = cleaned.replace(/[\u{2614}-\u{2615}]/gu, ''); // 雨伞/咖啡
cleaned = cleaned.replace(/[\u{2648}-\u{2653}]/gu, ''); // 星座符号
cleaned = cleaned.replace(/[\u{267F}]/gu, ''); // 轮椅符号
cleaned = cleaned.replace(/[\u{2693}]/gu, ''); // 船锚
cleaned = cleaned.replace(/[\u{26A1}]/gu, ''); // 高压符号
cleaned = cleaned.replace(/[\u{26AA}-\u{26AB}]/gu, ''); // 圆圈
cleaned = cleaned.replace(/[\u{26BD}]/gu, ''); // 足球
cleaned = cleaned.replace(/[\u{26BE}]/gu, ''); // 棒球
cleaned = cleaned.replace(/[\u{26C4}]/gu, ''); // 雪人
cleaned = cleaned.replace(/[\u{26C5}]/gu, ''); // 太阳云
cleaned = cleaned.replace(/[\u{26CE}]/gu, ''); // 星座
cleaned = cleaned.replace(/[\u{26D4}]/gu, ''); // 禁止进入
cleaned = cleaned.replace(/[\u{26EA}]/gu, ''); // 教堂
cleaned = cleaned.replace(/[\u{26F2}]/gu, ''); // 喷泉
cleaned = cleaned.replace(/[\u{26F3}]/gu, ''); // 高尔夫
cleaned = cleaned.replace(/[\u{26F5}]/gu, ''); // 帆船
cleaned = cleaned.replace(/[\u{26FA}]/gu, ''); // 帐篷
cleaned = cleaned.replace(/[\u{26FD}]/gu, ''); // 加油站
cleaned = cleaned.replace(/[\u{2702}]/gu, ''); // 剪刀
cleaned = cleaned.replace(/[\u{2705}]/gu, ''); // 白色对勾
cleaned = cleaned.replace(/[\u{2708}-\u{270D}]/gu, ''); // 飞机/笔等
cleaned = cleaned.replace(/[\u{270F}]/gu, ''); // 铅笔
cleaned = cleaned.replace(/[\u{2712}]/gu, ''); // 笔
cleaned = cleaned.replace(/[\u{2714}]/gu, ''); // 对勾
cleaned = cleaned.replace(/[\u{2716}]/gu, ''); // X标记
cleaned = cleaned.replace(/[\u{271D}]/gu, ''); // 十字架
cleaned = cleaned.replace(/[\u{2721}]/gu, ''); // 六芒星
cleaned = cleaned.replace(/[\u{2728}]/gu, ''); // 星光
cleaned = cleaned.replace(/[\u{2733}-\u{2734}]/gu, ''); // 八角雪花
cleaned = cleaned.replace(/[\u{2744}]/gu, ''); // 雪花
cleaned = cleaned.replace(/[\u{2747}]/gu, ''); // 闪亮
cleaned = cleaned.replace(/[\u{274C}]/gu, ''); // 红色X
cleaned = cleaned.replace(/[\u{274E}]/gu, ''); // 红色方X
cleaned = cleaned.replace(/[\u{2753}-\u{2755}]/gu, ''); // 问号
cleaned = cleaned.replace(/[\u{2757}]/gu, ''); // 感叹号
cleaned = cleaned.replace(/[\u{2763}-\u{2764}]/gu, ''); // 心形
cleaned = cleaned.replace(/[\u{2795}-\u{2797}]/gu, ''); // 加减乘
cleaned = cleaned.replace(/[\u{27A1}]/gu, ''); // 箭头
cleaned = cleaned.replace(/[\u{27B0}]/gu, ''); // 曲线箭头
cleaned = cleaned.replace(/[\u{27BF}]/gu, ''); // 双曲线箭头
cleaned = cleaned.replace(/[\u{2934}-\u{2935}]/gu, ''); // 箭头
cleaned = cleaned.replace(/[\u{2B05}-\u{2B07}]/gu, ''); // 方向箭头
cleaned = cleaned.replace(/[\u{2B1B}-\u{2B1C}]/gu, ''); // 黑白方块
cleaned = cleaned.replace(/[\u{2B50}]/gu, ''); // 中等星
cleaned = cleaned.replace(/[\u{2B55}]/gu, ''); // 圆圈
cleaned = cleaned.replace(/[\u{3030}]/gu, ''); // 波浪线
cleaned = cleaned.replace(/[\u{303D}]/gu, ''); // 花括号
cleaned = cleaned.replace(/[\u{3297}]/gu, ''); // 圆圈日文
cleaned = cleaned.replace(/[\u{3299}]/gu, ''); // 圆圈日文
// 移除HTML实体
cleaned = cleaned.replace(/&[a-zA-Z]+;/g, '');
// 清理多余空白
// 移除特殊符号(数学、货币等)
cleaned = cleaned.replace(/[≤≥≠≈∞∑∏√∫]/g, '');
cleaned = cleaned.replace(/[€£¥₹₽₩]/g, '');
cleaned = cleaned.replace(/[©®™]/g, '');
// 清理多余空白和换行
cleaned = cleaned.replace(/\n+/g, ' ');
cleaned = cleaned.replace(/\s+/g, ' ').trim();
return cleaned;