dsh-folia 4.26.0-pre.1 → 4.26.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +234 -2
- package/lib/routes/pet-chat.js +2 -0
- package/lib/settings-schema.js +28 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -8097,6 +8097,10 @@ window.__ModuleLoader__.load({
|
|
|
8097
8097
|
// ── 语音输入(默认关):真正干活的转写由 DSH 宿主的 speechToText 服务承担,
|
|
8098
8098
|
// 模型由那个 provider 自己下载/校验 —— 插件这边只负责录音与回填。
|
|
8099
8099
|
voiceEnabled: false,
|
|
8100
|
+
// ── 朗读回答(TTS):**默认开**;走系统 speechSynthesis,零依赖零 token。
|
|
8101
|
+
// enabled 与"宠物音效"完全无关(音效开关不影响朗读,反之亦然)。
|
|
8102
|
+
// voiceURI 空 = 自动挑中文音色(zh / Chinese / Huihui / Xiaoxiao …)。
|
|
8103
|
+
voiceOut: { enabled: true, rate: 1, pitch: 1, volume: 1, voiceURI: '' },
|
|
8100
8104
|
},
|
|
8101
8105
|
};
|
|
8102
8106
|
|
|
@@ -8814,6 +8818,10 @@ window.__ModuleLoader__.load({
|
|
|
8814
8818
|
const PET_CHAT_PERSONA_MAX = 200;
|
|
8815
8819
|
|
|
8816
8820
|
const petChatStr = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
8821
|
+
const petChatFloat = (v, lo, hi, fallback) => {
|
|
8822
|
+
const n = Number(v);
|
|
8823
|
+
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : fallback;
|
|
8824
|
+
};
|
|
8817
8825
|
const petChatInt = (v, lo, hi, fallback) => {
|
|
8818
8826
|
const n = Number(v);
|
|
8819
8827
|
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, Math.round(n))) : fallback;
|
|
@@ -8827,6 +8835,25 @@ window.__ModuleLoader__.load({
|
|
|
8827
8835
|
* 主机名拼错的 URL 与其"修好",不如让用户重新填一次。
|
|
8828
8836
|
* `apiKey` 原样保留(只在本机 profile 里),但**限长**,避免设置文件被灌爆。
|
|
8829
8837
|
*/
|
|
8838
|
+
/**
|
|
8839
|
+
* 朗读设置(TTS)的消毒。
|
|
8840
|
+
*
|
|
8841
|
+
* `enabled` 默认 **true**(工单要求默认开),所以判据是 `!== false` 而不是 `=== true` ——
|
|
8842
|
+
* 老档里没有这个键的人也会直接得到"开"。
|
|
8843
|
+
* rate/pitch/volume 走 clamp;voiceURI 只做长度限制(音色由运行时按 URI/中文名挑)。
|
|
8844
|
+
*/
|
|
8845
|
+
function readVoiceOut(raw) {
|
|
8846
|
+
const def = DEFAULTS.petChat.voiceOut;
|
|
8847
|
+
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
8848
|
+
return {
|
|
8849
|
+
enabled: src.enabled !== false,
|
|
8850
|
+
rate: petChatFloat(src.rate, 0.5, 2, def.rate),
|
|
8851
|
+
pitch: petChatFloat(src.pitch, 0, 2, def.pitch),
|
|
8852
|
+
volume: petChatFloat(src.volume, 0, 1, def.volume),
|
|
8853
|
+
voiceURI: petChatStr(src.voiceURI, 200).trim(),
|
|
8854
|
+
};
|
|
8855
|
+
}
|
|
8856
|
+
|
|
8830
8857
|
function readPetChat(raw) {
|
|
8831
8858
|
const def = DEFAULTS.petChat;
|
|
8832
8859
|
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
@@ -8854,6 +8881,7 @@ window.__ModuleLoader__.load({
|
|
|
8854
8881
|
quietHours: (typeof src.quietHours === 'string' && /^\d{2}:\d{2}-\d{2}:\d{2}$/.test(src.quietHours))
|
|
8855
8882
|
? src.quietHours : def.quietHours,
|
|
8856
8883
|
voiceEnabled: src.voiceEnabled === true,
|
|
8884
|
+
voiceOut: readVoiceOut(src.voiceOut),
|
|
8857
8885
|
};
|
|
8858
8886
|
}
|
|
8859
8887
|
|
|
@@ -20255,6 +20283,185 @@ window.__ModuleLoader__.load({
|
|
|
20255
20283
|
} catch { return () => {}; }
|
|
20256
20284
|
}
|
|
20257
20285
|
|
|
20286
|
+
// ── 内联模块:src/pet-chat-tts.js —— 朗读回答:speechSynthesis 薄封装(整段读 / 流式按句读 / 取消),不碰 DOM、不改文字(构建期注入;勿手改本段)──
|
|
20287
|
+
/**
|
|
20288
|
+
* pet-chat-tts.js — **朗读回答**(浏览器 / Electron 内置 speechSynthesis 的薄封装)。
|
|
20289
|
+
*
|
|
20290
|
+
* 三条铁律(来自工单):
|
|
20291
|
+
* ① **文字照常显示**:本模块只调 `speechSynthesis`,**不碰 DOM、不改文本** ——
|
|
20292
|
+
* 朗读是叠加,不是替换(气泡 + 打字机该显示什么还显示什么)。
|
|
20293
|
+
* ② **零依赖零 token**:走系统语音(Electron 下是 Windows SAPI);没有就说没有。
|
|
20294
|
+
* ③ 与宠物"音效"开关**无关**:这里只看 `petChat.voiceOut.enabled`。
|
|
20295
|
+
*
|
|
20296
|
+
* 朗读节奏:
|
|
20297
|
+
* · 整段到达(非流式 / 预设台词)⇒ `finish(text)` 整段读一次;
|
|
20298
|
+
* · 流式增量 ⇒ `push(chunk)`,凑满句末标点就按句读(不打断打字机)。
|
|
20299
|
+
*
|
|
20300
|
+
* 为什么要做成工厂并把 speechSynthesis / Utterance 注入进来:
|
|
20301
|
+
* 判据要能 mock(`test/verify-pet-chat.mjs` 的 6 条),而渲染进程的真实实现
|
|
20302
|
+
* 就是 `window.speechSynthesis` + `window.SpeechSynthesisUtterance`。
|
|
20303
|
+
*/
|
|
20304
|
+
|
|
20305
|
+
/** 句末标点(中英混排;省略号也算一句的结尾)。 */
|
|
20306
|
+
const PET_CHAT_TTS_SENTENCE_END = /[。!?!?;;…]+/;
|
|
20307
|
+
|
|
20308
|
+
/**
|
|
20309
|
+
* 按句末标点切句(保留标点)。
|
|
20310
|
+
* 单句过长(>120 字)时按逗号再切一次,避免一口气念 300 字。
|
|
20311
|
+
*/
|
|
20312
|
+
function petChatTtsSplit(text) {
|
|
20313
|
+
const raw = String(text ?? '');
|
|
20314
|
+
if (!raw.trim()) return [];
|
|
20315
|
+
const out = [];
|
|
20316
|
+
let buffer = '';
|
|
20317
|
+
for (const char of raw) {
|
|
20318
|
+
buffer += char;
|
|
20319
|
+
if (PET_CHAT_TTS_SENTENCE_END.test(char)) {
|
|
20320
|
+
if (buffer.trim()) out.push(buffer.trim());
|
|
20321
|
+
buffer = '';
|
|
20322
|
+
}
|
|
20323
|
+
}
|
|
20324
|
+
if (buffer.trim()) out.push(buffer.trim());
|
|
20325
|
+
// 保险:单句 >120 字再按逗号切
|
|
20326
|
+
const final = [];
|
|
20327
|
+
for (const sentence of out) {
|
|
20328
|
+
if (sentence.length <= 120) { final.push(sentence); continue; }
|
|
20329
|
+
let piece = '';
|
|
20330
|
+
for (const char of sentence) {
|
|
20331
|
+
piece += char;
|
|
20332
|
+
if (char === ',' || char === ',' ) { final.push(piece); piece = ''; }
|
|
20333
|
+
}
|
|
20334
|
+
if (piece.trim()) final.push(piece);
|
|
20335
|
+
}
|
|
20336
|
+
return final;
|
|
20337
|
+
}
|
|
20338
|
+
|
|
20339
|
+
/** 中文音色识别:`zh-*`、名字里带 Chinese / Huihui / Xiaoxiao。 */
|
|
20340
|
+
function petChatTtsIsChinese(voice) {
|
|
20341
|
+
if (!voice) return false;
|
|
20342
|
+
const lang = String(voice.lang || '').toLowerCase();
|
|
20343
|
+
const name = String(voice.name || '');
|
|
20344
|
+
return lang.startsWith('zh') || /chinese|huihui|xiaoxiao|kangkang|yaoyao|tingting|hanhan/i.test(name);
|
|
20345
|
+
}
|
|
20346
|
+
|
|
20347
|
+
/**
|
|
20348
|
+
* 造一个朗读引擎。
|
|
20349
|
+
*
|
|
20350
|
+
* @param {object} deps
|
|
20351
|
+
* @param {() => any} deps.getSpeech 返回 speechSynthesis(可能不存在)
|
|
20352
|
+
* @param {() => any[]} deps.getVoices 返回音色列表(可能为空)
|
|
20353
|
+
* @param {() => object} deps.getConfig 返回 `{ enabled, rate, pitch, volume, voiceURI }`
|
|
20354
|
+
* @param {Function} [deps.Utterance] `SpeechSynthesisUtterance` 构造器
|
|
20355
|
+
* @param {(code:string, message:string) => void} [deps.onHint] 一次性提示回调
|
|
20356
|
+
*/
|
|
20357
|
+
function petChatTtsCreate(deps) {
|
|
20358
|
+
const options = deps || {};
|
|
20359
|
+
const getSpeech = typeof options.getSpeech === 'function' ? options.getSpeech : () => null;
|
|
20360
|
+
const getVoices = typeof options.getVoices === 'function' ? options.getVoices : () => [];
|
|
20361
|
+
const getConfig = typeof options.getConfig === 'function' ? options.getConfig : () => ({ enabled: false });
|
|
20362
|
+
const onHint = typeof options.onHint === 'function' ? options.onHint : () => {};
|
|
20363
|
+
const Utterance = options.Utterance;
|
|
20364
|
+
|
|
20365
|
+
let pending = ''; // 流式未成句的尾巴
|
|
20366
|
+
let spokenInTurn = 0; // 本回合已经读了几段(决定 finish 要不要整段读)
|
|
20367
|
+
let hintShown = {}; // 一次性提示去重(按 code)
|
|
20368
|
+
|
|
20369
|
+
const hintOnce = (code, message) => {
|
|
20370
|
+
if (hintShown[code]) return;
|
|
20371
|
+
hintShown[code] = true;
|
|
20372
|
+
onHint(code, message);
|
|
20373
|
+
};
|
|
20374
|
+
|
|
20375
|
+
/** 选音色:voiceURI 优先,其次第一个中文音色;都没有返回 null(并提示一次)。 */
|
|
20376
|
+
function pickVoice(config, voices) {
|
|
20377
|
+
const list = Array.isArray(voices) ? voices : [];
|
|
20378
|
+
const wanted = String(config.voiceURI || '').trim();
|
|
20379
|
+
if (wanted) {
|
|
20380
|
+
const hit = list.find((voice) => voice && (voice.voiceURI === wanted || voice.name === wanted));
|
|
20381
|
+
if (hit) return hit;
|
|
20382
|
+
}
|
|
20383
|
+
const chinese = list.find((voice) => petChatTtsIsChinese(voice));
|
|
20384
|
+
if (chinese) return chinese;
|
|
20385
|
+
if (list.length) hintOnce('no-chinese-voice', '系统里没有中文音色,朗读可能不自然');
|
|
20386
|
+
return null;
|
|
20387
|
+
}
|
|
20388
|
+
|
|
20389
|
+
/** 读一段(内部):config 关了就什么都不做。 */
|
|
20390
|
+
function speakOne(text, speech, config, voices) {
|
|
20391
|
+
const trimmed = String(text ?? '').trim();
|
|
20392
|
+
if (!trimmed) return false;
|
|
20393
|
+
if (typeof Utterance !== 'function') return false;
|
|
20394
|
+
const utterance = new Utterance(trimmed);
|
|
20395
|
+
utterance.rate = Number.isFinite(Number(config.rate)) ? Number(config.rate) : 1;
|
|
20396
|
+
utterance.pitch = Number.isFinite(Number(config.pitch)) ? Number(config.pitch) : 1;
|
|
20397
|
+
utterance.volume = Number.isFinite(Number(config.volume)) ? Number(config.volume) : 1;
|
|
20398
|
+
const voice = pickVoice(config, voices);
|
|
20399
|
+
if (voice) utterance.voice = voice;
|
|
20400
|
+
speech.speak(utterance);
|
|
20401
|
+
if (!hintShown['first-speak']) {
|
|
20402
|
+
hintShown['first-speak'] = true;
|
|
20403
|
+
hintOnce('first-speak', '使用系统语音,无需下载 / 不耗 token');
|
|
20404
|
+
}
|
|
20405
|
+
return true;
|
|
20406
|
+
}
|
|
20407
|
+
|
|
20408
|
+
/** 新回合开始:停掉上一段朗读,清空缓冲。 */
|
|
20409
|
+
function start() {
|
|
20410
|
+
pending = '';
|
|
20411
|
+
spokenInTurn = 0;
|
|
20412
|
+
cancel();
|
|
20413
|
+
}
|
|
20414
|
+
|
|
20415
|
+
/** 取消朗读(关闭气泡 / 点停止 / 新消息)。 */
|
|
20416
|
+
function cancel() {
|
|
20417
|
+
const speech = getSpeech();
|
|
20418
|
+
if (speech && typeof speech.cancel === 'function') speech.cancel();
|
|
20419
|
+
}
|
|
20420
|
+
|
|
20421
|
+
/** 流式增量:凑满整句就先读(保证"边出字边读",但不打断打字机)。 */
|
|
20422
|
+
function push(chunk) {
|
|
20423
|
+
const config = getConfig() || {};
|
|
20424
|
+
if (config.enabled !== true) return;
|
|
20425
|
+
const speech = getSpeech();
|
|
20426
|
+
if (!speech || typeof speech.speak !== 'function') return; // ⑤ 没有 speechSynthesis ⇒ 静默跳过
|
|
20427
|
+
const text = String(chunk ?? '');
|
|
20428
|
+
if (!text) return;
|
|
20429
|
+
pending += text;
|
|
20430
|
+
const sentences = petChatTtsSplit(pending);
|
|
20431
|
+
// 只有"以标点结尾"的才算成句;最后一段若不以标点结尾,留到下次
|
|
20432
|
+
const endsWithPunct = PET_CHAT_TTS_SENTENCE_END.test(pending.slice(-1));
|
|
20433
|
+
const ready = endsWithPunct ? sentences : sentences.slice(0, -1);
|
|
20434
|
+
if (!ready.length) return;
|
|
20435
|
+
if (endsWithPunct) pending = '';
|
|
20436
|
+
else pending = sentences[sentences.length - 1] || '';
|
|
20437
|
+
const voices = getVoices();
|
|
20438
|
+
for (const sentence of ready) if (speakOne(sentence, speech, config, voices)) spokenInTurn += 1;
|
|
20439
|
+
}
|
|
20440
|
+
|
|
20441
|
+
/**
|
|
20442
|
+
* 回复结束:整段朗读。
|
|
20443
|
+
* 已经边流边读过句子的,这里只读剩下的尾巴;从没读过 ⇒ 整段读一次(判据①)。
|
|
20444
|
+
*/
|
|
20445
|
+
function finish(fullText) {
|
|
20446
|
+
const config = getConfig() || {};
|
|
20447
|
+
if (config.enabled !== true) return;
|
|
20448
|
+
const speech = getSpeech();
|
|
20449
|
+
if (!speech || typeof speech.speak !== 'function') return;
|
|
20450
|
+
const whole = String(fullText ?? '');
|
|
20451
|
+
const tail = pending;
|
|
20452
|
+
pending = '';
|
|
20453
|
+
const voices = getVoices();
|
|
20454
|
+
if (spokenInTurn === 0) {
|
|
20455
|
+
// 整段一次读完(气泡里显示的还是同一段文字,这里只是读它)
|
|
20456
|
+
if (whole.trim()) speakOne(whole.trim(), speech, config, voices);
|
|
20457
|
+
return;
|
|
20458
|
+
}
|
|
20459
|
+
if (tail.trim()) speakOne(tail.trim(), speech, config, voices);
|
|
20460
|
+
}
|
|
20461
|
+
|
|
20462
|
+
return { start, push, finish, cancel, split: petChatTtsSplit };
|
|
20463
|
+
}
|
|
20464
|
+
|
|
20258
20465
|
// ── 内联模块:src/pet-chat.js —— 桌宠对话气泡:点宠物出输入框,走宿主 /folia/pet-chat/* 的 SSE;没配模型时给预设台词(构建期注入;勿手改本段)──
|
|
20259
20466
|
/**
|
|
20260
20467
|
* pet-chat.js(客户端)— **桌宠对话气泡**(门 2 / 任务 A3)。
|
|
@@ -20349,6 +20556,12 @@ window.__ModuleLoader__.load({
|
|
|
20349
20556
|
petChatOn(voiceBtn, 'pointerdown', (event) => { if (event && event.preventDefault) event.preventDefault(); void petChatVoiceStart(); });
|
|
20350
20557
|
petChatOn(voiceBtn, 'pointerup', () => { void petChatVoiceStop(); });
|
|
20351
20558
|
petChatOn(voiceBtn, 'pointerleave', () => { if (petChatVoice) void petChatVoiceStop(); });
|
|
20559
|
+
// 停止朗读:只停语音,不动文字(文字已经显示在气泡里)
|
|
20560
|
+
const stopBtn = document.createElement('button');
|
|
20561
|
+
stopBtn.type = 'button';
|
|
20562
|
+
stopBtn.textContent = weT('停止朗读');
|
|
20563
|
+
stopBtn.style.cssText = 'background:none;border:1px solid rgba(255,255,255,.14);border-radius:7px;color:#c9c9d1;font-size:11px;padding:2px 6px;cursor:pointer';
|
|
20564
|
+
petChatOn(stopBtn, 'click', () => petChatTts.cancel());
|
|
20352
20565
|
const memoryBtn = document.createElement('button');
|
|
20353
20566
|
memoryBtn.type = 'button';
|
|
20354
20567
|
memoryBtn.textContent = weT('查看记忆');
|
|
@@ -20365,7 +20578,7 @@ window.__ModuleLoader__.load({
|
|
|
20365
20578
|
close.title = weT('关闭');
|
|
20366
20579
|
close.style.cssText = 'background:none;border:0;color:#c9c9d1;font-size:18px;cursor:pointer;line-height:1';
|
|
20367
20580
|
petChatOn(close, 'click', () => petChatHide());
|
|
20368
|
-
petChatAppend(tools, voiceBtn, memoryBtn, clear, close);
|
|
20581
|
+
petChatAppend(tools, voiceBtn, stopBtn, memoryBtn, clear, close);
|
|
20369
20582
|
petChatAppend(head, title, tools);
|
|
20370
20583
|
|
|
20371
20584
|
const log = document.createElement('div');
|
|
@@ -20451,6 +20664,7 @@ window.__ModuleLoader__.load({
|
|
|
20451
20664
|
|
|
20452
20665
|
function petChatHide() {
|
|
20453
20666
|
if (!petChatEls) return;
|
|
20667
|
+
petChatTts.cancel(); // 关闭气泡:立刻停读
|
|
20454
20668
|
petChatEls.root.style.display = 'none';
|
|
20455
20669
|
}
|
|
20456
20670
|
|
|
@@ -20489,6 +20703,7 @@ window.__ModuleLoader__.load({
|
|
|
20489
20703
|
const doc = probe && probe.data;
|
|
20490
20704
|
// 语音输入开关由宿主带回来:false ⇒ 按麦克风只提示"先去 DSH 开",不弹权限框
|
|
20491
20705
|
petChatVoiceEnabled = doc && doc.voiceEnabled === true;
|
|
20706
|
+
if (doc && doc.voiceOut && typeof doc.voiceOut === 'object') petChatVoiceOut = doc.voiceOut;
|
|
20492
20707
|
if (!doc || doc.enabled !== true) {
|
|
20493
20708
|
petChatStatus(weT('未开启对话(设置 → 桌宠 → 桌宠对话)'));
|
|
20494
20709
|
return null;
|
|
@@ -20537,13 +20752,16 @@ window.__ModuleLoader__.load({
|
|
|
20537
20752
|
if ([...text].length > 400) { petChatStatus(weT('一次最多 400 字')); return; }
|
|
20538
20753
|
els.input.value = '';
|
|
20539
20754
|
petChatPush('user', text);
|
|
20755
|
+
petChatTts.start(); // 新消息:停掉上一段朗读
|
|
20540
20756
|
petChatBusy = true;
|
|
20541
20757
|
petChatStatus(weT('思考中…'));
|
|
20542
20758
|
|
|
20543
20759
|
const state = await petChatSyncState();
|
|
20544
20760
|
if (!state || state.enabled !== true) {
|
|
20545
20761
|
// 没有模型:不假装在对话,直接给预设台词
|
|
20546
|
-
|
|
20762
|
+
const presetLine = petChatPresetLine();
|
|
20763
|
+
petChatPush('assistant', presetLine);
|
|
20764
|
+
petChatTts.finish(presetLine);
|
|
20547
20765
|
petChatStatus(weT('未开启对话(设置 → 桌宠 → 桌宠对话)'));
|
|
20548
20766
|
petChatBusy = false;
|
|
20549
20767
|
return;
|
|
@@ -20582,9 +20800,11 @@ window.__ModuleLoader__.load({
|
|
|
20582
20800
|
if (parsed.event === 'delta' && parsed.data && typeof parsed.data.t === 'string') {
|
|
20583
20801
|
assistant += parsed.data.t;
|
|
20584
20802
|
ensureBubble();
|
|
20803
|
+
petChatTts.push(parsed.data.t);
|
|
20585
20804
|
petChatLines[petChatLines.length - 1] = { role: 'assistant', text: assistant };
|
|
20586
20805
|
petChatRender();
|
|
20587
20806
|
} else if (parsed.event === 'done') {
|
|
20807
|
+
petChatTts.finish(assistant);
|
|
20588
20808
|
petChatApplyEmotion(parsed.data && parsed.data.emotion);
|
|
20589
20809
|
petChatStatus('');
|
|
20590
20810
|
} else if (parsed.event === 'error') {
|
|
@@ -20665,6 +20885,18 @@ window.__ModuleLoader__.load({
|
|
|
20665
20885
|
const PET_CHAT_VOICE_MAX_SECONDS = 15;
|
|
20666
20886
|
let petChatVoice = null;
|
|
20667
20887
|
let petChatVoiceEnabled = null;
|
|
20888
|
+
// 朗读(TTS):默认开;配置由 /state 带回,没拿到时按默认值(开)
|
|
20889
|
+
let petChatVoiceOut = { enabled: true, rate: 1, pitch: 1, volume: 1, voiceURI: '' };
|
|
20890
|
+
const petChatTts = petChatTtsCreate({
|
|
20891
|
+
getSpeech: () => (typeof window !== 'undefined' ? window.speechSynthesis : null),
|
|
20892
|
+
getVoices: () => {
|
|
20893
|
+
const speech = typeof window !== 'undefined' ? window.speechSynthesis : null;
|
|
20894
|
+
return speech && typeof speech.getVoices === 'function' ? speech.getVoices() : [];
|
|
20895
|
+
},
|
|
20896
|
+
getConfig: () => petChatVoiceOut,
|
|
20897
|
+
Utterance: typeof window !== 'undefined' ? window.SpeechSynthesisUtterance : undefined,
|
|
20898
|
+
onHint: (code, message) => petChatStatus(message),
|
|
20899
|
+
});
|
|
20668
20900
|
|
|
20669
20901
|
/** Float32 PCM → 16kHz 单声道 PCM16 WAV。 */
|
|
20670
20902
|
function petChatEncodeWav(samples, sampleRate) {
|
package/lib/routes/pet-chat.js
CHANGED
|
@@ -281,6 +281,7 @@ export function registerPetChatRoutes(webServer, c) {
|
|
|
281
281
|
proactiveMinGapMin: Number.isFinite(Number(raw.proactiveMinGapMin)) ? Math.max(30, Math.min(720, Number(raw.proactiveMinGapMin))) : 120,
|
|
282
282
|
quietHours: typeof raw.quietHours === 'string' && /^\d{2}:\d{2}-\d{2}:\d{2}$/.test(raw.quietHours) ? raw.quietHours : '22:00-08:00',
|
|
283
283
|
voiceEnabled: raw.voiceEnabled === true,
|
|
284
|
+
voiceOut: raw.voiceOut && typeof raw.voiceOut === 'object' ? { enabled: raw.voiceOut.enabled !== false, rate: Number(raw.voiceOut.rate) || 1, pitch: Number(raw.voiceOut.pitch) || 0, volume: Number(raw.voiceOut.volume) || 1, voiceURI: String(raw.voiceOut.voiceURI || '') } : { enabled: true, rate: 1, pitch: 1, volume: 1, voiceURI: '' },
|
|
284
285
|
};
|
|
285
286
|
}
|
|
286
287
|
|
|
@@ -352,6 +353,7 @@ export function registerPetChatRoutes(webServer, c) {
|
|
|
352
353
|
lastError,
|
|
353
354
|
// 语音输入:客户端据此决定麦克风按钮是"可直接录"还是"先提示去开启"
|
|
354
355
|
voiceEnabled: config.voiceEnabled === true,
|
|
356
|
+
voiceOut: config.voiceOut,
|
|
355
357
|
asrProvider: ASR_PROVIDER_ID,
|
|
356
358
|
}));
|
|
357
359
|
}
|
package/lib/settings-schema.js
CHANGED
|
@@ -1009,6 +1009,10 @@ const DEFAULTS = {
|
|
|
1009
1009
|
// ── 语音输入(默认关):真正干活的转写由 DSH 宿主的 speechToText 服务承担,
|
|
1010
1010
|
// 模型由那个 provider 自己下载/校验 —— 插件这边只负责录音与回填。
|
|
1011
1011
|
voiceEnabled: false,
|
|
1012
|
+
// ── 朗读回答(TTS):**默认开**;走系统 speechSynthesis,零依赖零 token。
|
|
1013
|
+
// enabled 与"宠物音效"完全无关(音效开关不影响朗读,反之亦然)。
|
|
1014
|
+
// voiceURI 空 = 自动挑中文音色(zh / Chinese / Huihui / Xiaoxiao …)。
|
|
1015
|
+
voiceOut: { enabled: true, rate: 1, pitch: 1, volume: 1, voiceURI: '' },
|
|
1012
1016
|
},
|
|
1013
1017
|
};
|
|
1014
1018
|
|
|
@@ -1726,6 +1730,10 @@ const PET_CHAT_MODEL_MAX = 120;
|
|
|
1726
1730
|
const PET_CHAT_PERSONA_MAX = 200;
|
|
1727
1731
|
|
|
1728
1732
|
const petChatStr = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
1733
|
+
const petChatFloat = (v, lo, hi, fallback) => {
|
|
1734
|
+
const n = Number(v);
|
|
1735
|
+
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, n)) : fallback;
|
|
1736
|
+
};
|
|
1729
1737
|
const petChatInt = (v, lo, hi, fallback) => {
|
|
1730
1738
|
const n = Number(v);
|
|
1731
1739
|
return Number.isFinite(n) ? Math.min(hi, Math.max(lo, Math.round(n))) : fallback;
|
|
@@ -1739,6 +1747,25 @@ const petChatInt = (v, lo, hi, fallback) => {
|
|
|
1739
1747
|
* 主机名拼错的 URL 与其"修好",不如让用户重新填一次。
|
|
1740
1748
|
* `apiKey` 原样保留(只在本机 profile 里),但**限长**,避免设置文件被灌爆。
|
|
1741
1749
|
*/
|
|
1750
|
+
/**
|
|
1751
|
+
* 朗读设置(TTS)的消毒。
|
|
1752
|
+
*
|
|
1753
|
+
* `enabled` 默认 **true**(工单要求默认开),所以判据是 `!== false` 而不是 `=== true` ——
|
|
1754
|
+
* 老档里没有这个键的人也会直接得到"开"。
|
|
1755
|
+
* rate/pitch/volume 走 clamp;voiceURI 只做长度限制(音色由运行时按 URI/中文名挑)。
|
|
1756
|
+
*/
|
|
1757
|
+
function readVoiceOut(raw) {
|
|
1758
|
+
const def = DEFAULTS.petChat.voiceOut;
|
|
1759
|
+
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
1760
|
+
return {
|
|
1761
|
+
enabled: src.enabled !== false,
|
|
1762
|
+
rate: petChatFloat(src.rate, 0.5, 2, def.rate),
|
|
1763
|
+
pitch: petChatFloat(src.pitch, 0, 2, def.pitch),
|
|
1764
|
+
volume: petChatFloat(src.volume, 0, 1, def.volume),
|
|
1765
|
+
voiceURI: petChatStr(src.voiceURI, 200).trim(),
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1742
1769
|
function readPetChat(raw) {
|
|
1743
1770
|
const def = DEFAULTS.petChat;
|
|
1744
1771
|
const src = raw && typeof raw === 'object' && !Array.isArray(raw) ? raw : {};
|
|
@@ -1766,6 +1793,7 @@ function readPetChat(raw) {
|
|
|
1766
1793
|
quietHours: (typeof src.quietHours === 'string' && /^\d{2}:\d{2}-\d{2}:\d{2}$/.test(src.quietHours))
|
|
1767
1794
|
? src.quietHours : def.quietHours,
|
|
1768
1795
|
voiceEnabled: src.voiceEnabled === true,
|
|
1796
|
+
voiceOut: readVoiceOut(src.voiceOut),
|
|
1769
1797
|
};
|
|
1770
1798
|
}
|
|
1771
1799
|
|