dsh-folia 4.26.0-pre.13 → 4.26.0-pre.14
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 +44 -1
- package/lib/routes/pet-chat.js +63 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -20705,6 +20705,44 @@ window.__ModuleLoader__.load({
|
|
|
20705
20705
|
},
|
|
20706
20706
|
});
|
|
20707
20707
|
|
|
20708
|
+
/**
|
|
20709
|
+
* 语音模型(SenseVoice)自举:调宿主 /pet-chat/asr(它会 speechToText.prepare),
|
|
20710
|
+
* 然后轮询 /pet-chat/asr 把下载进度显示在气泡里。
|
|
20711
|
+
* 这样用户装完插件直接说话就行,不需要去 DSH 设置里找「语音输入」开关。
|
|
20712
|
+
*/
|
|
20713
|
+
async function ensureAsrReady() {
|
|
20714
|
+
petBubble.setState('think');
|
|
20715
|
+
try {
|
|
20716
|
+
await apiPostJson('/pet-chat/asr', {}, { parse: 'always' });
|
|
20717
|
+
} catch { /* 触发失败也要继续轮询看状态 */ }
|
|
20718
|
+
for (let i = 0; i < 240; i += 1) {
|
|
20719
|
+
await new Promise((resolve) => { setTimeout(resolve, 1500); });
|
|
20720
|
+
const resp = await apiJson('/pet-chat/asr', { parse: 'always' }).catch(() => null);
|
|
20721
|
+
const doc = (resp && resp.data) || {};
|
|
20722
|
+
if (doc.ready) {
|
|
20723
|
+
petBubble.show('语音准备好了,点我再说一次');
|
|
20724
|
+
petBubble.hide(3000);
|
|
20725
|
+
return;
|
|
20726
|
+
}
|
|
20727
|
+
if (doc.available === false) {
|
|
20728
|
+
petBubble.show('这个 DSH 版本没有语音转写服务,先打字吧');
|
|
20729
|
+
petBubble.hide(3000);
|
|
20730
|
+
return;
|
|
20731
|
+
}
|
|
20732
|
+
if (doc.phase === 'failed') {
|
|
20733
|
+
petBubble.show('语音模型下载失败,稍后再点我试试');
|
|
20734
|
+
petBubble.hide(3000);
|
|
20735
|
+
return;
|
|
20736
|
+
}
|
|
20737
|
+
const pct = doc.totalBytes > 0 && doc.completedBytes >= 0
|
|
20738
|
+
? Math.max(0, Math.min(100, Math.round((doc.completedBytes / doc.totalBytes) * 100)))
|
|
20739
|
+
: null;
|
|
20740
|
+
petBubble.show(pct === null ? '语音模型准备中…' : `语音模型下载中 ${pct}%`);
|
|
20741
|
+
}
|
|
20742
|
+
petBubble.show('语音模型还没下完,过一会儿再点我');
|
|
20743
|
+
petBubble.hide(3000);
|
|
20744
|
+
}
|
|
20745
|
+
|
|
20708
20746
|
/** 语音输入(v0.1):前端不碰麦克风 —— 宿主用 ffmpeg 录,这里只发请求、收文本。 */
|
|
20709
20747
|
const petVoiceIn = petVoiceInputCreate({
|
|
20710
20748
|
postRecord: async () => {
|
|
@@ -20767,13 +20805,18 @@ window.__ModuleLoader__.load({
|
|
|
20767
20805
|
const map = {
|
|
20768
20806
|
'no-device': '没找到麦克风,先打字吧',
|
|
20769
20807
|
'ffmpeg-missing': '缺少 ffmpeg,先打字吧',
|
|
20770
|
-
'asr-not-ready': '
|
|
20808
|
+
'asr-not-ready': '语音模型还没下载,我来准备一下…',
|
|
20771
20809
|
timeout: '这次没听清,再说一次或直接打字',
|
|
20772
20810
|
'no-speech': '没听到声音,再说一次或直接打字',
|
|
20773
20811
|
network: '网络不太顺,重试或直接打字',
|
|
20774
20812
|
};
|
|
20775
20813
|
const message = map[error && error.code] || '没听清,直接打字也行';
|
|
20776
20814
|
petBubble.show(message);
|
|
20815
|
+
// asr-not-ready:自动触发模型下载并在气泡里显示进度,用户不用去 DSH 设置里找开关
|
|
20816
|
+
if (error && error.code === 'asr-not-ready') {
|
|
20817
|
+
void ensureAsrReady();
|
|
20818
|
+
return;
|
|
20819
|
+
}
|
|
20777
20820
|
petBubble.hide(3000);
|
|
20778
20821
|
petChatOpenTyping({ hint: message });
|
|
20779
20822
|
},
|
package/lib/routes/pet-chat.js
CHANGED
|
@@ -813,6 +813,65 @@ export function registerPetChatRoutes(webServer, c) {
|
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
+
/**
|
|
817
|
+
* GET /pet-chat/asr —— 语音转写模型的就绪状态与下载进度。
|
|
818
|
+
* 读 `speechToText.snapshot()` 里该 provider 的 preparation:
|
|
819
|
+
* phase: unprepared | checking | downloading | loading | waking | ready | failed | standby …
|
|
820
|
+
* downloading 时带 completedBytes / totalBytes。
|
|
821
|
+
*/
|
|
822
|
+
function handleAsrStatus(res) {
|
|
823
|
+
const send = (payload, status = 200) => {
|
|
824
|
+
res.statusCode = status;
|
|
825
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
826
|
+
res.end(JSON.stringify(payload));
|
|
827
|
+
};
|
|
828
|
+
const service = speechToText;
|
|
829
|
+
if (!service || typeof service.snapshot !== 'function') {
|
|
830
|
+
send({ ok: true, available: false, providerId: ASR_PROVIDER_ID, phase: 'unavailable', ready: false });
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
let prep = { phase: 'missing' };
|
|
834
|
+
try {
|
|
835
|
+
const snap = service.snapshot();
|
|
836
|
+
const prov = (snap && Array.isArray(snap.providers) ? snap.providers : [])
|
|
837
|
+
.find((item) => item && item.id === ASR_PROVIDER_ID);
|
|
838
|
+
prep = (prov && prov.preparation) || { phase: 'missing' };
|
|
839
|
+
} catch { /* snapshot 失败按未就绪处理 */ }
|
|
840
|
+
send({
|
|
841
|
+
ok: true,
|
|
842
|
+
available: true,
|
|
843
|
+
providerId: ASR_PROVIDER_ID,
|
|
844
|
+
phase: prep.phase || 'missing',
|
|
845
|
+
completedBytes: typeof prep.completedBytes === 'number' ? prep.completedBytes : null,
|
|
846
|
+
totalBytes: typeof prep.totalBytes === 'number' ? prep.totalBytes : null,
|
|
847
|
+
ready: prep.phase === 'ready',
|
|
848
|
+
message: typeof prep.message === 'string' ? prep.message : null,
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* POST /pet-chat/asr —— 触发模型下载/准备(幂等;已在准备中会 join 同一个任务)。
|
|
854
|
+
* 这样用户装完插件就能用语音,不必去 DSH 设置里找"语音输入"开关。
|
|
855
|
+
*/
|
|
856
|
+
function handleAsrPrepare(res) {
|
|
857
|
+
const send = (payload, status = 200) => {
|
|
858
|
+
res.statusCode = status;
|
|
859
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
860
|
+
res.end(JSON.stringify(payload));
|
|
861
|
+
};
|
|
862
|
+
const service = speechToText;
|
|
863
|
+
if (!service || typeof service.prepare !== 'function') {
|
|
864
|
+
send({ ok: false, code: 'asr-unavailable', hint: '这个 DSH 版本没有提供语音转写服务' });
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
try {
|
|
868
|
+
service.prepare(ASR_PROVIDER_ID);
|
|
869
|
+
send({ ok: true, started: true, providerId: ASR_PROVIDER_ID });
|
|
870
|
+
} catch (error) {
|
|
871
|
+
send({ ok: false, code: 'asr-prepare-failed', hint: String((error && error.message) || error) });
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
816
875
|
async function handleConfigGet(res) {
|
|
817
876
|
const config = readPetChat();
|
|
818
877
|
const key = String(config.apiKey || '');
|
|
@@ -993,6 +1052,10 @@ export function registerPetChatRoutes(webServer, c) {
|
|
|
993
1052
|
if (tail === '/reset' && method === 'POST') { handleReset(res); return; }
|
|
994
1053
|
if (tail === '/transcribe' && method === 'POST') { handleTranscribe(req, res); return; }
|
|
995
1054
|
if (tail === '/record' && method === 'POST') { await handleRecord(req, res); return; }
|
|
1055
|
+
// 语音模型(SenseVoice)自举:用户不需要去 DSH 设置里找开关,
|
|
1056
|
+
// 插件自己触发 preparation 并轮询进度(DSH 的 speechToText.prepare 是公开方法)。
|
|
1057
|
+
if (tail === '/asr' && (method === 'GET' || method === 'HEAD')) { handleAsrStatus(res); return; }
|
|
1058
|
+
if (tail === '/asr' && method === 'POST') { handleAsrPrepare(res); return; }
|
|
996
1059
|
// v0.1「零配置」主动搭话:没有开关,只有内部策略 + 语音指令静默
|
|
997
1060
|
if (tail === '/proactive' && (method === 'GET' || method === 'HEAD')) {
|
|
998
1061
|
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|