dsh-folia 4.26.0-pre.61 → 4.26.0-pre.63
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 +251 -20
- package/lib/index.js +3 -0
- package/lib/media/transcode.js +225 -3
- package/lib/route-registry.js +2 -0
- package/lib/routes/pet-chat.js +122 -23
- package/lib/voice/record.js +373 -27
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -745,6 +745,17 @@ window.__ModuleLoader__.load({
|
|
|
745
745
|
"在听": "Listening",
|
|
746
746
|
"在想": "Thinking",
|
|
747
747
|
"在说": "Speaking",
|
|
748
|
+
// pre.63:连续对话(右键菜单 + 设置页同一 voice.continuous)
|
|
749
|
+
"连续对话": "Continuous conversation",
|
|
750
|
+
"暂停听": "Pause listening",
|
|
751
|
+
"继续听": "Resume listening",
|
|
752
|
+
"连续对话中 · 右键可关闭": "Continuous conversation · right-click to turn off",
|
|
753
|
+
"⏸ 连续对话已暂停(点桌宠继续)": "⏸ Continuous conversation paused (click the pet to resume)",
|
|
754
|
+
"页面隐藏,连续对话已暂停": "Page hidden — continuous conversation paused",
|
|
755
|
+
"连续对话结束:已连续 {n} 轮": "Continuous conversation ended after {n} rounds",
|
|
756
|
+
"连续对话已停止:{e}": "Continuous conversation stopped: {e}",
|
|
757
|
+
"连续对话结束:连续 {n} 轮没听到": "Continuous conversation ended: no speech for {n} rounds",
|
|
758
|
+
"没听到,再说一次({n}/{m})": "Didn't hear that — try again ({n}/{m})",
|
|
748
759
|
"所选音色不可用,已用系统默认:{name}": "Selected voice is unavailable — using the system default: {name}",
|
|
749
760
|
"所选音色不可用,已用系统默认音色": "Selected voice is unavailable — using the system default voice",
|
|
750
761
|
// pre.54:本机音色来源 / 可下载目录骨架。
|
|
@@ -1208,8 +1219,18 @@ window.__ModuleLoader__.load({
|
|
|
1208
1219
|
"保存失败": "Save failed",
|
|
1209
1220
|
"保存失败:{msg}": "Save failed: {msg}",
|
|
1210
1221
|
"正在检测麦克风、预热语音识别与合成…(首次会下载模型)": "Checking the microphone and warming up speech recognition and synthesis… (models download on first use)",
|
|
1222
|
+
// pre.62:语音运行环境(ffmpeg 懒下载)
|
|
1223
|
+
"正在准备录音组件、检测麦克风、预热语音识别与合成…(首次会下载)": "Preparing the recording component, checking the microphone and warming up speech recognition and synthesis… (downloads on first use)",
|
|
1224
|
+
"语音运行环境:ffmpeg 已就绪": "Voice runtime: ffmpeg ready",
|
|
1225
|
+
"语音运行环境:准备失败(点击重试)": "Voice runtime: preparation failed (click to retry)",
|
|
1226
|
+
"语音运行环境:准备失败({err})": "Voice runtime: preparation failed ({err})",
|
|
1227
|
+
"语音运行环境:尚未准备": "Voice runtime: not prepared yet",
|
|
1228
|
+
"正在准备录音组件 {pct}%": "Preparing the recording component {pct}%",
|
|
1229
|
+
"录音组件还在准备,稍后再点我": "The recording component is still preparing — tap me again shortly",
|
|
1230
|
+
"录音组件准备失败,去「智能大肥鱼 → 朗读与音色」点重试": "Recording component preparation failed — retry in Smart Chubby Fish → Read-aloud & voices",
|
|
1231
|
+
"自动准备 ffmpeg、选麦克风、选音色、预热 ASR/TTS。": "Prepares ffmpeg, picks the microphone and voice, and warms up ASR/TTS.",
|
|
1211
1232
|
"一键启用完成:能听、能说。": "One-click setup complete: it can hear and speak.",
|
|
1212
|
-
"
|
|
1233
|
+
"一键启用有未通过项,见下面的报告。": "Some checks did not pass; see the report below.",
|
|
1213
1234
|
"一键启用失败:{msg}": "One-click setup failed: {msg}",
|
|
1214
1235
|
"助手": "Assistant",
|
|
1215
1236
|
"朗读与音色": "Read-aloud & voices",
|
|
@@ -19371,6 +19392,8 @@ window.__ModuleLoader__.load({
|
|
|
19371
19392
|
const [voiceCfg, setVoiceCfg] = React.useState({ sapiEnabled: false, enabledEngine: 'edge', continuous: true });
|
|
19372
19393
|
const [setupBusy, setSetupBusy] = React.useState(false);
|
|
19373
19394
|
const [setupReport, setSetupReport] = React.useState(null);
|
|
19395
|
+
// pre.62:录音组件(ffmpeg)供给状态;下载中时轮询 /voice/diagnose 显示百分比。
|
|
19396
|
+
const [ffmpeg, setFfmpeg] = React.useState(null);
|
|
19374
19397
|
const [enabledEngine, setEnabledEngine] = React.useState('edge');
|
|
19375
19398
|
const [checkedEngine, setCheckedEngine] = React.useState('edge');
|
|
19376
19399
|
const [enableBusy, setEnableBusy] = React.useState('');
|
|
@@ -19395,6 +19418,25 @@ window.__ModuleLoader__.load({
|
|
|
19395
19418
|
hasKey: false, maskedKey: '', lastError: '',
|
|
19396
19419
|
});
|
|
19397
19420
|
const update = React.useCallback((patch) => setDraft((prev) => ({ ...prev, ...patch })), []);
|
|
19421
|
+
/** pre.63:把设置页的连续对话开关同步给右键菜单(同一 voice.continuous)。 */
|
|
19422
|
+
const publishContinuous = React.useCallback((enabled) => {
|
|
19423
|
+
try {
|
|
19424
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
|
|
19425
|
+
window.dispatchEvent(new CustomEvent('we-pet-continuous-state', { detail: { enabled: enabled === true } }));
|
|
19426
|
+
}
|
|
19427
|
+
} catch { /* 菜单同步是增强 */ }
|
|
19428
|
+
}, []);
|
|
19429
|
+
React.useEffect(() => {
|
|
19430
|
+
const onState = (event) => {
|
|
19431
|
+
const detail = (event && event.detail) || {};
|
|
19432
|
+
if (typeof detail.enabled === 'boolean') {
|
|
19433
|
+
setVoiceCfg((prev) => ({ ...prev, continuous: detail.enabled }));
|
|
19434
|
+
}
|
|
19435
|
+
};
|
|
19436
|
+
if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') return undefined;
|
|
19437
|
+
window.addEventListener('we-pet-continuous-state', onState);
|
|
19438
|
+
return () => window.removeEventListener('we-pet-continuous-state', onState);
|
|
19439
|
+
}, []);
|
|
19398
19440
|
|
|
19399
19441
|
const load = React.useCallback(async () => {
|
|
19400
19442
|
try {
|
|
@@ -19407,6 +19449,7 @@ window.__ModuleLoader__.load({
|
|
|
19407
19449
|
voice.continuous = voice.continuous !== false;
|
|
19408
19450
|
setDraft({ ...CHAT_DEFAULTS, ...doc, voice, apiKey: '' });
|
|
19409
19451
|
setVoiceCfg({ sapiEnabled: voice.sapiEnabled, enabledEngine: voice.enabledEngine, continuous: voice.continuous });
|
|
19452
|
+
publishContinuous(voice.continuous !== false);
|
|
19410
19453
|
setEnabledEngine(voice.enabledEngine);
|
|
19411
19454
|
setCheckedEngine(voice.enabledEngine);
|
|
19412
19455
|
setStatus(doc.hasApiKey
|
|
@@ -19414,7 +19457,7 @@ window.__ModuleLoader__.load({
|
|
|
19414
19457
|
: { ok: null, text: weT('还没有填 API Key') });
|
|
19415
19458
|
}
|
|
19416
19459
|
} catch { /* 首次加载失败不打扰 */ }
|
|
19417
|
-
}, []);
|
|
19460
|
+
}, [publishContinuous]);
|
|
19418
19461
|
|
|
19419
19462
|
const loadVoices = React.useCallback(async () => {
|
|
19420
19463
|
const resp = await apiJson('/pet-chat/tts/voices', { parse: 'always' }).catch(() => null);
|
|
@@ -19441,6 +19484,13 @@ window.__ModuleLoader__.load({
|
|
|
19441
19484
|
}
|
|
19442
19485
|
}, []);
|
|
19443
19486
|
|
|
19487
|
+
const loadFfmpeg = React.useCallback(async () => {
|
|
19488
|
+
const resp = await apiJson('/pet-chat/voice/diagnose?light=1', { parse: 'always' }).catch(() => null);
|
|
19489
|
+
const doc = unwrapPetChat(resp);
|
|
19490
|
+
const st = doc && doc.steps && doc.steps.ffmpeg;
|
|
19491
|
+
if (st && st.phase) setFfmpeg(st);
|
|
19492
|
+
}, []);
|
|
19493
|
+
|
|
19444
19494
|
const loadProviders = React.useCallback(async () => {
|
|
19445
19495
|
const resp = await apiJson('/pet-chat/voice/providers', { parse: 'always' }).catch(() => null);
|
|
19446
19496
|
const doc = unwrapPetChat(resp);
|
|
@@ -19483,7 +19533,15 @@ window.__ModuleLoader__.load({
|
|
|
19483
19533
|
|
|
19484
19534
|
React.useEffect(() => { void load(); }, [load]);
|
|
19485
19535
|
React.useEffect(() => { void loadVoices(); }, [loadVoices]);
|
|
19536
|
+
React.useEffect(() => { void loadFfmpeg(); }, [loadFfmpeg]);
|
|
19486
19537
|
React.useEffect(() => { void loadProviders(); }, [loadProviders]);
|
|
19538
|
+
// 下载期间 800ms 刷一次进度;ready/failed/idle 不再轮询。
|
|
19539
|
+
React.useEffect(() => {
|
|
19540
|
+
const phase = ffmpeg && ffmpeg.phase;
|
|
19541
|
+
if (phase !== 'preparing' && phase !== 'download') return undefined;
|
|
19542
|
+
const timer = setInterval(() => { void loadFfmpeg(); }, 800);
|
|
19543
|
+
return () => clearInterval(timer);
|
|
19544
|
+
}, [ffmpeg && ffmpeg.phase, loadFfmpeg]);
|
|
19487
19545
|
React.useEffect(() => {
|
|
19488
19546
|
void (async () => {
|
|
19489
19547
|
const resp = await apiJson('/pet-chat/work-plugins', { parse: 'always' }).catch(() => null);
|
|
@@ -19700,7 +19758,9 @@ window.__ModuleLoader__.load({
|
|
|
19700
19758
|
const runSetup = async () => {
|
|
19701
19759
|
setSetupBusy(true);
|
|
19702
19760
|
setSetupReport(null);
|
|
19703
|
-
setNote({ ok: true, text: weT('
|
|
19761
|
+
setNote({ ok: true, text: weT('正在准备录音组件、检测麦克风、预热语音识别与合成…(首次会下载)') });
|
|
19762
|
+
// setup 是长请求(ffmpeg 70MB / ASR 模型):并行轮询 diagnose 把 ffmpeg 进度显示出来。
|
|
19763
|
+
const progressTimer = setInterval(() => { void loadFfmpeg(); }, 800);
|
|
19704
19764
|
try {
|
|
19705
19765
|
const resp = await apiPostJson('/pet-chat/voice/setup', {
|
|
19706
19766
|
sapiEnabled: voiceCfg.sapiEnabled === true,
|
|
@@ -19708,17 +19768,22 @@ window.__ModuleLoader__.load({
|
|
|
19708
19768
|
}, { parse: 'always' });
|
|
19709
19769
|
const doc = unwrapPetChat(resp);
|
|
19710
19770
|
setSetupReport(doc && Array.isArray(doc.steps) ? doc : null);
|
|
19771
|
+
if (doc && doc.ffmpeg) setFfmpeg(doc.ffmpeg);
|
|
19711
19772
|
if (doc && doc.voice) {
|
|
19712
19773
|
setDraft((prev) => ({ ...prev, voice: Object.assign({}, prev.voice || {}, { name: doc.voice, sapiEnabled: voiceCfg.sapiEnabled === true }) }));
|
|
19713
19774
|
}
|
|
19714
19775
|
await loadVoices();
|
|
19776
|
+
await loadFfmpeg();
|
|
19715
19777
|
setNote({
|
|
19716
19778
|
ok: Boolean(doc && doc.ok),
|
|
19717
|
-
text: doc && doc.ok ? weT('一键启用完成:能听、能说。') : weT('
|
|
19779
|
+
text: doc && doc.ok ? weT('一键启用完成:能听、能说。') : weT('一键启用有未通过项,见下面的报告。'),
|
|
19718
19780
|
});
|
|
19719
19781
|
} catch (e) {
|
|
19720
19782
|
setNote({ ok: false, text: weT('一键启用失败:{msg}', { msg: (e && e.message) || '' }) });
|
|
19721
|
-
} finally {
|
|
19783
|
+
} finally {
|
|
19784
|
+
clearInterval(progressTimer);
|
|
19785
|
+
setSetupBusy(false);
|
|
19786
|
+
}
|
|
19722
19787
|
};
|
|
19723
19788
|
|
|
19724
19789
|
const row = (key, label, node) => React.createElement('label', {
|
|
@@ -19738,6 +19803,27 @@ window.__ModuleLoader__.load({
|
|
|
19738
19803
|
|| ['openai', 'azure', 'elevenlabs'].includes(v.engine));
|
|
19739
19804
|
|
|
19740
19805
|
const child = [];
|
|
19806
|
+
const ffmpegPhase = (ffmpeg && ffmpeg.phase) || 'idle';
|
|
19807
|
+
const ffmpegPct = Math.max(0, Math.min(100, Number(ffmpeg && ffmpeg.percent) || 0));
|
|
19808
|
+
const ffmpegReady = ffmpegPhase === 'ready' || Boolean(ffmpeg && ffmpeg.ok === true);
|
|
19809
|
+
const ffmpegErr = String((ffmpeg && ffmpeg.error) || '').slice(0, 80) || '未知错误';
|
|
19810
|
+
const ffmpegText = ffmpegReady
|
|
19811
|
+
? weT('语音运行环境:ffmpeg 已就绪')
|
|
19812
|
+
: (ffmpegPhase === 'failed'
|
|
19813
|
+
? weT('语音运行环境:准备失败({err})', { err: ffmpegErr })
|
|
19814
|
+
: (ffmpegPhase === 'preparing' || ffmpegPhase === 'download'
|
|
19815
|
+
? weT('正在准备录音组件 {pct}%', { pct: ffmpegPct })
|
|
19816
|
+
: weT('语音运行环境:尚未准备')));
|
|
19817
|
+
const ffmpegRow = (key) => React.createElement('div', {
|
|
19818
|
+
key, className: 'we-picker__hint', style: { display: 'flex', gap: '6px', alignItems: 'center', margin: '4px 0', color: ffmpegPhase === 'failed' ? '#f87171' : undefined },
|
|
19819
|
+
},
|
|
19820
|
+
React.createElement('span', null, ffmpegText),
|
|
19821
|
+
!ffmpegReady && !setupBusy
|
|
19822
|
+
? React.createElement('button', {
|
|
19823
|
+
type: 'button', className: 'we-picker__btn', style: { fontSize: '11px', padding: '1px 8px' },
|
|
19824
|
+
onClick: runSetup,
|
|
19825
|
+
}, weT('重试'))
|
|
19826
|
+
: null);
|
|
19741
19827
|
child.push(React.createElement('div', { key: 'title', style: { fontWeight: 600, margin: '14px 0 4px', fontSize: '13px' } }, weT('智能大肥鱼')));
|
|
19742
19828
|
child.push(React.createElement('div', { key: 'hint', className: 'we-picker__hint', style: { margin: '0 0 6px' } },
|
|
19743
19829
|
weT('填 Key、起名字、选音色,再决定要不要朗读。主动搭话与记忆是固定策略;停止/恢复对它说一声就行。')));
|
|
@@ -19782,6 +19868,7 @@ window.__ModuleLoader__.load({
|
|
|
19782
19868
|
})),
|
|
19783
19869
|
React.createElement('div', { key: 'assistant-note', className: 'we-picker__hint', style: { margin: '6px 0' } },
|
|
19784
19870
|
weT('填完 Key 后去「朗读与音色」点一次「一键启用语音」,麦克风、音色和识别模型会自动准备好。')),
|
|
19871
|
+
ffmpegRow('ffmpeg-env'),
|
|
19785
19872
|
));
|
|
19786
19873
|
child.push(React.createElement(MicTestBlock, { key: 'mic-test' }));
|
|
19787
19874
|
}
|
|
@@ -19806,19 +19893,29 @@ window.__ModuleLoader__.load({
|
|
|
19806
19893
|
},
|
|
19807
19894
|
React.createElement('input', {
|
|
19808
19895
|
type: 'checkbox', checked: continuousOn, disabled: busy,
|
|
19809
|
-
onChange: (e) =>
|
|
19896
|
+
onChange: (e) => {
|
|
19897
|
+
const on = e.target.checked;
|
|
19898
|
+
setVoiceCfg((prev) => ({ ...prev, continuous: on }));
|
|
19899
|
+
publishContinuous(on);
|
|
19900
|
+
try {
|
|
19901
|
+
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function') {
|
|
19902
|
+
window.dispatchEvent(new CustomEvent('we-pet-continuous', { detail: { action: 'set', enabled: on } }));
|
|
19903
|
+
}
|
|
19904
|
+
} catch { /* ignore */ }
|
|
19905
|
+
},
|
|
19810
19906
|
}),
|
|
19811
19907
|
weT('☑ 连续对话')));
|
|
19812
19908
|
voicePage.push(React.createElement('div', {
|
|
19813
19909
|
key: 'continuous-hint', className: 'we-picker__hint', style: { margin: '0 0 6px' },
|
|
19814
19910
|
}, weT('默认开启:朗读结束后约 0.6 秒自动开麦;静默 2 轮或连续 8 轮自动退出,点桌宠可暂停。')));
|
|
19815
19911
|
|
|
19912
|
+
voicePage.push(ffmpegRow('ffmpeg-voice'));
|
|
19816
19913
|
voicePage.push(React.createElement('div', { key: 'setup', style: { display: 'flex', gap: '8px', alignItems: 'center', margin: '6px 0' } },
|
|
19817
19914
|
React.createElement('button', {
|
|
19818
19915
|
type: 'button', className: 'we-picker__btn', disabled: setupBusy || busy, onClick: runSetup,
|
|
19819
19916
|
}, setupBusy ? weT('正在启用…') : weT('一键启用语音')),
|
|
19820
19917
|
React.createElement('span', { className: 'we-picker__hint', style: { fontSize: '11px' } },
|
|
19821
|
-
weT('
|
|
19918
|
+
weT('自动准备 ffmpeg、选麦克风、选音色、预热 ASR/TTS。'))));
|
|
19822
19919
|
if (setupReport && Array.isArray(setupReport.steps)) {
|
|
19823
19920
|
voicePage.push(React.createElement('div', {
|
|
19824
19921
|
key: 'setup-report', style: {
|
|
@@ -20540,6 +20637,15 @@ window.__ModuleLoader__.load({
|
|
|
20540
20637
|
let walkLeft = 0;
|
|
20541
20638
|
/** 单击轮换到第几号轨道。 */
|
|
20542
20639
|
let clickIdx = 0;
|
|
20640
|
+
/** pre.63:右键菜单的连续对话状态(由 pet-chat 通过事件同步)。 */
|
|
20641
|
+
let continuousEnabled = true;
|
|
20642
|
+
let continuousPaused = false;
|
|
20643
|
+
const onContinuousState = (event) => {
|
|
20644
|
+
const detail = (event && event.detail) || {};
|
|
20645
|
+
if (typeof detail.enabled === 'boolean') continuousEnabled = detail.enabled;
|
|
20646
|
+
if (typeof detail.paused === 'boolean') continuousPaused = detail.paused;
|
|
20647
|
+
if (menu) closeMenu();
|
|
20648
|
+
};
|
|
20543
20649
|
|
|
20544
20650
|
let scaleCur = Number(scale) > 0 ? Number(scale) : 1;
|
|
20545
20651
|
const cw = Math.max(1, Number(pet.cell && pet.cell.width) || 192);
|
|
@@ -20759,6 +20865,9 @@ window.__ModuleLoader__.load({
|
|
|
20759
20865
|
* 菜单条目 = 9 条动作各一条(点一下立刻试演)+ 声音/大小/复位/隐藏。
|
|
20760
20866
|
*/
|
|
20761
20867
|
let menu = null;
|
|
20868
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
20869
|
+
window.addEventListener("we-pet-continuous-state", onContinuousState);
|
|
20870
|
+
}
|
|
20762
20871
|
function closeMenu() {
|
|
20763
20872
|
if (menu && menu.parentNode) menu.parentNode.removeChild(menu);
|
|
20764
20873
|
menu = null;
|
|
@@ -20801,6 +20910,33 @@ window.__ModuleLoader__.load({
|
|
|
20801
20910
|
const hr = document.createElement("div");
|
|
20802
20911
|
hr.style.cssText = "height:1px;margin:6px 0;background:rgba(255,255,255,0.14)";
|
|
20803
20912
|
menu.appendChild(hr);
|
|
20913
|
+
// pre.63:连续对话(与设置页 voice.continuous 同一字段,由 pet-chat 同步状态/持久化)
|
|
20914
|
+
const sendContinuous = (action) => {
|
|
20915
|
+
try {
|
|
20916
|
+
window.dispatchEvent(new CustomEvent("we-pet-continuous", { detail: { action } }));
|
|
20917
|
+
} catch { /* 没装 pet-chat 时无副作用 */ }
|
|
20918
|
+
};
|
|
20919
|
+
menu.appendChild(buildMenuItem(
|
|
20920
|
+
(continuousEnabled ? "☑ " : "☐ ") + weT("连续对话"),
|
|
20921
|
+
() => {
|
|
20922
|
+
continuousEnabled = !continuousEnabled;
|
|
20923
|
+
sendContinuous("toggle");
|
|
20924
|
+
closeMenu();
|
|
20925
|
+
},
|
|
20926
|
+
));
|
|
20927
|
+
if (continuousEnabled) {
|
|
20928
|
+
menu.appendChild(buildMenuItem(
|
|
20929
|
+
continuousPaused ? weT("继续听") : weT("暂停听"),
|
|
20930
|
+
() => {
|
|
20931
|
+
sendContinuous(continuousPaused ? "resume" : "pause");
|
|
20932
|
+
continuousPaused = !continuousPaused;
|
|
20933
|
+
closeMenu();
|
|
20934
|
+
},
|
|
20935
|
+
));
|
|
20936
|
+
}
|
|
20937
|
+
const hr2 = document.createElement("div");
|
|
20938
|
+
hr2.style.cssText = "height:1px;margin:6px 0;background:rgba(255,255,255,0.14)";
|
|
20939
|
+
menu.appendChild(hr2);
|
|
20804
20940
|
// 「对话」:打开桌宠对话的输入条(由 pet-chat 特性监听该事件;没装该特性时点了无副作用)
|
|
20805
20941
|
menu.appendChild(buildMenuItem(weT("对话"), () => {
|
|
20806
20942
|
try { window.dispatchEvent(new CustomEvent("we-pet-talk")); } catch { /* ignore */ }
|
|
@@ -20870,6 +21006,7 @@ window.__ModuleLoader__.load({
|
|
|
20870
21006
|
if (typeof window !== "undefined") {
|
|
20871
21007
|
window.removeEventListener("pointermove", onPointerMove);
|
|
20872
21008
|
window.removeEventListener("pointerup", onPointerUp);
|
|
21009
|
+
window.removeEventListener("we-pet-continuous-state", onContinuousState);
|
|
20873
21010
|
}
|
|
20874
21011
|
}
|
|
20875
21012
|
|
|
@@ -22223,15 +22360,13 @@ window.__ModuleLoader__.load({
|
|
|
22223
22360
|
|
|
22224
22361
|
const CSS = [
|
|
22225
22362
|
'.we-pet-wrap{position:fixed;z-index:9999;display:flex;flex-direction:column;align-items:center;gap:6px;max-width:320px;pointer-events:none;transform-origin:50% 100%;}',
|
|
22226
|
-
// 回答气泡:半透明深色底 + 轻描边 + 14–16px
|
|
22227
|
-
|
|
22228
|
-
'.we-pet-bubble{position:relative;max-width:320px;padding:10px 12px;border-radius:15px;background:rgba(20,20,24,.82);color:#f2f2f5;font-size:13px;line-height:1.5;border:1px solid rgba(255,255,255,.14);box-shadow:0 8px 24px rgba(0,0,0,.28);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);white-space:pre-wrap;word-break:break-word;opacity:0;transition:opacity 150ms ease;pointer-events:auto;overflow:visible;}',
|
|
22229
|
-
'.we-pet-bubble-text{max-height:160px;overflow-y:auto;padding-right:3px;scrollbar-width:thin;}',
|
|
22363
|
+
// 回答气泡:半透明深色底 + 轻描边 + 14–16px 圆角;长回答 160px 内滚动。
|
|
22364
|
+
'.we-pet-bubble{position:relative;max-width:320px;max-height:160px;overflow-y:auto;padding:10px 12px;border-radius:15px;background:rgba(20,20,24,.82);color:#f2f2f5;font-size:13px;line-height:1.5;border:1px solid rgba(255,255,255,.14);box-shadow:0 8px 24px rgba(0,0,0,.28);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);white-space:pre-wrap;word-break:break-word;opacity:0;transition:opacity 150ms ease;pointer-events:auto;scrollbar-width:thin;}',
|
|
22230
22365
|
'.we-pet-bubble[data-visible="1"]{opacity:1;}',
|
|
22231
22366
|
// 小尾巴指向桌宠(在气泡底部中央;不挡脸)。
|
|
22232
22367
|
'.we-pet-bubble::after{content:"";position:absolute;left:50%;bottom:-6px;width:12px;height:12px;background:inherit;border-right:1px solid rgba(255,255,255,.14);border-bottom:1px solid rgba(255,255,255,.14);transform:translateX(-50%) rotate(45deg);}',
|
|
22233
|
-
'.we-pet-bubble
|
|
22234
|
-
'.we-pet-bubble
|
|
22368
|
+
'.we-pet-bubble::-webkit-scrollbar{width:4px;}',
|
|
22369
|
+
'.we-pet-bubble::-webkit-scrollbar-thumb{background:rgba(255,255,255,.22);border-radius:2px;}',
|
|
22235
22370
|
// 状态条:细、独立、可点、3–5 秒淡出。
|
|
22236
22371
|
'.we-pet-status{max-width:320px;padding:5px 10px;border-radius:999px;background:rgba(20,20,24,.74);color:#ececf2;font-size:12px;line-height:1.4;border:1px solid rgba(255,255,255,.12);box-shadow:0 4px 14px rgba(0,0,0,.22);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);display:flex;align-items:center;gap:6px;opacity:0;transition:opacity 150ms ease;pointer-events:auto;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}',
|
|
22237
22372
|
'.we-pet-status[data-visible="1"]{opacity:1;}',
|
|
@@ -22457,7 +22592,7 @@ window.__ModuleLoader__.load({
|
|
|
22457
22592
|
return;
|
|
22458
22593
|
}
|
|
22459
22594
|
const labels = {
|
|
22460
|
-
listen: '🎤 ' + (continuous ? tr('
|
|
22595
|
+
listen: '🎤 ' + (continuous ? tr('连续对话中 · 右键可关闭') : tr('在听')),
|
|
22461
22596
|
think: '💭 ' + tr('在想'),
|
|
22462
22597
|
speak: '🔊 ' + tr('在说'),
|
|
22463
22598
|
};
|
|
@@ -22479,11 +22614,11 @@ window.__ModuleLoader__.load({
|
|
|
22479
22614
|
|
|
22480
22615
|
function isVisible() { return visible; }
|
|
22481
22616
|
|
|
22482
|
-
/**
|
|
22617
|
+
/** 连续对话模式:把「在听」换成一语中的状态条,提醒右键可关闭。 */
|
|
22483
22618
|
function setContinuous(active) {
|
|
22484
22619
|
continuous = active === true;
|
|
22485
22620
|
if (continuous && statusEl && statusEl.dataset && String(statusEl.dataset.state || '') === 'listen') {
|
|
22486
|
-
statusEl.textContent = '🎤 ' + tr('
|
|
22621
|
+
statusEl.textContent = '🎤 ' + tr('连续对话中 · 右键可关闭');
|
|
22487
22622
|
}
|
|
22488
22623
|
}
|
|
22489
22624
|
|
|
@@ -23019,6 +23154,7 @@ window.__ModuleLoader__.load({
|
|
|
23019
23154
|
} catch { /* 读不到就用默认(不静音) */ }
|
|
23020
23155
|
petChatContinuousEnabled = petChatVoice.continuous !== false;
|
|
23021
23156
|
if (petChatContinuousEnabled === false) petChatContinuousStop('', true);
|
|
23157
|
+
petChatPublishContinuousState();
|
|
23022
23158
|
return petChatVoice;
|
|
23023
23159
|
}
|
|
23024
23160
|
|
|
@@ -23041,6 +23177,21 @@ window.__ModuleLoader__.load({
|
|
|
23041
23177
|
}
|
|
23042
23178
|
}
|
|
23043
23179
|
|
|
23180
|
+
/** pre.63:把连续对话状态推给右键菜单(pet-layer 监听)。 */
|
|
23181
|
+
function petChatPublishContinuousState() {
|
|
23182
|
+
try {
|
|
23183
|
+
if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function') return;
|
|
23184
|
+
window.dispatchEvent(new CustomEvent('we-pet-continuous-state', {
|
|
23185
|
+
detail: {
|
|
23186
|
+
enabled: petChatContinuousEnabled === true,
|
|
23187
|
+
active: petChatContinuousActive === true,
|
|
23188
|
+
paused: petChatContinuousPaused === true,
|
|
23189
|
+
rounds: petChatContinuousRounds,
|
|
23190
|
+
},
|
|
23191
|
+
}));
|
|
23192
|
+
} catch { /* 右键菜单是增强,事件失败不影响对话 */ }
|
|
23193
|
+
}
|
|
23194
|
+
|
|
23044
23195
|
function petChatContinuousStart() {
|
|
23045
23196
|
if (petChatContinuousEnabled !== true) return false;
|
|
23046
23197
|
petChatContinuousClearTimer();
|
|
@@ -23048,6 +23199,7 @@ window.__ModuleLoader__.load({
|
|
|
23048
23199
|
petChatContinuousPaused = false;
|
|
23049
23200
|
if (petChatContinuousRounds === 0) petChatContinuousSilent = 0;
|
|
23050
23201
|
petBubble.setContinuous(true);
|
|
23202
|
+
petChatPublishContinuousState();
|
|
23051
23203
|
return true;
|
|
23052
23204
|
}
|
|
23053
23205
|
|
|
@@ -23058,9 +23210,59 @@ window.__ModuleLoader__.load({
|
|
|
23058
23210
|
petChatContinuousRounds = 0;
|
|
23059
23211
|
petChatContinuousSilent = 0;
|
|
23060
23212
|
petBubble.setContinuous(false);
|
|
23213
|
+
petChatPublishContinuousState();
|
|
23061
23214
|
if (reason && silent !== true) petBubble.status('info', reason, { delay: 3500 });
|
|
23062
23215
|
}
|
|
23063
23216
|
|
|
23217
|
+
/** 右键「暂停听」:立即停掉自动续听与当前录音,但保留 enabled 字段。 */
|
|
23218
|
+
function petChatContinuousPause(reason) {
|
|
23219
|
+
if (!petChatContinuousEnabled) return false;
|
|
23220
|
+
petChatVoiceAbort = true;
|
|
23221
|
+
try { petVoiceIn.stop(); } catch { /* ignore */ }
|
|
23222
|
+
petChatContinuousStop(reason || weT('⏸ 连续对话已暂停(点桌宠继续)'), false);
|
|
23223
|
+
return true;
|
|
23224
|
+
}
|
|
23225
|
+
|
|
23226
|
+
/** 右键「继续听」:恢复免点击循环,并立刻开下一轮(不用再点桌宠)。 */
|
|
23227
|
+
function petChatContinuousResume() {
|
|
23228
|
+
if (!petChatContinuousEnabled) return false;
|
|
23229
|
+
petChatVoiceAbort = false;
|
|
23230
|
+
petChatContinuousPaused = false;
|
|
23231
|
+
petChatContinuousStart();
|
|
23232
|
+
petChatContinuousArm(450);
|
|
23233
|
+
return true;
|
|
23234
|
+
}
|
|
23235
|
+
|
|
23236
|
+
/** 开关(菜单/设置页共用 voice.continuous):持久化 + 广播给菜单。 */
|
|
23237
|
+
function petChatSetContinuousEnabled(enabled) {
|
|
23238
|
+
const next = enabled === true;
|
|
23239
|
+
petChatContinuousEnabled = next;
|
|
23240
|
+
if (!next) {
|
|
23241
|
+
petChatVoiceAbort = true;
|
|
23242
|
+
try { petVoiceIn.stop(); } catch { /* ignore */ }
|
|
23243
|
+
petChatContinuousStop('', true);
|
|
23244
|
+
} else {
|
|
23245
|
+
petChatContinuousPaused = false;
|
|
23246
|
+
petChatVoiceAbort = false;
|
|
23247
|
+
petChatPublishContinuousState();
|
|
23248
|
+
}
|
|
23249
|
+
try {
|
|
23250
|
+
void apiPostJson('/pet-chat/voice/config', { continuous: next }, { parse: 'always' })
|
|
23251
|
+
.then(() => petChatRefreshVoice())
|
|
23252
|
+
.catch(() => { /* 设置页下次保存会再写 */ });
|
|
23253
|
+
} catch { /* ignore */ }
|
|
23254
|
+
return next;
|
|
23255
|
+
}
|
|
23256
|
+
|
|
23257
|
+
/** 右键菜单事件:toggle / pause / resume。 */
|
|
23258
|
+
function petChatOnContinuousCommand(event) {
|
|
23259
|
+
const action = String((event && event.detail && event.detail.action) || '');
|
|
23260
|
+
if (action === 'toggle') petChatSetContinuousEnabled(!petChatContinuousEnabled);
|
|
23261
|
+
else if (action === 'set') petChatSetContinuousEnabled(event.detail.enabled === true);
|
|
23262
|
+
else if (action === 'pause') petChatContinuousPause();
|
|
23263
|
+
else if (action === 'resume') petChatContinuousResume();
|
|
23264
|
+
}
|
|
23265
|
+
|
|
23064
23266
|
/** 朗读结束或一次静默后,延迟 0.65s 自动开麦。 */
|
|
23065
23267
|
function petChatContinuousArm(delayMs) {
|
|
23066
23268
|
if (!petChatContinuousEnabled || !petChatContinuousActive || petChatContinuousPaused) return;
|
|
@@ -23142,8 +23344,21 @@ window.__ModuleLoader__.load({
|
|
|
23142
23344
|
// barge-in:**一开录就先停朗读**(判据 verify-voice-tts 断言这个顺序)
|
|
23143
23345
|
onBeforeRecord: () => { petSpeakStop(); },
|
|
23144
23346
|
postRecord: async () => {
|
|
23145
|
-
|
|
23146
|
-
|
|
23347
|
+
// pre.62:ffmpeg 不在包里,首次点麦可能在下载。宿主回 ffmpeg-preparing+percent;
|
|
23348
|
+
// 这里在状态条显示进度并自动重试 /record(下载在宿主后台继续),不显示“没听到声音”。
|
|
23349
|
+
for (let attempt = 0; attempt < 180; attempt += 1) {
|
|
23350
|
+
const res = await apiPostJson('/pet-chat/record', { language: 'zh' }, { parse: 'always' });
|
|
23351
|
+
const doc = (res && res.data) || {};
|
|
23352
|
+
if (doc.code === 'ffmpeg-preparing') {
|
|
23353
|
+
const pct = Math.max(0, Math.min(100, Number(doc.percent) || 0));
|
|
23354
|
+
petBubble.status('info', weT('正在准备录音组件 {pct}%', { pct }), { delay: 0 });
|
|
23355
|
+
await new Promise((resolve) => { setTimeout(resolve, 1000); });
|
|
23356
|
+
continue;
|
|
23357
|
+
}
|
|
23358
|
+
petBubble.hideStatus(0);
|
|
23359
|
+
return doc;
|
|
23360
|
+
}
|
|
23361
|
+
return { ok: false, code: 'ffmpeg-preparing', hint: weT('录音组件还在准备,稍后再点我') };
|
|
23147
23362
|
},
|
|
23148
23363
|
postChat: async (text, onState) => {
|
|
23149
23364
|
if (petChatVoiceAbort) {
|
|
@@ -23255,6 +23470,7 @@ window.__ModuleLoader__.load({
|
|
|
23255
23470
|
}
|
|
23256
23471
|
petChatContinuousRounds += 1;
|
|
23257
23472
|
petChatContinuousSilent = 0;
|
|
23473
|
+
petChatPublishContinuousState();
|
|
23258
23474
|
if (!queuedSpeech) petChatContinuousArm();
|
|
23259
23475
|
}
|
|
23260
23476
|
// 没有任何一句进入朗读(静音 / 合成不可用)⇒ 沿用旧行为:整段文字 3 秒后淡出。
|
|
@@ -23270,6 +23486,8 @@ window.__ModuleLoader__.load({
|
|
|
23270
23486
|
'no-signal': '麦克风没收到声音:检查静音或输入设备',
|
|
23271
23487
|
'too-quiet': '太小声了,离麦克风近一点(30–50cm)再说一次',
|
|
23272
23488
|
'ffmpeg-missing': '缺少 ffmpeg,先打字吧',
|
|
23489
|
+
'ffmpeg-preparing': '录音组件还在准备,稍后再点我',
|
|
23490
|
+
'ffmpeg-failed': '录音组件准备失败,去「智能大肥鱼 → 朗读与音色」点重试',
|
|
23273
23491
|
'unsupported-platform': '这个系统不支持桌面录音,用浏览器打开 DSH 才能语音',
|
|
23274
23492
|
'asr-not-ready': '语音模型还没下载,我来准备一下…',
|
|
23275
23493
|
unclear: '没听清,再说一次或直接打字',
|
|
@@ -23354,7 +23572,7 @@ window.__ModuleLoader__.load({
|
|
|
23354
23572
|
const seq = ++petChatWakeSeq;
|
|
23355
23573
|
if (petChatContinuousActive || petChatContinuousTimer != null) {
|
|
23356
23574
|
petChatVoiceAbort = true;
|
|
23357
|
-
petChatContinuousStop(weT('
|
|
23575
|
+
petChatContinuousStop(weT('⏸ 连续对话已暂停(点桌宠继续)'), false);
|
|
23358
23576
|
petBubble.hide(0);
|
|
23359
23577
|
petBubble.hideStatus(0);
|
|
23360
23578
|
petVoiceIn.stop();
|
|
@@ -23449,9 +23667,20 @@ window.__ModuleLoader__.load({
|
|
|
23449
23667
|
|
|
23450
23668
|
window.addEventListener('we-pet-talk', onTalkEvent);
|
|
23451
23669
|
window.addEventListener('we-pet-speak', onSpeakEvent);
|
|
23670
|
+
// pre.63:右键菜单的连续对话开关/暂停/继续(与设置页共用 voice.continuous)。
|
|
23671
|
+
const onContinuousEvent = (event) => { petChatOnContinuousCommand(event); };
|
|
23672
|
+
window.addEventListener('we-pet-continuous', onContinuousEvent);
|
|
23673
|
+
// 页面隐藏:自动暂停连续对话(不偷偷在后台开麦)。
|
|
23674
|
+
const onVisibility = () => {
|
|
23675
|
+
if (typeof document === 'undefined' || document.visibilityState !== 'hidden') return;
|
|
23676
|
+
if (petChatContinuousActive && !petChatContinuousPaused) {
|
|
23677
|
+
petChatContinuousPause(weT('页面隐藏,连续对话已暂停'));
|
|
23678
|
+
}
|
|
23679
|
+
};
|
|
23680
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
23452
23681
|
document.addEventListener('click', onDocumentClick, true);
|
|
23453
23682
|
document.addEventListener('keydown', onKeyDown, true);
|
|
23454
|
-
void petChatRefreshVoice();
|
|
23683
|
+
void petChatRefreshVoice().then(() => petChatPublishContinuousState()).catch(() => {});
|
|
23455
23684
|
petChatEventsStart();
|
|
23456
23685
|
// 对外通道:`speak(text)` 供待办/提醒直接调用(不打开任何窗口)
|
|
23457
23686
|
try {
|
|
@@ -23465,8 +23694,10 @@ window.__ModuleLoader__.load({
|
|
|
23465
23694
|
return () => {
|
|
23466
23695
|
window.removeEventListener('we-pet-talk', onTalkEvent);
|
|
23467
23696
|
window.removeEventListener('we-pet-speak', onSpeakEvent);
|
|
23697
|
+
window.removeEventListener('we-pet-continuous', onContinuousEvent);
|
|
23468
23698
|
document.removeEventListener('click', onDocumentClick, true);
|
|
23469
23699
|
document.removeEventListener('keydown', onKeyDown, true);
|
|
23700
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
23470
23701
|
petChatEventsStop();
|
|
23471
23702
|
petSpeakStop();
|
|
23472
23703
|
try { if (window.__dshFoliaPet) delete window.__dshFoliaPet; } catch { /* ignore */ }
|
package/lib/index.js
CHANGED
|
@@ -308,6 +308,9 @@ export function apply(ctx) {
|
|
|
308
308
|
// 会抛 "cannot get property … without inject",让整个插件加载失败(POSTMORTEM-LOAD-CRASH)。
|
|
309
309
|
// 静态扫描判据:test/verify-ctx-access.mjs;加载冒烟:test/verify-entry-load.mjs。
|
|
310
310
|
speechToText: typeof ctx.get === 'function' ? ctx.get('speechToText') : undefined,
|
|
311
|
+
// pre.62:语音链的 ffmpeg 供给(首次使用懒下载;/record 先看进度,不等 70MB)。
|
|
312
|
+
ffmpegEnsure: hostKernel.transcodeKit.ensureFfmpeg,
|
|
313
|
+
ffmpegStatus: hostKernel.transcodeKit.ffmpegStatus,
|
|
311
314
|
});
|
|
312
315
|
|
|
313
316
|
// 启动预热(有意不阻塞):站点清单与模块索引各拉一次,让第一次打开面板不冷。
|