dsh-mimo-speak 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +197 -2
- package/README.zh.md +166 -0
- package/cordis.patch.yml +20 -0
- package/icon.svg +6 -0
- package/lib/client.js +3607 -0
- package/lib/client.js.map +1 -0
- package/lib/node/brief.d.ts +23 -0
- package/lib/node/brief.js +110 -0
- package/lib/node/brief.js.map +1 -0
- package/lib/node/client/BundleConfigCard.d.ts +15 -0
- package/lib/node/client/BundleConfigCard.js +22 -0
- package/lib/node/client/BundleConfigCard.js.map +1 -0
- package/lib/node/client/PlayerBar.d.ts +45 -0
- package/lib/node/client/PlayerBar.js +83 -0
- package/lib/node/client/PlayerBar.js.map +1 -0
- package/lib/node/client/SettingsSectionCard.d.ts +14 -0
- package/lib/node/client/SettingsSectionCard.js +19 -0
- package/lib/node/client/SettingsSectionCard.js.map +1 -0
- package/lib/node/client/SpeakAction.d.ts +32 -0
- package/lib/node/client/SpeakAction.js +651 -0
- package/lib/node/client/SpeakAction.js.map +1 -0
- package/lib/node/client/SpeakerIcon.d.ts +11 -0
- package/lib/node/client/SpeakerIcon.js +5 -0
- package/lib/node/client/SpeakerIcon.js.map +1 -0
- package/lib/node/client/TtsSettingsForm.d.ts +27 -0
- package/lib/node/client/TtsSettingsForm.js +164 -0
- package/lib/node/client/TtsSettingsForm.js.map +1 -0
- package/lib/node/client/api.d.ts +89 -0
- package/lib/node/client/api.js +247 -0
- package/lib/node/client/api.js.map +1 -0
- package/lib/node/client/audio-bus.d.ts +29 -0
- package/lib/node/client/audio-bus.js +91 -0
- package/lib/node/client/audio-bus.js.map +1 -0
- package/lib/node/client/chat-text.d.ts +32 -0
- package/lib/node/client/chat-text.js +90 -0
- package/lib/node/client/chat-text.js.map +1 -0
- package/lib/node/client/highlight.d.ts +45 -0
- package/lib/node/client/highlight.js +198 -0
- package/lib/node/client/highlight.js.map +1 -0
- package/lib/node/client/index.d.ts +26 -0
- package/lib/node/client/index.js +89 -0
- package/lib/node/client/index.js.map +1 -0
- package/lib/node/client/locales.d.ts +19 -0
- package/lib/node/client/locales.js +180 -0
- package/lib/node/client/locales.js.map +1 -0
- package/lib/node/client/panel-visibility.d.ts +24 -0
- package/lib/node/client/panel-visibility.js +16 -0
- package/lib/node/client/panel-visibility.js.map +1 -0
- package/lib/node/client/settings-controller.d.ts +116 -0
- package/lib/node/client/settings-controller.js +201 -0
- package/lib/node/client/settings-controller.js.map +1 -0
- package/lib/node/client/settings-registration.d.ts +24 -0
- package/lib/node/client/settings-registration.js +21 -0
- package/lib/node/client/settings-registration.js.map +1 -0
- package/lib/node/client/slots.d.ts +48 -0
- package/lib/node/client/slots.js +15 -0
- package/lib/node/client/slots.js.map +1 -0
- package/lib/node/client/speech-cache.d.ts +59 -0
- package/lib/node/client/speech-cache.js +68 -0
- package/lib/node/client/speech-cache.js.map +1 -0
- package/lib/node/client/split-speech.d.ts +20 -0
- package/lib/node/client/split-speech.js +100 -0
- package/lib/node/client/split-speech.js.map +1 -0
- package/lib/node/client/status.d.ts +28 -0
- package/lib/node/client/status.js +60 -0
- package/lib/node/client/status.js.map +1 -0
- package/lib/node/client/stream-dispose.d.ts +119 -0
- package/lib/node/client/stream-dispose.js +249 -0
- package/lib/node/client/stream-dispose.js.map +1 -0
- package/lib/node/client/styles.d.ts +19 -0
- package/lib/node/client/styles.js +176 -0
- package/lib/node/client/styles.js.map +1 -0
- package/lib/node/client/use-audio-player.d.ts +44 -0
- package/lib/node/client/use-audio-player.js +102 -0
- package/lib/node/client/use-audio-player.js.map +1 -0
- package/lib/node/client/use-audio-queue.d.ts +44 -0
- package/lib/node/client/use-audio-queue.js +151 -0
- package/lib/node/client/use-audio-queue.js.map +1 -0
- package/lib/node/client/use-stream-player.d.ts +41 -0
- package/lib/node/client/use-stream-player.js +60 -0
- package/lib/node/client/use-stream-player.js.map +1 -0
- package/lib/node/edge-tts.d.ts +21 -0
- package/lib/node/edge-tts.js +111 -0
- package/lib/node/edge-tts.js.map +1 -0
- package/lib/node/index.d.ts +97 -0
- package/lib/node/index.js +463 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/normalize.d.ts +30 -0
- package/lib/node/normalize.js +72 -0
- package/lib/node/normalize.js.map +1 -0
- package/lib/node/settings.d.ts +186 -0
- package/lib/node/settings.js +74 -0
- package/lib/node/settings.js.map +1 -0
- package/lib/node/summarize.d.ts +29 -0
- package/lib/node/summarize.js +131 -0
- package/lib/node/summarize.js.map +1 -0
- package/lib/node/tool.d.ts +54 -0
- package/lib/node/tool.js +123 -0
- package/lib/node/tool.js.map +1 -0
- package/lib/node/tts.d.ts +127 -0
- package/lib/node/tts.js +361 -0
- package/lib/node/tts.js.map +1 -0
- package/lib/node/wav.d.ts +32 -0
- package/lib/node/wav.js +63 -0
- package/lib/node/wav.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +122 -4
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MiMo TTS speech synthesis, Host half.
|
|
3
|
+
*
|
|
4
|
+
* The Host answers the browser's synthesis questions (`/api/mimo-speak/status`,
|
|
5
|
+
* `/synthesize`, `/synthesize-stream`, `/test`, `/summary`) and registers the
|
|
6
|
+
* `mimo-tts-say` agent tool that writes WAV files into the session
|
|
7
|
+
* workspace. The API key never leaves the Host — the browser sends text and
|
|
8
|
+
* receives WAV bytes.
|
|
9
|
+
*
|
|
10
|
+
* Settings are ordinary volatile Config fields, so the settings service
|
|
11
|
+
* projects them into the configuration form the browser half renders on its
|
|
12
|
+
* own Plugins-page card (`plugins.bundle.config`); the automatic card is
|
|
13
|
+
* turned off because this plugin contributes that card itself.
|
|
14
|
+
* @module dsh-mimo-speak
|
|
15
|
+
*/
|
|
16
|
+
import { stat } from 'node:fs/promises';
|
|
17
|
+
import z from '@deepseek-ai/schemastery';
|
|
18
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials';
|
|
19
|
+
import { DEFAULT_BASE_URL, DEFAULT_CHUNK_CHARS, DEFAULT_CLONE_MODEL, DEFAULT_CREDENTIAL_REF, DEFAULT_EDGE_VOICE, DEFAULT_FALLBACK_ENGINE, DEFAULT_HIGHLIGHT, DEFAULT_MAX_CHARS, DEFAULT_MODEL, DEFAULT_MUTE_WHILE_RECORDING, DEFAULT_PROGRESS_BAR, DEFAULT_READ_SCOPE, DEFAULT_TIMEOUT_MS, DEFAULT_VOICE, MIMOSPEAK_STATUS_PATH, MIMOSPEAK_SUMMARY_PATH, MIMOSPEAK_SYNTHESIZE_PATH, MIMOSPEAK_SYNTHESIZE_STREAM_PATH, MIMOSPEAK_TEST_PATH, } from "./settings.js";
|
|
20
|
+
import { resolveEngineConfig, streamSpeechPcm, synthesizeSpeech, TtsError, withAbortSignal } from "./tts.js";
|
|
21
|
+
import { synthesizeEdge } from "./edge-tts.js";
|
|
22
|
+
import { summarizeForSpeech } from "./summarize.js";
|
|
23
|
+
import { createSayTool } from "./tool.js";
|
|
24
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
25
|
+
export const name = 'mimo-speak';
|
|
26
|
+
export const Config = z.object({
|
|
27
|
+
apiKeyEnv: z.string().role('credential-ref').default(DEFAULT_CREDENTIAL_REF).volatile(),
|
|
28
|
+
baseUrl: z.string().default(DEFAULT_BASE_URL).volatile(),
|
|
29
|
+
model: z.string().default(DEFAULT_MODEL).volatile(),
|
|
30
|
+
voice: z.string().default(DEFAULT_VOICE).volatile(),
|
|
31
|
+
voiceSamplePath: z.string().volatile(),
|
|
32
|
+
style: z.string().volatile(),
|
|
33
|
+
maxChars: z.number().step(1).min(1).default(DEFAULT_MAX_CHARS).volatile(),
|
|
34
|
+
chunkChars: z.number().step(1).min(20).max(1000).default(DEFAULT_CHUNK_CHARS).volatile(),
|
|
35
|
+
timeoutMs: z.number().step(1).min(1).default(DEFAULT_TIMEOUT_MS).volatile(),
|
|
36
|
+
autoRead: z.boolean().default(false).volatile(),
|
|
37
|
+
fallbackEngine: z.union([z.const('none'), z.const('edge')]).default(DEFAULT_FALLBACK_ENGINE).volatile(),
|
|
38
|
+
edgeVoice: z.string().default(DEFAULT_EDGE_VOICE).volatile(),
|
|
39
|
+
readScope: z.union([z.const('text'), z.const('all'), z.const('smart'), z.const('brief')]).default(DEFAULT_READ_SCOPE).volatile(),
|
|
40
|
+
highlight: z.boolean().default(DEFAULT_HIGHLIGHT).volatile(),
|
|
41
|
+
progressBar: z.boolean().default(DEFAULT_PROGRESS_BAR).volatile(),
|
|
42
|
+
muteWhileRecording: z.boolean().default(DEFAULT_MUTE_WHILE_RECORDING).volatile(),
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Read the whole config as one consistent snapshot at operation start. The
|
|
46
|
+
* credential reference resolves through the host credentials service, so the
|
|
47
|
+
* literal key never lives in a configuration file; an absent service, an
|
|
48
|
+
* unknown reference, or a missing value all resolve to an empty key, which
|
|
49
|
+
* the engine reports as `not-configured`.
|
|
50
|
+
*/
|
|
51
|
+
async function resolveEngineSnapshot(ctx, config) {
|
|
52
|
+
const credentials = ctx.get?.('credentials');
|
|
53
|
+
const ref = (config.apiKeyEnv.get() ?? '').trim();
|
|
54
|
+
let apiKey = '';
|
|
55
|
+
if (credentials !== undefined && ref !== '') {
|
|
56
|
+
try {
|
|
57
|
+
const resolved = await credentials.resolve(credentialRef(ref));
|
|
58
|
+
apiKey = (resolved?.value ?? '').trim();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
apiKey = '';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return resolveEngineConfig({
|
|
65
|
+
apiKey,
|
|
66
|
+
baseUrl: config.baseUrl.get(),
|
|
67
|
+
model: config.model.get(),
|
|
68
|
+
voice: config.voice.get(),
|
|
69
|
+
voiceSamplePath: config.voiceSamplePath.get(),
|
|
70
|
+
style: config.style.get(),
|
|
71
|
+
maxChars: config.maxChars.get(),
|
|
72
|
+
timeoutMs: config.timeoutMs.get(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Model that actually reaches MiMo: the clone model whenever a voice sample is
|
|
77
|
+
* configured, because the default TTS model rejects an `audio.voice` Data URI.
|
|
78
|
+
* @param engine - resolved engine configuration.
|
|
79
|
+
* @returns the model id reported to the browser and the agent tool.
|
|
80
|
+
*/
|
|
81
|
+
function effectiveModelOf(engine) {
|
|
82
|
+
return engine.voiceSamplePath === '' ? engine.model : DEFAULT_CLONE_MODEL;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Host registration: the settings presentation policy, the agent tool, and
|
|
86
|
+
* the Web routes.
|
|
87
|
+
* @param ctx - plugin context; the routes appear when `webServer` and
|
|
88
|
+
* `connection` exist (Web and Desktop GUI compositions).
|
|
89
|
+
* @param config - live volatile settings.
|
|
90
|
+
*/
|
|
91
|
+
export function apply(ctx, config) {
|
|
92
|
+
// This plugin contributes its own Plugins-page configuration card
|
|
93
|
+
// (`plugins.bundle.config`); automatic page generation is off so the
|
|
94
|
+
// namespace does not get a duplicate auto page.
|
|
95
|
+
ctx.inject(['settings'], (child) => {
|
|
96
|
+
child.effect(() => child.settings.configure({ auto: false }, ctx.fiber));
|
|
97
|
+
});
|
|
98
|
+
// Agent tool: text → WAV in the session workspace. Only compositions that
|
|
99
|
+
// expose a `tools` service (chat / agent sessions) get it; the browser half
|
|
100
|
+
// and pure web compositions simply never enter this callback.
|
|
101
|
+
ctx.inject(['tools'], (child) => {
|
|
102
|
+
child.effect(() => {
|
|
103
|
+
const tools = child.tools;
|
|
104
|
+
// 没有 tools 服务(纯 Web 组合)时什么都不注册,但 effect 仍要返回一个清理函数
|
|
105
|
+
if (typeof tools?.register !== 'function')
|
|
106
|
+
return () => { };
|
|
107
|
+
const dispose = tools.register(createSayTool({
|
|
108
|
+
synthesize: async (request) => {
|
|
109
|
+
const engine = await resolveEngineSnapshot(ctx, config);
|
|
110
|
+
const wav = await synthesizeSpeech(engine, request);
|
|
111
|
+
const style = (request.style ?? '').trim() || engine.style;
|
|
112
|
+
const voice = (request.voice ?? '').trim() || engine.voice;
|
|
113
|
+
return { wav, model: effectiveModelOf(engine), style, voice };
|
|
114
|
+
},
|
|
115
|
+
log: message => console.info(message),
|
|
116
|
+
}));
|
|
117
|
+
return () => {
|
|
118
|
+
if (typeof dispose === 'function')
|
|
119
|
+
dispose();
|
|
120
|
+
};
|
|
121
|
+
}, 'dsh-mimo-speak: say tool');
|
|
122
|
+
});
|
|
123
|
+
ctx.inject(['webServer', 'connection'], (child) => {
|
|
124
|
+
const fence = (req, res) => {
|
|
125
|
+
// The configured Host/Origin fence plus browser authentication: an
|
|
126
|
+
// unauthenticated LAN request must not spend the operator's API credits.
|
|
127
|
+
const rejection = child.connection.requestRejection(req);
|
|
128
|
+
if (rejection === undefined)
|
|
129
|
+
return false;
|
|
130
|
+
res.statusCode = rejection;
|
|
131
|
+
res.end();
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
const sendJson = (res, status, body) => {
|
|
135
|
+
const bytes = Buffer.from(JSON.stringify(body), 'utf8');
|
|
136
|
+
res.statusCode = status;
|
|
137
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
138
|
+
res.setHeader('cache-control', 'no-store');
|
|
139
|
+
res.end(bytes);
|
|
140
|
+
};
|
|
141
|
+
const sendError = (res, status, body) => {
|
|
142
|
+
sendJson(res, status, body);
|
|
143
|
+
};
|
|
144
|
+
const errorStatusOf = (failure) => failure.code === 'not-configured' ? 503
|
|
145
|
+
: failure.code === 'bad-request' || failure.code === 'text-too-long' ? 400
|
|
146
|
+
: failure.code === 'timeout' ? 504
|
|
147
|
+
: 502;
|
|
148
|
+
const errorBodyOf = (failure) => ({
|
|
149
|
+
error: {
|
|
150
|
+
code: failure.code,
|
|
151
|
+
message: failure.message,
|
|
152
|
+
...(failure.upstreamStatus === undefined ? {} : { upstreamStatus: failure.upstreamStatus }),
|
|
153
|
+
...(failure.upstreamParam === undefined ? {} : { param: failure.upstreamParam }),
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
const toFailure = (error) => error instanceof TtsError
|
|
157
|
+
? error
|
|
158
|
+
: new TtsError('upstream-error', error instanceof Error ? error.message : String(error));
|
|
159
|
+
const readRequest = (parsed) => {
|
|
160
|
+
const request = parsed;
|
|
161
|
+
if (typeof request.text !== 'string' || request.text.trim() === '')
|
|
162
|
+
return undefined;
|
|
163
|
+
return {
|
|
164
|
+
text: request.text,
|
|
165
|
+
style: typeof request.style === 'string' ? request.style : undefined,
|
|
166
|
+
voice: typeof request.voice === 'string' ? request.voice : undefined,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
/** Try Edge TTS once, when configured, and stream the result as MP3. */
|
|
170
|
+
const tryEdgeFallback = async (res, request, engine, primaryFailure) => {
|
|
171
|
+
if (config.fallbackEngine.get() !== 'edge')
|
|
172
|
+
return false;
|
|
173
|
+
if (primaryFailure.code === 'bad-request' || primaryFailure.code === 'text-too-long')
|
|
174
|
+
return false;
|
|
175
|
+
try {
|
|
176
|
+
const mp3 = await synthesizeEdge(request.text, config.edgeVoice.get(), engine.timeoutMs);
|
|
177
|
+
res.statusCode = 200;
|
|
178
|
+
res.setHeader('content-type', 'audio/mpeg');
|
|
179
|
+
res.setHeader('cache-control', 'no-store');
|
|
180
|
+
res.end(Buffer.from(mp3));
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
catch (edgeError) {
|
|
184
|
+
const edgeFailure = toFailure(edgeError);
|
|
185
|
+
sendError(res, errorStatusOf(edgeFailure), errorBodyOf(new TtsError(edgeFailure.code, `MiMo failed (${primaryFailure.message}); Edge fallback also failed (${edgeFailure.message}).`)));
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
child.effect(() => child.webServer.register({
|
|
190
|
+
kind: 'exact',
|
|
191
|
+
path: MIMOSPEAK_STATUS_PATH,
|
|
192
|
+
handler: (req, res) => {
|
|
193
|
+
if (fence(req, res))
|
|
194
|
+
return;
|
|
195
|
+
if (req.method !== 'GET') {
|
|
196
|
+
sendError(res, 405, { error: { code: 'bad-request', message: 'GET only.' } });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
void (async () => {
|
|
200
|
+
const engine = await resolveEngineSnapshot(ctx, config);
|
|
201
|
+
const hasVoiceSample = engine.voiceSamplePath !== ''
|
|
202
|
+
? await stat(engine.voiceSamplePath).then(value => value.isFile(), () => false)
|
|
203
|
+
: false;
|
|
204
|
+
const status = {
|
|
205
|
+
configured: engine.apiKey !== '',
|
|
206
|
+
model: effectiveModelOf(engine),
|
|
207
|
+
voice: engine.voice,
|
|
208
|
+
hasVoiceSample,
|
|
209
|
+
baseUrl: engine.baseUrl,
|
|
210
|
+
autoRead: config.autoRead.get() === true,
|
|
211
|
+
maxChars: config.maxChars.get(),
|
|
212
|
+
chunkChars: config.chunkChars.get(),
|
|
213
|
+
fallbackEngine: config.fallbackEngine.get(),
|
|
214
|
+
edgeVoice: config.edgeVoice.get() ?? DEFAULT_EDGE_VOICE,
|
|
215
|
+
readScope: config.readScope.get(),
|
|
216
|
+
highlight: config.highlight.get() !== false,
|
|
217
|
+
progressBar: config.progressBar.get() === true,
|
|
218
|
+
muteWhileRecording: config.muteWhileRecording.get() === true,
|
|
219
|
+
};
|
|
220
|
+
sendJson(res, 200, status);
|
|
221
|
+
})();
|
|
222
|
+
},
|
|
223
|
+
}), `dsh-mimo-speak: GET ${MIMOSPEAK_STATUS_PATH}`);
|
|
224
|
+
child.effect(() => child.webServer.register({
|
|
225
|
+
kind: 'exact',
|
|
226
|
+
path: MIMOSPEAK_SYNTHESIZE_PATH,
|
|
227
|
+
handler: (req, res) => {
|
|
228
|
+
if (fence(req, res))
|
|
229
|
+
return;
|
|
230
|
+
if (req.method !== 'POST') {
|
|
231
|
+
sendError(res, 405, { error: { code: 'bad-request', message: 'POST only.' } });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
void (async () => {
|
|
235
|
+
const parsed = await readJsonBody(req);
|
|
236
|
+
if (parsed === undefined) {
|
|
237
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'Request body is not a JSON object.' } });
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const request = readRequest(parsed);
|
|
241
|
+
if (request === undefined) {
|
|
242
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'A non-empty `text` string is required.' } });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const engine = await resolveEngineSnapshot(ctx, config);
|
|
246
|
+
try {
|
|
247
|
+
const wav = await synthesizeSpeech(engine, request);
|
|
248
|
+
res.statusCode = 200;
|
|
249
|
+
res.setHeader('content-type', 'audio/wav');
|
|
250
|
+
res.setHeader('cache-control', 'no-store');
|
|
251
|
+
res.end(Buffer.from(wav));
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
const failure = toFailure(error);
|
|
255
|
+
if (await tryEdgeFallback(res, request, engine, failure))
|
|
256
|
+
return;
|
|
257
|
+
sendError(res, errorStatusOf(failure), errorBodyOf(failure));
|
|
258
|
+
}
|
|
259
|
+
})();
|
|
260
|
+
},
|
|
261
|
+
}), `dsh-mimo-speak: POST ${MIMOSPEAK_SYNTHESIZE_PATH}`);
|
|
262
|
+
// Stream one text as raw PCM chunks (SSE). The browser plays the first
|
|
263
|
+
// chunk as soon as it arrives instead of waiting for the whole utterance.
|
|
264
|
+
child.effect(() => child.webServer.register({
|
|
265
|
+
kind: 'exact',
|
|
266
|
+
path: MIMOSPEAK_SYNTHESIZE_STREAM_PATH,
|
|
267
|
+
handler: (req, res) => {
|
|
268
|
+
if (fence(req, res))
|
|
269
|
+
return;
|
|
270
|
+
if (req.method !== 'POST') {
|
|
271
|
+
sendError(res, 405, { error: { code: 'bad-request', message: 'POST only.' } });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
void (async () => {
|
|
275
|
+
const parsed = await readJsonBody(req);
|
|
276
|
+
if (parsed === undefined) {
|
|
277
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'Request body is not a JSON object.' } });
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const request = readRequest(parsed);
|
|
281
|
+
if (request === undefined) {
|
|
282
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'A non-empty `text` string is required.' } });
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const engine = await resolveEngineSnapshot(ctx, config);
|
|
286
|
+
const abort = responseAbortSignal(res, engine.timeoutMs);
|
|
287
|
+
res.statusCode = 200;
|
|
288
|
+
res.setHeader('content-type', 'text/event-stream; charset=utf-8');
|
|
289
|
+
res.setHeader('cache-control', 'no-store');
|
|
290
|
+
res.setHeader('connection', 'keep-alive');
|
|
291
|
+
res.flushHeaders?.();
|
|
292
|
+
const emit = (payload) => {
|
|
293
|
+
if (res.writableEnded || res.destroyed)
|
|
294
|
+
return;
|
|
295
|
+
res.write(`data: ${JSON.stringify(payload)}\n\n`);
|
|
296
|
+
};
|
|
297
|
+
try {
|
|
298
|
+
const stats = await streamSpeechPcm(engine, request, undefined, (pcm) => {
|
|
299
|
+
emit({ pcm: Buffer.from(pcm).toString('base64') });
|
|
300
|
+
}, abort.signal);
|
|
301
|
+
emit({ done: true, firstChunkMs: stats.firstChunkMs, chunks: stats.chunks });
|
|
302
|
+
res.end();
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
const failure = toFailure(error);
|
|
306
|
+
emit({ error: errorBodyOf(failure).error });
|
|
307
|
+
res.end();
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
abort.dispose();
|
|
311
|
+
}
|
|
312
|
+
})();
|
|
313
|
+
},
|
|
314
|
+
}), `dsh-mimo-speak: POST ${MIMOSPEAK_SYNTHESIZE_STREAM_PATH}`);
|
|
315
|
+
// Spoken summary for the brief read scope: one short model-written
|
|
316
|
+
// sentence-group instead of a mechanical sentence pick. Best effort — the
|
|
317
|
+
// client keeps its offline extractive fallback when this route says no.
|
|
318
|
+
child.effect(() => child.webServer.register({
|
|
319
|
+
kind: 'exact',
|
|
320
|
+
path: MIMOSPEAK_SUMMARY_PATH,
|
|
321
|
+
handler: (req, res) => {
|
|
322
|
+
if (fence(req, res))
|
|
323
|
+
return;
|
|
324
|
+
if (req.method !== 'POST') {
|
|
325
|
+
sendError(res, 405, { error: { code: 'bad-request', message: 'POST only.' } });
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
void (async () => {
|
|
329
|
+
const parsed = await readJsonBody(req);
|
|
330
|
+
if (parsed === undefined) {
|
|
331
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'Request body is not a JSON object.' } });
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const text = typeof parsed.text === 'string'
|
|
335
|
+
? parsed.text
|
|
336
|
+
: '';
|
|
337
|
+
if (text.trim() === '') {
|
|
338
|
+
sendError(res, 400, { error: { code: 'bad-request', message: 'A non-empty `text` string is required.' } });
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const abort = responseAbortSignal(res, config.timeoutMs.get());
|
|
342
|
+
try {
|
|
343
|
+
const summary = await summarizeForSpeech(ctx, text, abort.signal);
|
|
344
|
+
if (summary === undefined) {
|
|
345
|
+
sendError(res, 503, errorBodyOf(new TtsError('not-configured', 'No model is available to summarize; the client falls back to the offline brief.')));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const body = { summary };
|
|
349
|
+
sendJson(res, 200, body);
|
|
350
|
+
}
|
|
351
|
+
finally {
|
|
352
|
+
abort.dispose();
|
|
353
|
+
}
|
|
354
|
+
})();
|
|
355
|
+
},
|
|
356
|
+
}), `dsh-mimo-speak: POST ${MIMOSPEAK_SUMMARY_PATH}`);
|
|
357
|
+
// Health check: speak a fixed sentence with the live configuration and
|
|
358
|
+
// report which engine answered and how long the first audio took.
|
|
359
|
+
child.effect(() => child.webServer.register({
|
|
360
|
+
kind: 'exact',
|
|
361
|
+
path: MIMOSPEAK_TEST_PATH,
|
|
362
|
+
handler: (req, res) => {
|
|
363
|
+
if (fence(req, res))
|
|
364
|
+
return;
|
|
365
|
+
if (req.method !== 'POST') {
|
|
366
|
+
sendError(res, 405, { error: { code: 'bad-request', message: 'POST only.' } });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
void (async () => {
|
|
370
|
+
const engine = await resolveEngineSnapshot(ctx, config);
|
|
371
|
+
const probe = { text: '你好,这是连接测试。' };
|
|
372
|
+
const startedAt = Date.now();
|
|
373
|
+
try {
|
|
374
|
+
const wav = await synthesizeSpeech(engine, probe);
|
|
375
|
+
const result = {
|
|
376
|
+
ok: true,
|
|
377
|
+
engine: 'mimo',
|
|
378
|
+
latencyMs: Date.now() - startedAt,
|
|
379
|
+
audioBytes: wav.length,
|
|
380
|
+
voice: engine.voice,
|
|
381
|
+
model: effectiveModelOf(engine),
|
|
382
|
+
};
|
|
383
|
+
sendJson(res, 200, result);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
const failure = toFailure(error);
|
|
387
|
+
if (config.fallbackEngine.get() === 'edge') {
|
|
388
|
+
try {
|
|
389
|
+
const mp3 = await synthesizeEdge(probe.text, config.edgeVoice.get(), engine.timeoutMs);
|
|
390
|
+
const result = {
|
|
391
|
+
ok: true,
|
|
392
|
+
engine: 'edge',
|
|
393
|
+
latencyMs: Date.now() - startedAt,
|
|
394
|
+
audioBytes: mp3.length,
|
|
395
|
+
voice: config.edgeVoice.get() ?? DEFAULT_EDGE_VOICE,
|
|
396
|
+
};
|
|
397
|
+
sendJson(res, 200, result);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
catch (edgeError) {
|
|
401
|
+
const edgeFailure = toFailure(edgeError);
|
|
402
|
+
sendError(res, errorStatusOf(edgeFailure), errorBodyOf(new TtsError(edgeFailure.code, `MiMo failed (${failure.message}); Edge fallback also failed (${edgeFailure.message}).`)));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
sendError(res, errorStatusOf(failure), errorBodyOf(failure));
|
|
407
|
+
}
|
|
408
|
+
})();
|
|
409
|
+
},
|
|
410
|
+
}), `dsh-mimo-speak: POST ${MIMOSPEAK_TEST_PATH}`);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
/** JSON body size limit; settings and one speak request are small. */
|
|
414
|
+
const MAX_BODY_BYTES = 1024 * 1024;
|
|
415
|
+
/**
|
|
416
|
+
* Build one abort signal for a response that closes early or runs past its
|
|
417
|
+
* configured budget.
|
|
418
|
+
*/
|
|
419
|
+
function responseAbortSignal(res, timeoutMs) {
|
|
420
|
+
const controller = new AbortController();
|
|
421
|
+
const onClose = () => {
|
|
422
|
+
if (!res.writableEnded)
|
|
423
|
+
controller.abort();
|
|
424
|
+
};
|
|
425
|
+
res.once('close', onClose);
|
|
426
|
+
const combined = withAbortSignal(timeoutMs, controller.signal);
|
|
427
|
+
return {
|
|
428
|
+
signal: combined.signal,
|
|
429
|
+
dispose: () => {
|
|
430
|
+
res.off('close', onClose);
|
|
431
|
+
combined.dispose();
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Read one JSON object request body under the size limit.
|
|
437
|
+
* @param req - inbound request.
|
|
438
|
+
* @returns the parsed object, or undefined when the body is absent, oversized,
|
|
439
|
+
* malformed, or not a JSON object.
|
|
440
|
+
*/
|
|
441
|
+
async function readJsonBody(req) {
|
|
442
|
+
const chunks = [];
|
|
443
|
+
let size = 0;
|
|
444
|
+
for await (const chunk of req) {
|
|
445
|
+
const buffer = chunk;
|
|
446
|
+
size += buffer.length;
|
|
447
|
+
if (size > MAX_BODY_BYTES)
|
|
448
|
+
return undefined;
|
|
449
|
+
chunks.push(buffer);
|
|
450
|
+
}
|
|
451
|
+
if (chunks.length === 0)
|
|
452
|
+
return undefined;
|
|
453
|
+
try {
|
|
454
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
455
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
456
|
+
? parsed
|
|
457
|
+
: undefined;
|
|
458
|
+
}
|
|
459
|
+
catch {
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAKvC,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EACL,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAC/R,qBAAqB,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,gCAAgC,EAAE,mBAAmB,GAChI,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC5G,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,qDAAqD;AACrD,MAAM,CAAC,MAAM,IAAI,GAAG,YAAY,CAAA;AAqChC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,gBAAgB,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AAM,GAAG,KAAe,CAAA;QAC9B,IAAI,IAAI,MAAM,CAAC,MAAM,CAAA;QACrB,IAAI,IAAI,GAAG,cAAc;YAAE,OAAO,SAAS,CAAA;QAC3C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrB,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACzC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;QAC1E,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAC5E,CAAC,CAAC,MAAiC;YACnC,CAAC,CAAC,SAAS,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown → speakable-text normalization applied Host-side before synthesis.
|
|
3
|
+
*
|
|
4
|
+
* The MiMo TTS endpoint speaks whatever it is given; assistant replies are
|
|
5
|
+
* Markdown, and reading decoration, fences, and URLs aloud is noise. The
|
|
6
|
+
* normalization here is deliberately conservative: it removes presentation
|
|
7
|
+
* markup while keeping the words, and it never invents text.
|
|
8
|
+
* @module dsh-mimo-speak/normalize
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Convert assistant Markdown into text worth speaking aloud.
|
|
12
|
+
*
|
|
13
|
+
* Removes fenced code (kept as a short spoken note), inline-code markers,
|
|
14
|
+
* heading/list/quote markers, emphasis markers, tables (cells joined with
|
|
15
|
+
* commas), images, HTML tags, and link targets (the anchor text stays).
|
|
16
|
+
* @param markdown - raw assistant reply text.
|
|
17
|
+
* @returns plain text suitable for TTS input.
|
|
18
|
+
*/
|
|
19
|
+
export declare function toSpeakableText(markdown: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Cut a long text at a sentence boundary near `maxChars`.
|
|
22
|
+
*
|
|
23
|
+
* The synthesize route refuses oversized input; callers that prefer speaking a
|
|
24
|
+
* prefix over refusing outright use this first.
|
|
25
|
+
* @param text - normalized speakable text.
|
|
26
|
+
* @param maxChars - inclusive character budget.
|
|
27
|
+
* @returns the text unchanged when it fits, otherwise a prefix ending at the
|
|
28
|
+
* last sentence boundary inside the budget (or a hard cut when there is none).
|
|
29
|
+
*/
|
|
30
|
+
export declare function clampText(text: string, maxChars: number): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown → speakable-text normalization applied Host-side before synthesis.
|
|
3
|
+
*
|
|
4
|
+
* The MiMo TTS endpoint speaks whatever it is given; assistant replies are
|
|
5
|
+
* Markdown, and reading decoration, fences, and URLs aloud is noise. The
|
|
6
|
+
* normalization here is deliberately conservative: it removes presentation
|
|
7
|
+
* markup while keeping the words, and it never invents text.
|
|
8
|
+
* @module dsh-mimo-speak/normalize
|
|
9
|
+
*/
|
|
10
|
+
/** Replacement spoken for a fenced code block (reading code aloud is noise). */
|
|
11
|
+
const CODE_FENCE_NOTE = '代码略。';
|
|
12
|
+
/**
|
|
13
|
+
* Convert assistant Markdown into text worth speaking aloud.
|
|
14
|
+
*
|
|
15
|
+
* Removes fenced code (kept as a short spoken note), inline-code markers,
|
|
16
|
+
* heading/list/quote markers, emphasis markers, tables (cells joined with
|
|
17
|
+
* commas), images, HTML tags, and link targets (the anchor text stays).
|
|
18
|
+
* @param markdown - raw assistant reply text.
|
|
19
|
+
* @returns plain text suitable for TTS input.
|
|
20
|
+
*/
|
|
21
|
+
export function toSpeakableText(markdown) {
|
|
22
|
+
let text = markdown;
|
|
23
|
+
// Fenced code: one spoken note per block, whatever its language.
|
|
24
|
+
text = text.replace(/```[\s\S]*?```/g, `\n${CODE_FENCE_NOTE}\n`);
|
|
25
|
+
text = text.replace(/~~~[\s\S]*?~~~/g, `\n${CODE_FENCE_NOTE}\n`);
|
|
26
|
+
// Inline code keeps its content, loses its ticks.
|
|
27
|
+
text = text.replace(/`([^`\n]*)`/g, '$1');
|
|
28
|
+
// Images: drop entirely (alt text is rarely speakable).
|
|
29
|
+
text = text.replace(/!\[[^\]]*\]\([^)]*\)/g, '');
|
|
30
|
+
// Links keep the anchor text; the URL is never spoken.
|
|
31
|
+
text = text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1');
|
|
32
|
+
text = text.replace(/\[([^\]]*)\]\[[^\]]*\]/g, '$1');
|
|
33
|
+
// Reference definitions and HTML tags.
|
|
34
|
+
text = text.replace(/^\[[^\]]*\]:\s+\S+.*$/gmu, '');
|
|
35
|
+
text = text.replace(/<\/?[a-zA-Z][^>\n]*>/g, '');
|
|
36
|
+
// Headings, bullets, quotes, and horizontal rules.
|
|
37
|
+
text = text.replace(/^#{1,6}\s+/gmu, '');
|
|
38
|
+
text = text.replace(/^\s*(?:[-*+]|\d+[.)])\s+/gmu, '');
|
|
39
|
+
text = text.replace(/^\s*>\s?/gmu, '');
|
|
40
|
+
text = text.replace(/^\s*(?:-{3,}|\*{3,}|_{3,})\s*$/gmu, '\n');
|
|
41
|
+
// Tables: keep cell text in reading order, drop alignment and cell markup.
|
|
42
|
+
text = text.replace(/^\|?[\s:|-]+\|[\s:|-]*$/gmu, '');
|
|
43
|
+
text = text.replace(/\s*\|\s*/g, ',');
|
|
44
|
+
// Emphasis and strikethrough markers only; the words stay.
|
|
45
|
+
text = text.replace(/(\*\*|__|~~)/g, '');
|
|
46
|
+
text = text.replace(/(?<!\w)\*([^*\n]+)\*(?!\w)/g, '$1');
|
|
47
|
+
text = text.replace(/(?<!\w)_([^_\n]+)_(?!\w)/g, '$1');
|
|
48
|
+
// Escaped punctuation keeps the punctuation.
|
|
49
|
+
text = text.replace(/\\([\\`*_{}[\]()#+\-.!])/g, '$1');
|
|
50
|
+
// Whitespace: collapse runs, trim each line, drop empty lines.
|
|
51
|
+
text = text.replace(/[ \t]+/g, ' ');
|
|
52
|
+
text = text.split('\n').map(line => line.trim()).filter(line => line !== '').join('\n');
|
|
53
|
+
return text.trim();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Cut a long text at a sentence boundary near `maxChars`.
|
|
57
|
+
*
|
|
58
|
+
* The synthesize route refuses oversized input; callers that prefer speaking a
|
|
59
|
+
* prefix over refusing outright use this first.
|
|
60
|
+
* @param text - normalized speakable text.
|
|
61
|
+
* @param maxChars - inclusive character budget.
|
|
62
|
+
* @returns the text unchanged when it fits, otherwise a prefix ending at the
|
|
63
|
+
* last sentence boundary inside the budget (or a hard cut when there is none).
|
|
64
|
+
*/
|
|
65
|
+
export function clampText(text, maxChars) {
|
|
66
|
+
if (text.length <= maxChars)
|
|
67
|
+
return text;
|
|
68
|
+
const prefix = text.slice(0, maxChars);
|
|
69
|
+
const boundary = Math.max(prefix.lastIndexOf('。'), prefix.lastIndexOf('!'), prefix.lastIndexOf('?'), prefix.lastIndexOf('!'), prefix.lastIndexOf('?'), prefix.lastIndexOf('.'));
|
|
70
|
+
return boundary > maxChars / 2 ? prefix.slice(0, boundary + 1) : prefix;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,gFAAgF;AAChF,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,IAAI,IAAI,GAAG,QAAQ,CAAA;IACnB,iEAAiE;IACjE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,KAAK,eAAe,IAAI,CAAC,CAAA;IAChE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,KA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