dsh-xiaomi-tts 2.3.0 → 2.3.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/README.en.md +5 -3
- package/README.md +80 -13
- package/assets/image.png +0 -0
- package/lib/client/conversation.d.ts +26 -0
- package/lib/client/conversation.d.ts.map +1 -0
- package/lib/client/index.d.ts +0 -51
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/live-speech-controller.d.ts +44 -0
- package/lib/client/live-speech-controller.d.ts.map +1 -0
- package/lib/client/localization.d.ts +66 -0
- package/lib/client/localization.d.ts.map +1 -0
- package/lib/client/pcm-audio-queue.d.ts +21 -0
- package/lib/client/pcm-audio-queue.d.ts.map +1 -0
- package/lib/client/playback-controller.d.ts +29 -0
- package/lib/client/playback-controller.d.ts.map +1 -0
- package/lib/client/playback-types.d.ts +17 -0
- package/lib/client/playback-types.d.ts.map +1 -0
- package/lib/client/playback.d.ts +4 -0
- package/lib/client/playback.d.ts.map +1 -0
- package/lib/client/settings-card.d.ts +11 -0
- package/lib/client/settings-card.d.ts.map +1 -0
- package/lib/client/settings-scope.d.ts +6 -0
- package/lib/client/settings-scope.d.ts.map +1 -0
- package/lib/client/styles.d.ts +2 -0
- package/lib/client/styles.d.ts.map +1 -0
- package/lib/client/voice-design-picker.d.ts +14 -0
- package/lib/client/voice-design-picker.d.ts.map +1 -0
- package/lib/client.js +675 -384
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +281 -4
- package/lib/{shared-DQA9zfpt.js → shared-9qFFYsWe.js} +73 -8
- package/lib/shared.d.ts +24 -1
- package/lib/shared.d.ts.map +1 -1
- package/lib/shared.js +2 -2
- package/package.json +3 -1
package/lib/client.js
CHANGED
|
@@ -37,6 +37,14 @@ const TTS_SETTINGS_NAMESPACE = "xiaomi-mimo-tts";
|
|
|
37
37
|
const TTS_ROUTE = "/plugins/xiaomi-mimo-tts/synthesize";
|
|
38
38
|
/** Same-origin route that proxies MiMo PCM16 server-sent audio chunks. */
|
|
39
39
|
const TTS_STREAM_ROUTE = "/plugins/xiaomi-mimo-tts/synthesize-stream";
|
|
40
|
+
/** Same-origin route that removes this plugin from the DSH Web profile. */
|
|
41
|
+
const TTS_UNINSTALL_ROUTE = "/plugins/xiaomi-mimo-tts/uninstall";
|
|
42
|
+
/** Same-origin route that checks the published npm version. */
|
|
43
|
+
const TTS_UPDATE_ROUTE = "/plugins/xiaomi-mimo-tts/update";
|
|
44
|
+
/** Keep the UI version visible without making the browser bundle load package.json. */
|
|
45
|
+
const TTS_VERSION = "2.3.2";
|
|
46
|
+
/** Same-origin route that reports API key configuration status without exposing the key. */
|
|
47
|
+
const TTS_API_KEY_STATUS_ROUTE = "/plugins/xiaomi-mimo-tts/api-key-status";
|
|
40
48
|
/** Same-origin prefix used by the Web client to load voice-design preset icons. */
|
|
41
49
|
const TTS_VOICE_DESIGN_ASSET_ROUTE = "/plugins/xiaomi-mimo-tts/voice-presets";
|
|
42
50
|
/** Supported built-in Xiaomi MiMo voices. */
|
|
@@ -118,10 +126,12 @@ const TTS_PUNCTUATION = {
|
|
|
118
126
|
"?": "?",
|
|
119
127
|
";": ";",
|
|
120
128
|
"、": ",",
|
|
129
|
+
"(": ",",
|
|
130
|
+
")": ",",
|
|
121
131
|
" ": " "
|
|
122
132
|
};
|
|
123
133
|
/** Decorative punctuation can make TTS emit non-speech artifacts, so omit it entirely. */
|
|
124
|
-
const TTS_NON_SPEECH_PUNCTUATION = /[()
|
|
134
|
+
const TTS_NON_SPEECH_PUNCTUATION = /[()\[\]【】[]〔〕〖〗{}{}「」『』《》〈〉“”‘’"'`<>:…—–-~]/gu;
|
|
125
135
|
const TTS_URL_PATTERN = /\b(?:https?|ftp):\/\/[^\s<>()]+|\bwww\.[^\s<>()]+|\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:com|cn|net|org|io|ai|dev|me|co|edu|gov|xyz|tech|info|app|site|link)(?:[/:?#][^\s<>()]*)?/giu;
|
|
126
136
|
const TTS_WINDOWS_PATH_PATTERN = /(?:\b[A-Za-z]:[\\/]|\\\\)(?:[A-Za-z0-9._ -]+[\\/])*(?:[A-Za-z0-9._ -]+)/gu;
|
|
127
137
|
const TTS_UNIX_PATH_PATTERN = /\/(?:[A-Za-z0-9._-]+\/)*(?:[A-Za-z0-9._-]+)/gu;
|
|
@@ -139,7 +149,7 @@ function removeTtsSymbols(value) {
|
|
|
139
149
|
return value.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF]/g, " ").replace(/(?:\p{Extended_Pictographic}|\p{Emoji_Presentation}|\p{Regional_Indicator}|\p{Emoji_Modifier}|\p{So}|\uFE0E|\uFE0F|\u200D|\u20E3)/gu, " ");
|
|
140
150
|
}
|
|
141
151
|
function normalizeTtsPunctuation(value) {
|
|
142
|
-
return value.replace(TTS_NON_SPEECH_PUNCTUATION, "").replace(/[
|
|
152
|
+
return value.replace(TTS_NON_SPEECH_PUNCTUATION, "").replace(/[,。!?;、() ]/gu, (character) => TTS_PUNCTUATION[character] ?? character).replace(/(^|\s)[,;:!?]+(?=\s|$)/g, "$1").replace(/([,;:])\s*([.!?])/g, "$2").replace(/\s+([,.;:!?])/g, "$1");
|
|
143
153
|
}
|
|
144
154
|
/**
|
|
145
155
|
* Prepare assistant text for speech synthesis without changing the chat transcript.
|
|
@@ -196,16 +206,18 @@ function classifyLiveSpeechTransition(current, next) {
|
|
|
196
206
|
if (current === null || current.sessionId !== next.sessionId || current.turn !== next.turn) return "new-turn";
|
|
197
207
|
return current.step === next.step ? "same-step" : "same-turn";
|
|
198
208
|
}
|
|
199
|
-
/** Serializes sentence requests and makes cancellation independent from the playback backend. */
|
|
200
209
|
var AbortableSentenceQueue = class {
|
|
201
210
|
pending = [];
|
|
202
211
|
current = null;
|
|
203
212
|
revision = 0;
|
|
204
|
-
|
|
213
|
+
busy = false;
|
|
214
|
+
constructor(start, options = {}) {
|
|
205
215
|
this.start = start;
|
|
216
|
+
this.options = options;
|
|
206
217
|
}
|
|
207
218
|
enqueue(sentence) {
|
|
208
219
|
this.pending.push(sentence);
|
|
220
|
+
this.setBusy(true);
|
|
209
221
|
this.pump();
|
|
210
222
|
}
|
|
211
223
|
cancel() {
|
|
@@ -213,23 +225,38 @@ var AbortableSentenceQueue = class {
|
|
|
213
225
|
this.pending.length = 0;
|
|
214
226
|
this.current?.abort();
|
|
215
227
|
this.current = null;
|
|
228
|
+
this.setBusy(false);
|
|
216
229
|
}
|
|
217
230
|
async pump() {
|
|
218
231
|
if (this.current !== null) return;
|
|
219
232
|
const sentence = this.pending.shift();
|
|
220
|
-
if (sentence === void 0)
|
|
233
|
+
if (sentence === void 0) {
|
|
234
|
+
this.setBusy(false);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
221
237
|
const revision = this.revision;
|
|
222
238
|
const controller = new AbortController();
|
|
223
239
|
this.current = controller;
|
|
224
240
|
try {
|
|
225
241
|
await this.start(sentence, controller.signal);
|
|
226
242
|
} catch (error) {
|
|
227
|
-
if (!controller.signal.aborted)
|
|
243
|
+
if (!controller.signal.aborted && revision === this.revision) {
|
|
244
|
+
this.pending.length = 0;
|
|
245
|
+
this.revision += 1;
|
|
246
|
+
this.options.onError?.(error);
|
|
247
|
+
}
|
|
228
248
|
} finally {
|
|
229
249
|
if (this.current === controller) this.current = null;
|
|
230
|
-
if (revision === this.revision) this.pump();
|
|
250
|
+
if (revision === this.revision) if (this.pending.length > 0) this.pump();
|
|
251
|
+
else this.setBusy(false);
|
|
252
|
+
else this.setBusy(false);
|
|
231
253
|
}
|
|
232
254
|
}
|
|
255
|
+
setBusy(busy) {
|
|
256
|
+
if (this.busy === busy) return;
|
|
257
|
+
this.busy = busy;
|
|
258
|
+
this.options.onBusyChange?.(busy);
|
|
259
|
+
}
|
|
233
260
|
};
|
|
234
261
|
/** Defaults shared by the Schemastery config and the Web settings form. */
|
|
235
262
|
const DEFAULT_TTS_SETTINGS = {
|
|
@@ -247,6 +274,11 @@ const DEFAULT_TTS_SETTINGS = {
|
|
|
247
274
|
maxTextLength: 12e3,
|
|
248
275
|
requestTimeoutMs: 12e4
|
|
249
276
|
};
|
|
277
|
+
/** Whether an API key selects one of the Xiaomi endpoints supported by this plugin. */
|
|
278
|
+
function isSupportedTtsApiKey(apiKey) {
|
|
279
|
+
const normalized = apiKey.trim();
|
|
280
|
+
return normalized.startsWith("sk-") || normalized.startsWith("tp-");
|
|
281
|
+
}
|
|
250
282
|
/** Resolve an optional settings snapshot into the values used by the form. */
|
|
251
283
|
function resolveTtsSettings(value) {
|
|
252
284
|
const resolved = {
|
|
@@ -262,228 +294,32 @@ function resolveTtsSettings(value) {
|
|
|
262
294
|
}
|
|
263
295
|
|
|
264
296
|
//#endregion
|
|
265
|
-
//#region src/client/
|
|
266
|
-
/** Client services required by this plugin. */
|
|
267
|
-
const inject = [
|
|
268
|
-
"slots",
|
|
269
|
-
"locale",
|
|
270
|
-
"connection",
|
|
271
|
-
"remote",
|
|
272
|
-
"settingsScope"
|
|
273
|
-
];
|
|
274
|
-
const NS = "xiaomi-mimo-tts";
|
|
275
|
-
const zh = {
|
|
276
|
-
"action.play": "朗读回复",
|
|
277
|
-
"action.pause": "暂停朗读",
|
|
278
|
-
"action.resume": "继续朗读",
|
|
279
|
-
"action.loading": "正在生成语音",
|
|
280
|
-
"action.retry": "重新生成语音",
|
|
281
|
-
"error.noText": "这条回复没有可朗读的正文。",
|
|
282
|
-
"error.request": "语音生成失败。",
|
|
283
|
-
"error.play": "浏览器阻止了自动播放,请点击朗读按钮。",
|
|
284
|
-
"settings.title": "语音朗读 (Xiaomi MiMo)",
|
|
285
|
-
"settings.description": "在助手回复操作栏中使用 Xiaomi MiMo TTS 生成并播放语音。",
|
|
286
|
-
"settings.enabled": "显示朗读按钮",
|
|
287
|
-
"settings.enabledHint": "关闭后不会在助手回复操作栏显示朗读按钮,也不会自动播报。",
|
|
288
|
-
"settings.apiKey": "API Key",
|
|
289
|
-
"settings.apiKeyHint": "密钥保存在 DSH 设置文件中,传到浏览器前会被脱敏。",
|
|
290
|
-
"settings.apiKeyStatus": "只有输入新值并保存时才会替换现有密钥。",
|
|
291
|
-
"settings.apiKeyConfigured": "已配置",
|
|
292
|
-
"settings.getApiKey": "获取 API Key",
|
|
293
|
-
"settings.autoPlay": "开启自动播报",
|
|
294
|
-
"settings.autoPlayHint": "开启时会同步显示朗读按钮;浏览器也可能拒绝自动播放。",
|
|
295
|
-
"settings.model": "TTS 模型",
|
|
296
|
-
"settings.presetModel": "预置音色模型 (mimo-v2.5-tts)",
|
|
297
|
-
"settings.voiceDesignModel": "自定义音色模型 (mimo-v2.5-tts-voicedesign)",
|
|
298
|
-
"settings.modelAutoPlayHintPreset": "预置音色模型支持实时流式播放。",
|
|
299
|
-
"settings.modelAutoPlayHintVoiceDesign": "自定义音色仅支持在回复完成后自动播放。",
|
|
300
|
-
"settings.voice": "内置音色",
|
|
301
|
-
"settings.voiceDesignPrompt": "自定义音色描述",
|
|
302
|
-
"settings.customVoiceOption": "自定义",
|
|
303
|
-
"settings.customVoiceSummary": "手动编写音色描述",
|
|
304
|
-
"settings.voiceDesignPromptHint": "按“年龄段 + 性别、声音质感、语速节奏、情绪底色”描述声音本身;不写场景或动作。",
|
|
305
|
-
"settings.format": "音频格式",
|
|
306
|
-
"settings.save": "保存",
|
|
307
|
-
"settings.saving": "保存中…",
|
|
308
|
-
"settings.saved": "已保存",
|
|
309
|
-
"settings.unsaved": "未保存",
|
|
310
|
-
"settings.overridden": "已覆盖",
|
|
311
|
-
"settings.reset": "恢复默认",
|
|
312
|
-
"settings.discard": "放弃修改",
|
|
313
|
-
"settings.failed": "保存失败,请重试。",
|
|
314
|
-
"settings.readOnly": "当前 DSH 设置为只读。",
|
|
315
|
-
"settings.secretPlaceholder": "输入新的 Xiaomi MiMo API Key",
|
|
316
|
-
"settings.expand": "展开设置",
|
|
317
|
-
"settings.collapse": "收起设置"
|
|
318
|
-
};
|
|
319
|
-
const en = {
|
|
320
|
-
"action.play": "Read aloud",
|
|
321
|
-
"action.pause": "Pause speech",
|
|
322
|
-
"action.resume": "Resume speech",
|
|
323
|
-
"action.loading": "Generating speech",
|
|
324
|
-
"action.retry": "Generate speech again",
|
|
325
|
-
"error.noText": "This response has no readable body text.",
|
|
326
|
-
"error.request": "Speech generation failed.",
|
|
327
|
-
"error.play": "The browser blocked autoplay. Click Read aloud to play it.",
|
|
328
|
-
"settings.title": "Text To Speech (Xiaomi MiMo)",
|
|
329
|
-
"settings.description": "Generate and play Xiaomi MiMo TTS audio from assistant message actions.",
|
|
330
|
-
"settings.enabled": "Show read-aloud button",
|
|
331
|
-
"settings.enabledHint": "When disabled, the read-aloud button and automatic speech are both turned off.",
|
|
332
|
-
"settings.apiKey": "API Key",
|
|
333
|
-
"settings.apiKeyHint": "Stored in DSH settings and redacted before settings are sent to the browser.",
|
|
334
|
-
"settings.apiKeyStatus": "An existing key changes only when you save a new value.",
|
|
335
|
-
"settings.apiKeyConfigured": "Configured",
|
|
336
|
-
"settings.getApiKey": "Get API Key",
|
|
337
|
-
"settings.autoPlay": "Enable automatic read-aloud",
|
|
338
|
-
"settings.autoPlayHint": "Enabling it also shows the read-aloud button; the browser may reject autoplay.",
|
|
339
|
-
"settings.model": "TTS model",
|
|
340
|
-
"settings.presetModel": "Preset voices (mimo-v2.5-tts)",
|
|
341
|
-
"settings.voiceDesignModel": "Custom voice design (mimo-v2.5-tts-voicedesign)",
|
|
342
|
-
"settings.modelAutoPlayHintPreset": "Preset voices support realtime streaming playback.",
|
|
343
|
-
"settings.modelAutoPlayHintVoiceDesign": "Custom voice design supports automatic playback only after the reply is complete.",
|
|
344
|
-
"settings.voice": "Built-in voice",
|
|
345
|
-
"settings.voiceDesignPrompt": "Custom voice description",
|
|
346
|
-
"settings.customVoiceOption": "Custom",
|
|
347
|
-
"settings.customVoiceSummary": "Write a custom voice description",
|
|
348
|
-
"settings.voiceDesignPromptHint": "Describe the voice itself with age/gender, texture, pace, and emotional baseline; avoid scenes or actions.",
|
|
349
|
-
"settings.format": "Audio format",
|
|
350
|
-
"settings.save": "Save",
|
|
351
|
-
"settings.saving": "Saving…",
|
|
352
|
-
"settings.saved": "Saved",
|
|
353
|
-
"settings.unsaved": "Unsaved",
|
|
354
|
-
"settings.overridden": "Overridden",
|
|
355
|
-
"settings.reset": "Restore default",
|
|
356
|
-
"settings.discard": "Discard changes",
|
|
357
|
-
"settings.failed": "Save failed. Try again.",
|
|
358
|
-
"settings.readOnly": "DSH settings are read-only.",
|
|
359
|
-
"settings.secretPlaceholder": "Enter a new Xiaomi MiMo API key",
|
|
360
|
-
"settings.expand": "Expand settings",
|
|
361
|
-
"settings.collapse": "Collapse settings"
|
|
362
|
-
};
|
|
363
|
-
function isRecord(value) {
|
|
364
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
365
|
-
}
|
|
366
|
-
function decodeSettings(value) {
|
|
367
|
-
if (!isRecord(value)) return void 0;
|
|
368
|
-
const decoded = {};
|
|
369
|
-
if (typeof value.enabled === "boolean") decoded.enabled = value.enabled;
|
|
370
|
-
if (typeof value.apiKey === "string") decoded.apiKey = value.apiKey;
|
|
371
|
-
if (typeof value.baseURL === "string") decoded.baseURL = value.baseURL;
|
|
372
|
-
if (TTS_MODELS.includes(value.model)) decoded.model = value.model;
|
|
373
|
-
if (typeof value.voice === "string") decoded.voice = value.voice;
|
|
374
|
-
if (typeof value.voiceDesignPrompt === "string") decoded.voiceDesignPrompt = value.voiceDesignPrompt;
|
|
375
|
-
if (typeof value.voiceDesignCustomPrompt === "string") decoded.voiceDesignCustomPrompt = value.voiceDesignCustomPrompt;
|
|
376
|
-
if (value.format === "mp3" || value.format === "wav") decoded.format = value.format;
|
|
377
|
-
if (typeof value.autoPlay === "boolean") decoded.autoPlay = value.autoPlay;
|
|
378
|
-
if (typeof value.maxTextLength === "number") decoded.maxTextLength = value.maxTextLength;
|
|
379
|
-
if (typeof value.requestTimeoutMs === "number") decoded.requestTimeoutMs = value.requestTimeoutMs;
|
|
380
|
-
return decoded;
|
|
381
|
-
}
|
|
382
|
-
function useSettingsSnapshot(scope) {
|
|
383
|
-
return (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot(), () => scope.getSnapshot());
|
|
384
|
-
}
|
|
385
|
-
function formatStartupError(error) {
|
|
386
|
-
return error instanceof Error ? error.message : String(error);
|
|
387
|
-
}
|
|
388
|
-
function registerSlotContribution(ctx, name, register) {
|
|
389
|
-
ctx.effect(() => {
|
|
390
|
-
try {
|
|
391
|
-
ctx.slots.inject(name, () => {
|
|
392
|
-
try {
|
|
393
|
-
return register();
|
|
394
|
-
} catch (error) {
|
|
395
|
-
ctx.logger.error(`dsh-xiaomi-tts: ${name} contribution disabled: ${formatStartupError(error)}`);
|
|
396
|
-
return () => {};
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
} catch (error) {
|
|
400
|
-
ctx.logger.error(`dsh-xiaomi-tts: ${name} injection disabled: ${formatStartupError(error)}`);
|
|
401
|
-
}
|
|
402
|
-
return () => {};
|
|
403
|
-
}, `xiaomi-mimo-tts: ${name}`);
|
|
404
|
-
}
|
|
405
|
-
function messageText(snapshot, messageId) {
|
|
406
|
-
for (const node of snapshot.nodes) {
|
|
407
|
-
if (node.kind !== "assistant" || node.messageId !== messageId) continue;
|
|
408
|
-
return (0, __deepseek_ai_dsh_client_ui_primitives.extractMarkdownPlainText)(prepareTtsText(node.blocks.filter((block) => block.kind === "text").map((block) => block.text).join("\n\n"))).trim();
|
|
409
|
-
}
|
|
410
|
-
return "";
|
|
411
|
-
}
|
|
412
|
-
function messageTime(snapshot, messageId) {
|
|
413
|
-
for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return node.time;
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
function latestAssistantMessageId(snapshot) {
|
|
417
|
-
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
418
|
-
const node = snapshot.nodes[index];
|
|
419
|
-
if (node?.kind === "assistant" && node.messageId !== void 0) return node.messageId;
|
|
420
|
-
}
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
function assistantText(blocks) {
|
|
424
|
-
return blocks.filter((block) => block.kind === "text" && typeof block.text === "string").map((block) => block.text).join("\n\n");
|
|
425
|
-
}
|
|
426
|
-
function finalLiveMessage(snapshot, turn, step) {
|
|
427
|
-
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
428
|
-
const node = snapshot.nodes[index];
|
|
429
|
-
if (node?.kind === "assistant" && node.messageId !== void 0 && node.turn === turn && node.step === step) return {
|
|
430
|
-
messageId: node.messageId,
|
|
431
|
-
turn: node.turn,
|
|
432
|
-
step: node.step,
|
|
433
|
-
text: assistantText(node.blocks),
|
|
434
|
-
interrupted: node.interrupted === true
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
function messageLiveIdentity(snapshot, messageId) {
|
|
440
|
-
for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return {
|
|
441
|
-
turn: node.turn,
|
|
442
|
-
step: node.step
|
|
443
|
-
};
|
|
444
|
-
return null;
|
|
445
|
-
}
|
|
446
|
-
function pcmDeltaFromSse(data) {
|
|
447
|
-
if (data === "[DONE]") return null;
|
|
448
|
-
try {
|
|
449
|
-
const pcm = JSON.parse(data).choices?.[0]?.delta?.audio?.data;
|
|
450
|
-
return typeof pcm === "string" && pcm.length > 0 ? pcm : null;
|
|
451
|
-
} catch {
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
297
|
+
//#region src/client/pcm-audio-queue.ts
|
|
455
298
|
var PcmAudioQueue = class {
|
|
456
299
|
context = null;
|
|
457
300
|
scheduledAt = 0;
|
|
458
301
|
sources = /* @__PURE__ */ new Set();
|
|
459
302
|
revision = 0;
|
|
460
303
|
chain = Promise.resolve();
|
|
461
|
-
|
|
462
|
-
|
|
304
|
+
busy = false;
|
|
305
|
+
constructor(callbacks) {
|
|
306
|
+
this.callbacks = callbacks;
|
|
463
307
|
}
|
|
464
308
|
enqueue(base64) {
|
|
465
309
|
const revision = this.revision;
|
|
466
|
-
|
|
467
|
-
|
|
310
|
+
const run = this.chain.then(() => this.schedule(base64, revision));
|
|
311
|
+
this.chain = run.catch(() => {});
|
|
312
|
+
return run;
|
|
468
313
|
}
|
|
469
314
|
stop() {
|
|
470
315
|
this.revision += 1;
|
|
471
316
|
this.scheduledAt = 0;
|
|
472
|
-
|
|
317
|
+
this.chain = Promise.resolve();
|
|
318
|
+
for (const source of this.sources) try {
|
|
319
|
+
source.stop();
|
|
320
|
+
} catch {}
|
|
473
321
|
this.sources.clear();
|
|
474
|
-
this.
|
|
475
|
-
}
|
|
476
|
-
pause() {
|
|
477
|
-
if (this.context?.state === "running") {
|
|
478
|
-
this.context.suspend();
|
|
479
|
-
this.onStateChange("paused");
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
resume() {
|
|
483
|
-
if (this.context !== null && this.context.state !== "running") {
|
|
484
|
-
this.context.resume();
|
|
485
|
-
this.onStateChange("playing");
|
|
486
|
-
}
|
|
322
|
+
this.setBusy(false);
|
|
487
323
|
}
|
|
488
324
|
async dispose() {
|
|
489
325
|
this.stop();
|
|
@@ -512,18 +348,47 @@ var PcmAudioQueue = class {
|
|
|
512
348
|
source.addEventListener("ended", () => {
|
|
513
349
|
if (revision !== this.revision) return;
|
|
514
350
|
this.sources.delete(source);
|
|
515
|
-
if (this.sources.size === 0) this.
|
|
351
|
+
if (this.sources.size === 0) this.setBusy(false);
|
|
516
352
|
}, { once: true });
|
|
517
|
-
|
|
518
|
-
|
|
353
|
+
try {
|
|
354
|
+
source.start(startAt);
|
|
355
|
+
} catch (error) {
|
|
356
|
+
this.sources.delete(source);
|
|
357
|
+
throw error;
|
|
358
|
+
}
|
|
359
|
+
this.setBusy(true);
|
|
360
|
+
this.callbacks.onPlaybackStart();
|
|
361
|
+
}
|
|
362
|
+
setBusy(busy) {
|
|
363
|
+
if (this.busy === busy) return;
|
|
364
|
+
this.busy = busy;
|
|
365
|
+
this.callbacks.onBusyChange(busy);
|
|
519
366
|
}
|
|
520
367
|
getContext() {
|
|
521
368
|
if (this.context === null) this.context = new AudioContext();
|
|
522
369
|
return this.context;
|
|
523
370
|
}
|
|
524
371
|
};
|
|
372
|
+
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/client/live-speech-controller.ts
|
|
375
|
+
function pcmDeltaFromSse(data) {
|
|
376
|
+
if (data === "[DONE]") return null;
|
|
377
|
+
try {
|
|
378
|
+
const pcm = JSON.parse(data).choices?.[0]?.delta?.audio?.data;
|
|
379
|
+
return typeof pcm === "string" && pcm.length > 0 ? pcm : null;
|
|
380
|
+
} catch {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
525
384
|
var LiveSpeechController = class {
|
|
526
|
-
audio = new PcmAudioQueue(
|
|
385
|
+
audio = new PcmAudioQueue({
|
|
386
|
+
onBusyChange: (busy) => {
|
|
387
|
+
this.audioBusy = busy;
|
|
388
|
+
this.maybeFinishPlayback();
|
|
389
|
+
},
|
|
390
|
+
onPlaybackStart: () => this.setStatus("playing")
|
|
391
|
+
});
|
|
527
392
|
streamGeneration = 0;
|
|
528
393
|
queue = this.createQueue();
|
|
529
394
|
active = null;
|
|
@@ -534,6 +399,9 @@ var LiveSpeechController = class {
|
|
|
534
399
|
messageId = null;
|
|
535
400
|
status = "idle";
|
|
536
401
|
sessionId = null;
|
|
402
|
+
requestBusy = false;
|
|
403
|
+
audioBusy = false;
|
|
404
|
+
blockedTurn = null;
|
|
537
405
|
onStateChange = null;
|
|
538
406
|
setStateChangeListener(listener) {
|
|
539
407
|
this.onStateChange = listener;
|
|
@@ -555,6 +423,9 @@ var LiveSpeechController = class {
|
|
|
555
423
|
turn,
|
|
556
424
|
step
|
|
557
425
|
};
|
|
426
|
+
const turnKey = `${sessionId}:${turn}`;
|
|
427
|
+
if (this.blockedTurn === turnKey) return;
|
|
428
|
+
if (this.blockedTurn !== null && this.blockedTurn !== turnKey) this.blockedTurn = null;
|
|
558
429
|
const transition = classifyLiveSpeechTransition(this.active, next);
|
|
559
430
|
if (transition === "new-turn" || transition === "same-step" && !text.startsWith(this.observed)) this.reset(next);
|
|
560
431
|
else if (transition === "same-turn") this.advanceSegment(next);
|
|
@@ -563,6 +434,10 @@ var LiveSpeechController = class {
|
|
|
563
434
|
}
|
|
564
435
|
finish(sessionId, final) {
|
|
565
436
|
const key = `${sessionId}:${final.turn}:${final.step}`;
|
|
437
|
+
if (this.blockedTurn === `${sessionId}:${final.turn}`) {
|
|
438
|
+
this.handled.add(key);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
566
441
|
if (this.sessionId !== sessionId || this.active === null || this.cursorKey(this.active) !== key) return;
|
|
567
442
|
if (final.interrupted) {
|
|
568
443
|
this.cancelSession(sessionId);
|
|
@@ -574,28 +449,22 @@ var LiveSpeechController = class {
|
|
|
574
449
|
this.drain(true);
|
|
575
450
|
this.handled.add(key);
|
|
576
451
|
}
|
|
577
|
-
|
|
578
|
-
if (this.sessionId !== sessionId) return false;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
else this.audio.resume();
|
|
452
|
+
stop(sessionId) {
|
|
453
|
+
if (this.sessionId !== sessionId || this.active === null || this.status !== "loading" && this.status !== "playing") return false;
|
|
454
|
+
this.blockedTurn = `${sessionId}:${this.active.turn}`;
|
|
455
|
+
this.resetState();
|
|
582
456
|
return true;
|
|
583
457
|
}
|
|
584
458
|
hasHandled(sessionId, identity) {
|
|
585
|
-
|
|
459
|
+
if (identity === null) return false;
|
|
460
|
+
return this.blockedTurn === `${sessionId}:${identity.turn}` || this.handled.has(`${sessionId}:${identity.turn}:${identity.step}`);
|
|
586
461
|
}
|
|
587
462
|
cancelSession(sessionId) {
|
|
588
|
-
if (this.
|
|
463
|
+
if (this.sessionId === sessionId) this.cancel();
|
|
589
464
|
}
|
|
590
465
|
cancel() {
|
|
591
|
-
this.
|
|
592
|
-
this.
|
|
593
|
-
this.active = null;
|
|
594
|
-
this.observed = "";
|
|
595
|
-
this.consumed = 0;
|
|
596
|
-
this.pendingText = "";
|
|
597
|
-
this.messageId = null;
|
|
598
|
-
this.status = "idle";
|
|
466
|
+
this.blockedTurn = null;
|
|
467
|
+
this.resetState();
|
|
599
468
|
}
|
|
600
469
|
async dispose() {
|
|
601
470
|
this.cancel();
|
|
@@ -605,19 +474,29 @@ var LiveSpeechController = class {
|
|
|
605
474
|
reset(next) {
|
|
606
475
|
this.replaceQueue();
|
|
607
476
|
this.audio.stop();
|
|
608
|
-
this.beginSegment(next);
|
|
609
|
-
this.
|
|
477
|
+
this.beginSegment(next, false);
|
|
478
|
+
this.setStatus("idle");
|
|
610
479
|
}
|
|
611
480
|
advanceSegment(next) {
|
|
612
481
|
this.drain(true);
|
|
613
|
-
this.beginSegment(next);
|
|
482
|
+
this.beginSegment(next, true);
|
|
614
483
|
}
|
|
615
|
-
beginSegment(next) {
|
|
484
|
+
beginSegment(next, preserveMessageId) {
|
|
616
485
|
this.active = next;
|
|
617
486
|
this.observed = "";
|
|
618
487
|
this.consumed = 0;
|
|
619
488
|
this.pendingText = "";
|
|
489
|
+
if (!preserveMessageId) this.messageId = null;
|
|
490
|
+
}
|
|
491
|
+
resetState() {
|
|
492
|
+
this.replaceQueue();
|
|
493
|
+
this.audio.stop();
|
|
494
|
+
this.active = null;
|
|
495
|
+
this.observed = "";
|
|
496
|
+
this.consumed = 0;
|
|
497
|
+
this.pendingText = "";
|
|
620
498
|
this.messageId = null;
|
|
499
|
+
this.setStatus("idle");
|
|
621
500
|
}
|
|
622
501
|
cursorKey(cursor) {
|
|
623
502
|
return `${cursor.sessionId}:${cursor.turn}:${cursor.step}`;
|
|
@@ -638,10 +517,21 @@ var LiveSpeechController = class {
|
|
|
638
517
|
}
|
|
639
518
|
createQueue() {
|
|
640
519
|
const generation = this.streamGeneration;
|
|
641
|
-
return new AbortableSentenceQueue((sentence, signal) => this.stream(sentence, signal, generation)
|
|
520
|
+
return new AbortableSentenceQueue((sentence, signal) => this.stream(sentence, signal, generation), {
|
|
521
|
+
onBusyChange: (busy) => {
|
|
522
|
+
if (generation !== this.streamGeneration) return;
|
|
523
|
+
this.requestBusy = busy;
|
|
524
|
+
if (busy && this.status === "idle") this.setStatus("loading");
|
|
525
|
+
this.maybeFinishPlayback();
|
|
526
|
+
},
|
|
527
|
+
onError: (error) => {
|
|
528
|
+
if (generation === this.streamGeneration) this.handleStreamError(error);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
642
531
|
}
|
|
643
532
|
replaceQueue() {
|
|
644
533
|
this.streamGeneration += 1;
|
|
534
|
+
this.requestBusy = false;
|
|
645
535
|
this.queue.cancel();
|
|
646
536
|
this.queue = this.createQueue();
|
|
647
537
|
}
|
|
@@ -650,7 +540,6 @@ var LiveSpeechController = class {
|
|
|
650
540
|
}
|
|
651
541
|
async stream(sentence, signal, generation) {
|
|
652
542
|
if (!this.isCurrentStream(generation, signal)) return;
|
|
653
|
-
this.setStatus("loading");
|
|
654
543
|
try {
|
|
655
544
|
const response = await fetch(TTS_STREAM_ROUTE, {
|
|
656
545
|
method: "POST",
|
|
@@ -684,12 +573,20 @@ var LiveSpeechController = class {
|
|
|
684
573
|
reader.releaseLock();
|
|
685
574
|
}
|
|
686
575
|
} catch (error) {
|
|
687
|
-
if (
|
|
688
|
-
this.setStatus("error");
|
|
689
|
-
throw error;
|
|
576
|
+
if (this.isCurrentStream(generation, signal)) throw error;
|
|
690
577
|
}
|
|
691
578
|
}
|
|
579
|
+
handleStreamError(error) {
|
|
580
|
+
if (this.active !== null) this.blockedTurn = `${this.active.sessionId}:${this.active.turn}`;
|
|
581
|
+
this.setStatus("error");
|
|
582
|
+
this.replaceQueue();
|
|
583
|
+
this.audio.stop();
|
|
584
|
+
}
|
|
585
|
+
maybeFinishPlayback() {
|
|
586
|
+
if (!this.requestBusy && !this.audioBusy && (this.status === "loading" || this.status === "playing")) this.setStatus("idle");
|
|
587
|
+
}
|
|
692
588
|
setStatus(status) {
|
|
589
|
+
if (this.status === status) return;
|
|
693
590
|
this.status = status;
|
|
694
591
|
this.reportStatus();
|
|
695
592
|
}
|
|
@@ -697,11 +594,15 @@ var LiveSpeechController = class {
|
|
|
697
594
|
if (this.sessionId !== null && this.messageId !== null) this.onStateChange?.(this.sessionId, this.messageId, this.status);
|
|
698
595
|
}
|
|
699
596
|
};
|
|
597
|
+
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/client/playback-controller.ts
|
|
700
600
|
var PlaybackController = class {
|
|
701
601
|
autoPlayArmedAt = Date.now();
|
|
702
602
|
view = {
|
|
703
603
|
sessionId: null,
|
|
704
604
|
messageId: null,
|
|
605
|
+
source: null,
|
|
705
606
|
status: "idle",
|
|
706
607
|
error: null
|
|
707
608
|
};
|
|
@@ -727,23 +628,13 @@ var PlaybackController = class {
|
|
|
727
628
|
this.completedSessions.clear();
|
|
728
629
|
this.completedMessages.clear();
|
|
729
630
|
this.activeSessionId = sessionId;
|
|
730
|
-
this.publish(
|
|
731
|
-
sessionId: null,
|
|
732
|
-
messageId: null,
|
|
733
|
-
status: "idle",
|
|
734
|
-
error: null
|
|
735
|
-
});
|
|
631
|
+
this.publish(this.emptyView());
|
|
736
632
|
}
|
|
737
633
|
cancelPlayback(sessionId) {
|
|
738
634
|
if (this.activeSessionId !== sessionId) return;
|
|
739
635
|
this.generation += 1;
|
|
740
636
|
this.stopCurrent();
|
|
741
|
-
this.publish(
|
|
742
|
-
sessionId: null,
|
|
743
|
-
messageId: null,
|
|
744
|
-
status: "idle",
|
|
745
|
-
error: null
|
|
746
|
-
});
|
|
637
|
+
this.publish(this.emptyView());
|
|
747
638
|
}
|
|
748
639
|
deactivateSession(sessionId) {
|
|
749
640
|
if (this.activeSessionId !== sessionId) return;
|
|
@@ -753,12 +644,7 @@ var PlaybackController = class {
|
|
|
753
644
|
this.completedSessions.clear();
|
|
754
645
|
this.completedMessages.clear();
|
|
755
646
|
this.activeSessionId = null;
|
|
756
|
-
this.publish(
|
|
757
|
-
sessionId: null,
|
|
758
|
-
messageId: null,
|
|
759
|
-
status: "idle",
|
|
760
|
-
error: null
|
|
761
|
-
});
|
|
647
|
+
this.publish(this.emptyView());
|
|
762
648
|
}
|
|
763
649
|
observeSession(sessionId, running, latestMessageId) {
|
|
764
650
|
if (this.activeSessionId !== sessionId) return;
|
|
@@ -783,16 +669,21 @@ var PlaybackController = class {
|
|
|
783
669
|
}
|
|
784
670
|
updateLivePlayback(sessionId, messageId, status) {
|
|
785
671
|
if (this.activeSessionId !== sessionId) return;
|
|
786
|
-
if (
|
|
672
|
+
if (status === "idle") {
|
|
673
|
+
if (this.view.source === "live" && this.view.messageId === messageId) this.publish(this.emptyView());
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
if (this.view.source !== "complete") this.publish({
|
|
787
677
|
sessionId,
|
|
788
678
|
messageId,
|
|
679
|
+
source: "live",
|
|
789
680
|
status,
|
|
790
681
|
error: status === "error" ? "play-failed" : null
|
|
791
682
|
});
|
|
792
683
|
}
|
|
793
684
|
async toggle(sessionId, messageId, text, automatic) {
|
|
794
685
|
if (this.activeSessionId !== sessionId) return;
|
|
795
|
-
if (this.view.sessionId === sessionId && this.view.messageId === messageId && this.current !== null) {
|
|
686
|
+
if (this.view.source === "complete" && this.view.sessionId === sessionId && this.view.messageId === messageId && this.current !== null) {
|
|
796
687
|
const audio = this.current.audio;
|
|
797
688
|
const generation$1 = this.generation;
|
|
798
689
|
if (audio.paused) try {
|
|
@@ -801,6 +692,7 @@ var PlaybackController = class {
|
|
|
801
692
|
this.publish({
|
|
802
693
|
sessionId,
|
|
803
694
|
messageId,
|
|
695
|
+
source: "complete",
|
|
804
696
|
status: "playing",
|
|
805
697
|
error: null
|
|
806
698
|
});
|
|
@@ -809,6 +701,7 @@ var PlaybackController = class {
|
|
|
809
701
|
this.publish({
|
|
810
702
|
sessionId,
|
|
811
703
|
messageId,
|
|
704
|
+
source: "complete",
|
|
812
705
|
status: "paused",
|
|
813
706
|
error: automatic ? "autoplay-blocked" : "play-failed"
|
|
814
707
|
});
|
|
@@ -818,6 +711,7 @@ var PlaybackController = class {
|
|
|
818
711
|
this.publish({
|
|
819
712
|
sessionId,
|
|
820
713
|
messageId,
|
|
714
|
+
source: "complete",
|
|
821
715
|
status: "paused",
|
|
822
716
|
error: null
|
|
823
717
|
});
|
|
@@ -828,6 +722,7 @@ var PlaybackController = class {
|
|
|
828
722
|
this.publish({
|
|
829
723
|
sessionId,
|
|
830
724
|
messageId,
|
|
725
|
+
source: "complete",
|
|
831
726
|
status: "error",
|
|
832
727
|
error: "no-text"
|
|
833
728
|
});
|
|
@@ -840,6 +735,7 @@ var PlaybackController = class {
|
|
|
840
735
|
this.publish({
|
|
841
736
|
sessionId,
|
|
842
737
|
messageId,
|
|
738
|
+
source: "complete",
|
|
843
739
|
status: "loading",
|
|
844
740
|
error: null
|
|
845
741
|
});
|
|
@@ -863,33 +759,37 @@ var PlaybackController = class {
|
|
|
863
759
|
if (generation !== this.generation || this.activeSessionId !== sessionId) return;
|
|
864
760
|
const url = URL.createObjectURL(blob);
|
|
865
761
|
const audio = new Audio(url);
|
|
866
|
-
|
|
762
|
+
const current = {
|
|
867
763
|
url,
|
|
868
|
-
audio
|
|
764
|
+
audio,
|
|
765
|
+
onEnded: () => {
|
|
766
|
+
if (this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
|
|
767
|
+
this.releaseCurrentAudio(audio);
|
|
768
|
+
this.publish(this.emptyView());
|
|
769
|
+
},
|
|
770
|
+
onError: () => {
|
|
771
|
+
if (this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
|
|
772
|
+
this.releaseCurrentAudio(audio);
|
|
773
|
+
this.publish({
|
|
774
|
+
sessionId,
|
|
775
|
+
messageId,
|
|
776
|
+
source: "complete",
|
|
777
|
+
status: "error",
|
|
778
|
+
error: "play-failed"
|
|
779
|
+
});
|
|
780
|
+
}
|
|
869
781
|
};
|
|
782
|
+
this.current = current;
|
|
870
783
|
this.request = null;
|
|
871
|
-
audio.addEventListener("ended",
|
|
872
|
-
|
|
873
|
-
sessionId,
|
|
874
|
-
messageId,
|
|
875
|
-
status: "idle",
|
|
876
|
-
error: null
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
audio.addEventListener("error", () => {
|
|
880
|
-
if (this.activeSessionId === sessionId && this.current?.audio === audio) this.publish({
|
|
881
|
-
sessionId,
|
|
882
|
-
messageId,
|
|
883
|
-
status: "error",
|
|
884
|
-
error: "play-failed"
|
|
885
|
-
});
|
|
886
|
-
});
|
|
784
|
+
audio.addEventListener("ended", current.onEnded);
|
|
785
|
+
audio.addEventListener("error", current.onError);
|
|
887
786
|
try {
|
|
888
787
|
await audio.play();
|
|
889
788
|
if (generation !== this.generation || this.activeSessionId !== sessionId || this.current?.audio !== audio) return;
|
|
890
789
|
this.publish({
|
|
891
790
|
sessionId,
|
|
892
791
|
messageId,
|
|
792
|
+
source: "complete",
|
|
893
793
|
status: "playing",
|
|
894
794
|
error: null
|
|
895
795
|
});
|
|
@@ -898,6 +798,7 @@ var PlaybackController = class {
|
|
|
898
798
|
this.publish({
|
|
899
799
|
sessionId,
|
|
900
800
|
messageId,
|
|
801
|
+
source: "complete",
|
|
901
802
|
status: "paused",
|
|
902
803
|
error: automatic ? "autoplay-blocked" : "play-failed"
|
|
903
804
|
});
|
|
@@ -908,6 +809,7 @@ var PlaybackController = class {
|
|
|
908
809
|
this.publish({
|
|
909
810
|
sessionId,
|
|
910
811
|
messageId,
|
|
812
|
+
source: "complete",
|
|
911
813
|
status: "error",
|
|
912
814
|
error: error instanceof Error ? error.message : String(error)
|
|
913
815
|
});
|
|
@@ -925,18 +827,105 @@ var PlaybackController = class {
|
|
|
925
827
|
stopCurrent() {
|
|
926
828
|
this.request?.abort();
|
|
927
829
|
this.request = null;
|
|
928
|
-
if (this.current !== null)
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
830
|
+
if (this.current !== null) this.releaseCurrentAudio(this.current.audio);
|
|
831
|
+
}
|
|
832
|
+
releaseCurrentAudio(audio) {
|
|
833
|
+
if (this.current?.audio !== audio) return;
|
|
834
|
+
const current = this.current;
|
|
835
|
+
this.current = null;
|
|
836
|
+
audio.removeEventListener("ended", current.onEnded);
|
|
837
|
+
audio.removeEventListener("error", current.onError);
|
|
838
|
+
audio.pause();
|
|
839
|
+
audio.removeAttribute("src");
|
|
840
|
+
audio.load();
|
|
841
|
+
URL.revokeObjectURL(current.url);
|
|
842
|
+
}
|
|
843
|
+
emptyView() {
|
|
844
|
+
return {
|
|
845
|
+
sessionId: null,
|
|
846
|
+
messageId: null,
|
|
847
|
+
source: null,
|
|
848
|
+
status: "idle",
|
|
849
|
+
error: null
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
publish(view) {
|
|
853
|
+
if (this.view.sessionId === view.sessionId && this.view.messageId === view.messageId && this.view.source === view.source && this.view.status === view.status && this.view.error === view.error) return;
|
|
854
|
+
this.view = view;
|
|
855
|
+
for (const listener of this.listeners) listener();
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region src/client/settings-scope.ts
|
|
861
|
+
function isRecord(value) {
|
|
862
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
863
|
+
}
|
|
864
|
+
function decodeSettings(value) {
|
|
865
|
+
if (!isRecord(value)) return void 0;
|
|
866
|
+
const decoded = {};
|
|
867
|
+
if (typeof value.enabled === "boolean") decoded.enabled = value.enabled;
|
|
868
|
+
if (typeof value.apiKey === "string") decoded.apiKey = value.apiKey;
|
|
869
|
+
if (typeof value.baseURL === "string") decoded.baseURL = value.baseURL;
|
|
870
|
+
if (TTS_MODELS.includes(value.model)) decoded.model = value.model;
|
|
871
|
+
if (typeof value.voice === "string") decoded.voice = value.voice;
|
|
872
|
+
if (typeof value.voiceDesignPrompt === "string") decoded.voiceDesignPrompt = value.voiceDesignPrompt;
|
|
873
|
+
if (typeof value.voiceDesignCustomPrompt === "string") decoded.voiceDesignCustomPrompt = value.voiceDesignCustomPrompt;
|
|
874
|
+
if (value.format === "mp3" || value.format === "wav") decoded.format = value.format;
|
|
875
|
+
if (typeof value.autoPlay === "boolean") decoded.autoPlay = value.autoPlay;
|
|
876
|
+
if (typeof value.maxTextLength === "number") decoded.maxTextLength = value.maxTextLength;
|
|
877
|
+
if (typeof value.requestTimeoutMs === "number") decoded.requestTimeoutMs = value.requestTimeoutMs;
|
|
878
|
+
return decoded;
|
|
879
|
+
}
|
|
880
|
+
function useSettingsSnapshot(scope) {
|
|
881
|
+
const subscribe = (0, react.useCallback)((listener) => scope.subscribe(listener), [scope]);
|
|
882
|
+
const getSnapshot = (0, react.useCallback)(() => scope.getSnapshot(), [scope]);
|
|
883
|
+
return (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
//#endregion
|
|
887
|
+
//#region src/client/conversation.tsx
|
|
888
|
+
function messageText(snapshot, messageId) {
|
|
889
|
+
for (const node of snapshot.nodes) {
|
|
890
|
+
if (node.kind !== "assistant" || node.messageId !== messageId) continue;
|
|
891
|
+
return (0, __deepseek_ai_dsh_client_ui_primitives.extractMarkdownPlainText)(prepareTtsText(node.blocks.filter((block) => block.kind === "text").map((block) => block.text).join("\n\n"))).trim();
|
|
934
892
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
893
|
+
return "";
|
|
894
|
+
}
|
|
895
|
+
function messageTime(snapshot, messageId) {
|
|
896
|
+
for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return node.time;
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
function latestAssistantMessageId(snapshot) {
|
|
900
|
+
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
901
|
+
const node = snapshot.nodes[index];
|
|
902
|
+
if (node?.kind === "assistant" && node.messageId !== void 0) return node.messageId;
|
|
938
903
|
}
|
|
939
|
-
|
|
904
|
+
return null;
|
|
905
|
+
}
|
|
906
|
+
function assistantText(blocks) {
|
|
907
|
+
return blocks.filter((block) => block.kind === "text" && typeof block.text === "string").map((block) => block.text).join("\n\n");
|
|
908
|
+
}
|
|
909
|
+
function finalLiveMessage(snapshot, turn, step) {
|
|
910
|
+
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
911
|
+
const node = snapshot.nodes[index];
|
|
912
|
+
if (node?.kind === "assistant" && node.messageId !== void 0 && node.turn === turn && node.step === step) return {
|
|
913
|
+
messageId: node.messageId,
|
|
914
|
+
turn: node.turn,
|
|
915
|
+
step: node.step,
|
|
916
|
+
text: assistantText(node.blocks),
|
|
917
|
+
interrupted: node.interrupted === true
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
function messageLiveIdentity(snapshot, messageId) {
|
|
923
|
+
for (const node of snapshot.nodes) if (node.kind === "assistant" && node.messageId === messageId) return {
|
|
924
|
+
turn: node.turn,
|
|
925
|
+
step: node.step
|
|
926
|
+
};
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
940
929
|
/** Own the active-session boundary and feed its partial assistant output into realtime speech. */
|
|
941
930
|
function SessionPlaybackObserver({ sessionId, session, playback, live, settings }) {
|
|
942
931
|
const resolvedSettings = resolveTtsSettings(useSettingsSnapshot(settings).value);
|
|
@@ -1046,7 +1035,9 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1046
1035
|
if (settingsSnapshot.value?.enabled !== true || text.length === 0) return null;
|
|
1047
1036
|
const mine = view.sessionId === sessionId && view.messageId === messageId;
|
|
1048
1037
|
const status = mine ? view.status : "idle";
|
|
1049
|
-
const
|
|
1038
|
+
const source = mine ? view.source : null;
|
|
1039
|
+
const liveActive = source === "live" && (status === "loading" || status === "playing");
|
|
1040
|
+
const label = status === "loading" ? liveActive ? t("action.cancel") : t("action.loading") : status === "playing" ? liveActive ? t("action.stop") : t("action.pause") : status === "paused" ? t("action.resume") : status === "error" ? t("action.retry") : t("action.play");
|
|
1050
1041
|
const error = mine ? view.error : null;
|
|
1051
1042
|
const errorText = error === null ? null : error === "no-text" ? t("error.noText") : error === "autoplay-blocked" || error === "play-failed" ? t("error.play") : t("error.request");
|
|
1052
1043
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.Tooltip, {
|
|
@@ -1056,13 +1047,16 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1056
1047
|
type: "button",
|
|
1057
1048
|
className: "xmimo-tts-action",
|
|
1058
1049
|
"aria-label": label,
|
|
1059
|
-
"aria-pressed": status === "playing",
|
|
1060
|
-
disabled: status === "loading",
|
|
1050
|
+
"aria-pressed": status === "playing" || liveActive,
|
|
1051
|
+
disabled: status === "loading" && !liveActive,
|
|
1061
1052
|
onClick: () => {
|
|
1062
|
-
if (
|
|
1063
|
-
live.
|
|
1064
|
-
playback.
|
|
1053
|
+
if (mine && source === "live" && (status === "loading" || status === "playing")) {
|
|
1054
|
+
live.stop(sessionId);
|
|
1055
|
+
playback.cancelPlayback(sessionId);
|
|
1056
|
+
return;
|
|
1065
1057
|
}
|
|
1058
|
+
live.cancelSession(sessionId);
|
|
1059
|
+
playback.toggle(sessionId, messageId, text, false);
|
|
1066
1060
|
},
|
|
1067
1061
|
children: status === "loading" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconLoadingOutline16, { className: "xmimo-tts-spin" }) : status === "playing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconPauseOutline16, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconPlayOutline16, {})
|
|
1068
1062
|
})
|
|
@@ -1072,15 +1066,125 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1072
1066
|
children: errorText
|
|
1073
1067
|
})] });
|
|
1074
1068
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
"
|
|
1081
|
-
"
|
|
1082
|
-
"
|
|
1083
|
-
|
|
1069
|
+
|
|
1070
|
+
//#endregion
|
|
1071
|
+
//#region src/client/localization.ts
|
|
1072
|
+
const NS = "xiaomi-mimo-tts";
|
|
1073
|
+
const zh = {
|
|
1074
|
+
"action.play": "朗读回复",
|
|
1075
|
+
"action.pause": "暂停朗读",
|
|
1076
|
+
"action.resume": "继续朗读",
|
|
1077
|
+
"action.loading": "正在生成语音",
|
|
1078
|
+
"action.cancel": "取消语音生成",
|
|
1079
|
+
"action.stop": "停止朗读",
|
|
1080
|
+
"action.retry": "重新生成语音",
|
|
1081
|
+
"error.noText": "这条回复没有可朗读的正文。",
|
|
1082
|
+
"error.request": "语音生成失败。",
|
|
1083
|
+
"error.play": "浏览器阻止了自动播放,请点击朗读按钮。",
|
|
1084
|
+
"settings.title": "语音朗读 (Xiaomi MiMo)",
|
|
1085
|
+
"settings.description": "在助手回复操作栏中使用 Xiaomi MiMo TTS 生成并播放语音。",
|
|
1086
|
+
"settings.enabled": "显示朗读按钮",
|
|
1087
|
+
"settings.enabledHint": "关闭后不会在助手回复操作栏显示朗读按钮,也不会自动播报。",
|
|
1088
|
+
"settings.apiKey": "API Key",
|
|
1089
|
+
"settings.apiKeyStatus": "只有输入新值并保存时才会替换现有密钥。",
|
|
1090
|
+
"settings.apiKeyConfigured": "已配置",
|
|
1091
|
+
"settings.apiKeyMissing": "尚未配置 API Key,请先获取并设置密钥。",
|
|
1092
|
+
"settings.apiKeyUnsupported": "这个 API Key 似乎是错的,请检查并重新设置(sk-/tp- 开头)。",
|
|
1093
|
+
"settings.getApiKey": "获取 API Key",
|
|
1094
|
+
"settings.autoPlay": "开启自动播报",
|
|
1095
|
+
"settings.autoPlayHint": "开启时会同步显示朗读按钮;浏览器也可能拒绝自动播放。",
|
|
1096
|
+
"settings.model": "TTS 模型",
|
|
1097
|
+
"settings.presetModel": "预置音色模型 (mimo-v2.5-tts)",
|
|
1098
|
+
"settings.voiceDesignModel": "自定义音色模型 (mimo-v2.5-tts-voicedesign)",
|
|
1099
|
+
"settings.modelAutoPlayHintPreset": "预置音色模型支持实时流式播放。",
|
|
1100
|
+
"settings.modelAutoPlayHintVoiceDesign": "自定义音色仅支持在回复完成后自动播放。",
|
|
1101
|
+
"settings.voice": "内置音色",
|
|
1102
|
+
"settings.voiceDesignPrompt": "自定义音色描述",
|
|
1103
|
+
"settings.customVoiceOption": "自定义",
|
|
1104
|
+
"settings.customVoiceSummary": "手动编写音色描述",
|
|
1105
|
+
"settings.voiceDesignPromptHint": "按“年龄段 + 性别、声音质感、语速节奏、情绪底色”描述声音本身;不写场景或动作。",
|
|
1106
|
+
"settings.format": "音频格式",
|
|
1107
|
+
"settings.save": "保存",
|
|
1108
|
+
"settings.saving": "保存中…",
|
|
1109
|
+
"settings.saved": "已保存",
|
|
1110
|
+
"settings.unsaved": "未保存",
|
|
1111
|
+
"settings.overridden": "已覆盖",
|
|
1112
|
+
"settings.reset": "恢复默认",
|
|
1113
|
+
"settings.discard": "放弃修改",
|
|
1114
|
+
"settings.failed": "保存失败,请重试。",
|
|
1115
|
+
"settings.source": "✨查看源码",
|
|
1116
|
+
"settings.uninstall": "卸载",
|
|
1117
|
+
"settings.uninstalling": "卸载中…",
|
|
1118
|
+
"settings.uninstallQuestion": "确认卸载?",
|
|
1119
|
+
"settings.uninstallConfirm": "确认",
|
|
1120
|
+
"settings.uninstallCancel": "取消",
|
|
1121
|
+
"settings.uninstalled": "已卸载;重启DSH不再加载此插件。",
|
|
1122
|
+
"settings.uninstallFailed": "卸载失败,请重试或使用 DSH 命令行卸载。",
|
|
1123
|
+
"settings.updateAvailable": "🎉新版已发布",
|
|
1124
|
+
"settings.readOnly": "当前 DSH 设置为只读。",
|
|
1125
|
+
"settings.secretPlaceholder": "输入新的 Xiaomi MiMo API Key",
|
|
1126
|
+
"settings.expand": "展开设置",
|
|
1127
|
+
"settings.collapse": "收起设置"
|
|
1128
|
+
};
|
|
1129
|
+
const en = {
|
|
1130
|
+
"action.play": "Read aloud",
|
|
1131
|
+
"action.pause": "Pause speech",
|
|
1132
|
+
"action.resume": "Resume speech",
|
|
1133
|
+
"action.loading": "Generating speech",
|
|
1134
|
+
"action.cancel": "Cancel speech generation",
|
|
1135
|
+
"action.stop": "Stop speech",
|
|
1136
|
+
"action.retry": "Generate speech again",
|
|
1137
|
+
"error.noText": "This response has no readable body text.",
|
|
1138
|
+
"error.request": "Speech generation failed.",
|
|
1139
|
+
"error.play": "The browser blocked autoplay. Click Read aloud to play it.",
|
|
1140
|
+
"settings.title": "Text To Speech (Xiaomi MiMo)",
|
|
1141
|
+
"settings.description": "Generate and play Xiaomi MiMo TTS audio from assistant message actions.",
|
|
1142
|
+
"settings.enabled": "Show read-aloud button",
|
|
1143
|
+
"settings.enabledHint": "When disabled, the read-aloud button and automatic speech are both turned off.",
|
|
1144
|
+
"settings.apiKey": "API Key",
|
|
1145
|
+
"settings.apiKeyStatus": "An existing key changes only when you save a new value.",
|
|
1146
|
+
"settings.apiKeyConfigured": "Configured",
|
|
1147
|
+
"settings.apiKeyMissing": "No API key is configured. Get and set an API key first.",
|
|
1148
|
+
"settings.apiKeyUnsupported": "This API key seems invalid. Check it and set it again (starting with sk- or tp-).",
|
|
1149
|
+
"settings.getApiKey": "Get API Key",
|
|
1150
|
+
"settings.autoPlay": "Enable automatic read-aloud",
|
|
1151
|
+
"settings.autoPlayHint": "Enabling it also shows the read-aloud button; the browser may reject autoplay.",
|
|
1152
|
+
"settings.model": "TTS model",
|
|
1153
|
+
"settings.presetModel": "Preset voices (mimo-v2.5-tts)",
|
|
1154
|
+
"settings.voiceDesignModel": "Custom voice design (mimo-v2.5-tts-voicedesign)",
|
|
1155
|
+
"settings.modelAutoPlayHintPreset": "Preset voices support realtime streaming playback.",
|
|
1156
|
+
"settings.modelAutoPlayHintVoiceDesign": "Custom voice design supports automatic playback only after the reply is complete.",
|
|
1157
|
+
"settings.voice": "Built-in voice",
|
|
1158
|
+
"settings.voiceDesignPrompt": "Custom voice description",
|
|
1159
|
+
"settings.customVoiceOption": "Custom",
|
|
1160
|
+
"settings.customVoiceSummary": "Write a custom voice description",
|
|
1161
|
+
"settings.voiceDesignPromptHint": "Describe the voice itself with age/gender, texture, pace, and emotional baseline; avoid scenes or actions.",
|
|
1162
|
+
"settings.format": "Audio format",
|
|
1163
|
+
"settings.save": "Save",
|
|
1164
|
+
"settings.saving": "Saving…",
|
|
1165
|
+
"settings.saved": "Saved",
|
|
1166
|
+
"settings.unsaved": "Unsaved",
|
|
1167
|
+
"settings.overridden": "Overridden",
|
|
1168
|
+
"settings.reset": "Restore default",
|
|
1169
|
+
"settings.discard": "Discard changes",
|
|
1170
|
+
"settings.failed": "Save failed. Try again.",
|
|
1171
|
+
"settings.source": "✨ View source",
|
|
1172
|
+
"settings.uninstall": "Uninstall",
|
|
1173
|
+
"settings.uninstalling": "Uninstalling…",
|
|
1174
|
+
"settings.uninstallQuestion": "Confirm uninstall?",
|
|
1175
|
+
"settings.uninstallConfirm": "Confirm",
|
|
1176
|
+
"settings.uninstallCancel": "Cancel",
|
|
1177
|
+
"settings.uninstalled": "Uninstalled. DSH remains active and will not load the plugin on its next start.",
|
|
1178
|
+
"settings.uninstallFailed": "Uninstall failed. Try again or remove the plugin with the DSH CLI.",
|
|
1179
|
+
"settings.updateAvailable": "🎉 New release",
|
|
1180
|
+
"settings.readOnly": "DSH settings are read-only.",
|
|
1181
|
+
"settings.secretPlaceholder": "Enter a new Xiaomi MiMo API key",
|
|
1182
|
+
"settings.expand": "Expand settings",
|
|
1183
|
+
"settings.collapse": "Collapse settings"
|
|
1184
|
+
};
|
|
1185
|
+
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region src/client/voice-design-picker.tsx
|
|
1084
1188
|
const CUSTOM_VOICE_DESIGN_OPTION = "__custom__";
|
|
1085
1189
|
function isPresetVoiceDesignPrompt(value) {
|
|
1086
1190
|
return TTS_VOICE_DESIGN_PRESETS.some((item) => item.prompt === value);
|
|
@@ -1252,6 +1356,23 @@ function VoiceDesignPresetPicker({ value, disabled, label, customLabel, customSu
|
|
|
1252
1356
|
}) : null]
|
|
1253
1357
|
});
|
|
1254
1358
|
}
|
|
1359
|
+
|
|
1360
|
+
//#endregion
|
|
1361
|
+
//#region src/client/settings-card.tsx
|
|
1362
|
+
const EDITABLE_SETTING_FIELDS = [
|
|
1363
|
+
"enabled",
|
|
1364
|
+
"autoPlay",
|
|
1365
|
+
"model",
|
|
1366
|
+
"voice",
|
|
1367
|
+
"voiceDesignPrompt",
|
|
1368
|
+
"voiceDesignCustomPrompt",
|
|
1369
|
+
"format"
|
|
1370
|
+
];
|
|
1371
|
+
const RELEASES_URL = "https://github.com/ppy-web/dsh-plugin-xiaomi-mimo-tts/releases";
|
|
1372
|
+
function hostRoute(path) {
|
|
1373
|
+
const relative = path.replace(/^\/+/, "");
|
|
1374
|
+
return typeof document === "undefined" ? `/${relative}` : new URL(relative, document.baseURI).pathname;
|
|
1375
|
+
}
|
|
1255
1376
|
function layerSettings(value) {
|
|
1256
1377
|
return isRecord(value) ? value : void 0;
|
|
1257
1378
|
}
|
|
@@ -1297,7 +1418,10 @@ function SettingsCard({ scope, t }) {
|
|
|
1297
1418
|
const [format, setFormat] = (0, react.useState)(initial.format);
|
|
1298
1419
|
const [changes, setChanges] = (0, react.useState)({});
|
|
1299
1420
|
const [state, setState] = (0, react.useState)("idle");
|
|
1421
|
+
const [uninstallState, setUninstallState] = (0, react.useState)("idle");
|
|
1300
1422
|
const [open, setOpen] = (0, react.useState)(false);
|
|
1423
|
+
const [apiKeyStatus, setApiKeyStatus] = (0, react.useState)("loading");
|
|
1424
|
+
const [latestVersion, setLatestVersion] = (0, react.useState)(null);
|
|
1301
1425
|
const accepted = resolveTtsSettings(value);
|
|
1302
1426
|
const base = resolveTtsSettings(layerSettings(snapshot.base));
|
|
1303
1427
|
const draft = {
|
|
@@ -1328,6 +1452,45 @@ function SettingsCard({ scope, t }) {
|
|
|
1328
1452
|
};
|
|
1329
1453
|
const apiKeyDirty = changes.apiKey?.kind === "clear" ? hasOverride("apiKey") : changes.apiKey?.kind === "set" && apiKey.trim().length > 0;
|
|
1330
1454
|
const dirty = EDITABLE_SETTING_FIELDS.some(fieldDirty) || apiKeyDirty === true;
|
|
1455
|
+
const enteredApiKey = apiKey.trim();
|
|
1456
|
+
const apiKeyWarning = enteredApiKey.length > 0 ? !isSupportedTtsApiKey(enteredApiKey) : apiKeyStatus === "missing" || apiKeyStatus === "unsupported";
|
|
1457
|
+
const apiKeyMessage = enteredApiKey.length > 0 ? isSupportedTtsApiKey(enteredApiKey) ? t("settings.apiKeyStatus") : t("settings.apiKeyUnsupported") : apiKeyStatus === "missing" ? t("settings.apiKeyMissing") : apiKeyStatus === "unsupported" ? t("settings.apiKeyUnsupported") : t("settings.apiKeyStatus");
|
|
1458
|
+
(0, react.useEffect)(() => {
|
|
1459
|
+
if (snapshot.status === "unavailable") return;
|
|
1460
|
+
let active = true;
|
|
1461
|
+
setApiKeyStatus("loading");
|
|
1462
|
+
fetch(TTS_API_KEY_STATUS_ROUTE, { headers: { accept: "application/json" } }).then(async (response) => {
|
|
1463
|
+
if (!response.ok) throw new Error("api-key-status-failed");
|
|
1464
|
+
return await response.json();
|
|
1465
|
+
}).then((status) => {
|
|
1466
|
+
if (!active) return;
|
|
1467
|
+
setApiKeyStatus(status.configured !== true ? "missing" : status.supported === true ? "supported" : "unsupported");
|
|
1468
|
+
}).catch(() => {
|
|
1469
|
+
if (active) setApiKeyStatus("missing");
|
|
1470
|
+
});
|
|
1471
|
+
return () => {
|
|
1472
|
+
active = false;
|
|
1473
|
+
};
|
|
1474
|
+
}, [snapshot.status, value]);
|
|
1475
|
+
(0, react.useEffect)(() => {
|
|
1476
|
+
if (!open) return;
|
|
1477
|
+
let active = true;
|
|
1478
|
+
fetch(hostRoute(TTS_UPDATE_ROUTE), {
|
|
1479
|
+
cache: "no-store",
|
|
1480
|
+
headers: { accept: "application/json" }
|
|
1481
|
+
}).then(async (response) => {
|
|
1482
|
+
if (!response.ok) throw new Error("version-check-failed");
|
|
1483
|
+
return await response.json();
|
|
1484
|
+
}).then((result) => {
|
|
1485
|
+
if (!active) return;
|
|
1486
|
+
setLatestVersion(result.updateAvailable === true && typeof result.latestVersion === "string" ? result.latestVersion : null);
|
|
1487
|
+
}).catch(() => {
|
|
1488
|
+
if (active) setLatestVersion(null);
|
|
1489
|
+
});
|
|
1490
|
+
return () => {
|
|
1491
|
+
active = false;
|
|
1492
|
+
};
|
|
1493
|
+
}, [open]);
|
|
1331
1494
|
(0, react.useEffect)(() => {
|
|
1332
1495
|
if (dirty) return;
|
|
1333
1496
|
const next = resolveTtsSettings(value);
|
|
@@ -1392,6 +1555,21 @@ function SettingsCard({ scope, t }) {
|
|
|
1392
1555
|
setState("failed");
|
|
1393
1556
|
}
|
|
1394
1557
|
};
|
|
1558
|
+
const uninstall = async () => {
|
|
1559
|
+
setUninstallState("uninstalling");
|
|
1560
|
+
try {
|
|
1561
|
+
const response = await fetch(hostRoute(TTS_UNINSTALL_ROUTE), {
|
|
1562
|
+
method: "POST",
|
|
1563
|
+
headers: { "content-type": "application/json" },
|
|
1564
|
+
body: "{}"
|
|
1565
|
+
});
|
|
1566
|
+
const result = await response.json();
|
|
1567
|
+
if (!response.ok || result.ok !== true) throw new Error("plugin-uninstall-failed");
|
|
1568
|
+
setUninstallState("uninstalled");
|
|
1569
|
+
} catch {
|
|
1570
|
+
setUninstallState("failed");
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1395
1573
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
1396
1574
|
className: open ? "xmimo-tts-card xmimo-tts-card-open" : "xmimo-tts-card",
|
|
1397
1575
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
@@ -1405,9 +1583,16 @@ function SettingsCard({ scope, t }) {
|
|
|
1405
1583
|
children: [
|
|
1406
1584
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1407
1585
|
className: "xmimo-tts-card-head-text",
|
|
1408
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1586
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1409
1587
|
className: "xmimo-tts-card-title",
|
|
1410
|
-
children:
|
|
1588
|
+
children: [
|
|
1589
|
+
t("settings.title"),
|
|
1590
|
+
" ",
|
|
1591
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", {
|
|
1592
|
+
className: "xmimo-tts-version",
|
|
1593
|
+
children: ["v", TTS_VERSION]
|
|
1594
|
+
})
|
|
1595
|
+
]
|
|
1411
1596
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1412
1597
|
className: "xmimo-tts-card-description",
|
|
1413
1598
|
children: t("settings.description")
|
|
@@ -1460,9 +1645,10 @@ function SettingsCard({ scope, t }) {
|
|
|
1460
1645
|
markChange("apiKey");
|
|
1461
1646
|
}
|
|
1462
1647
|
}),
|
|
1463
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1464
|
-
className: "xmimo-tts-api-key-
|
|
1465
|
-
|
|
1648
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
1649
|
+
className: apiKeyWarning ? "xmimo-tts-api-key-warning" : void 0,
|
|
1650
|
+
role: apiKeyWarning ? "alert" : void 0,
|
|
1651
|
+
children: apiKeyMessage
|
|
1466
1652
|
})
|
|
1467
1653
|
]
|
|
1468
1654
|
}),
|
|
@@ -1470,64 +1656,84 @@ function SettingsCard({ scope, t }) {
|
|
|
1470
1656
|
className: "xmimo-tts-switch-row xmimo-tts-wide",
|
|
1471
1657
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
1472
1658
|
className: "xmimo-tts-checkbox-row",
|
|
1473
|
-
children: [
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
enabled
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1659
|
+
children: [
|
|
1660
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1661
|
+
className: "xmimo-tts-switch-copy",
|
|
1662
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
|
|
1663
|
+
label: t("settings.enabled"),
|
|
1664
|
+
overriddenLabel: t("settings.overridden"),
|
|
1665
|
+
resetLabel: t("settings.reset"),
|
|
1666
|
+
overridden: false,
|
|
1667
|
+
resettable: false,
|
|
1668
|
+
disabled: !snapshot.writable,
|
|
1669
|
+
onReset: () => {
|
|
1670
|
+
resetField("enabled");
|
|
1671
|
+
}
|
|
1672
|
+
})
|
|
1673
|
+
}),
|
|
1674
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1675
|
+
type: "checkbox",
|
|
1676
|
+
checked: enabled,
|
|
1677
|
+
disabled: !snapshot.writable,
|
|
1678
|
+
onChange: (event) => {
|
|
1679
|
+
const next = event.target.checked;
|
|
1680
|
+
setEnabled(next);
|
|
1681
|
+
if (!next) {
|
|
1682
|
+
setAutoPlay(false);
|
|
1683
|
+
setChanges((current) => ({
|
|
1684
|
+
...current,
|
|
1685
|
+
enabled: { kind: "set" },
|
|
1686
|
+
autoPlay: { kind: "set" }
|
|
1687
|
+
}));
|
|
1688
|
+
} else markChange("enabled");
|
|
1689
|
+
setState("idle");
|
|
1690
|
+
}
|
|
1691
|
+
}),
|
|
1692
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1693
|
+
className: "xmimo-tts-switch-control",
|
|
1694
|
+
"aria-hidden": "true"
|
|
1695
|
+
})
|
|
1696
|
+
]
|
|
1501
1697
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
1502
1698
|
className: "xmimo-tts-checkbox-row",
|
|
1503
|
-
children: [
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
autoPlay
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1699
|
+
children: [
|
|
1700
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1701
|
+
className: "xmimo-tts-switch-copy",
|
|
1702
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
|
|
1703
|
+
label: t("settings.autoPlay"),
|
|
1704
|
+
overriddenLabel: t("settings.overridden"),
|
|
1705
|
+
resetLabel: t("settings.reset"),
|
|
1706
|
+
overridden: false,
|
|
1707
|
+
resettable: false,
|
|
1708
|
+
disabled: !snapshot.writable,
|
|
1709
|
+
onReset: () => {
|
|
1710
|
+
resetField("autoPlay");
|
|
1711
|
+
}
|
|
1712
|
+
})
|
|
1713
|
+
}),
|
|
1714
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1715
|
+
type: "checkbox",
|
|
1716
|
+
checked: enabled && autoPlay,
|
|
1717
|
+
disabled: !snapshot.writable,
|
|
1718
|
+
onChange: (event) => {
|
|
1719
|
+
const next = event.target.checked;
|
|
1720
|
+
setAutoPlay(next);
|
|
1721
|
+
if (next) {
|
|
1722
|
+
setEnabled(true);
|
|
1723
|
+
setChanges((current) => ({
|
|
1724
|
+
...current,
|
|
1725
|
+
autoPlay: { kind: "set" },
|
|
1726
|
+
enabled: { kind: "set" }
|
|
1727
|
+
}));
|
|
1728
|
+
} else markChange("autoPlay");
|
|
1729
|
+
setState("idle");
|
|
1730
|
+
}
|
|
1731
|
+
}),
|
|
1732
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1733
|
+
className: "xmimo-tts-switch-control",
|
|
1734
|
+
"aria-hidden": "true"
|
|
1735
|
+
})
|
|
1736
|
+
]
|
|
1531
1737
|
})]
|
|
1532
1738
|
}),
|
|
1533
1739
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -1607,9 +1813,9 @@ function SettingsCard({ scope, t }) {
|
|
|
1607
1813
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.voiceDesignPromptHint") })
|
|
1608
1814
|
]
|
|
1609
1815
|
}) : null,
|
|
1610
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1611
|
-
className:
|
|
1612
|
-
children: [
|
|
1816
|
+
model === "mimo-v2.5-tts" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1817
|
+
className: "xmimo-tts-select-column xmimo-tts-wide",
|
|
1818
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
|
|
1613
1819
|
label: t("settings.voice"),
|
|
1614
1820
|
overriddenLabel: t("settings.overridden"),
|
|
1615
1821
|
resetLabel: t("settings.reset"),
|
|
@@ -1630,7 +1836,7 @@ function SettingsCard({ scope, t }) {
|
|
|
1630
1836
|
value: item,
|
|
1631
1837
|
children: item
|
|
1632
1838
|
}, item))
|
|
1633
|
-
})] })
|
|
1839
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
|
|
1634
1840
|
label: t("settings.format"),
|
|
1635
1841
|
overriddenLabel: t("settings.overridden"),
|
|
1636
1842
|
resetLabel: t("settings.reset"),
|
|
@@ -1655,12 +1861,62 @@ function SettingsCard({ scope, t }) {
|
|
|
1655
1861
|
children: "WAV"
|
|
1656
1862
|
})]
|
|
1657
1863
|
})] })]
|
|
1658
|
-
})
|
|
1864
|
+
}) : null
|
|
1659
1865
|
]
|
|
1660
1866
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1661
1867
|
className: "xmimo-tts-card-actions",
|
|
1662
1868
|
children: [
|
|
1869
|
+
uninstallState === "idle" && latestVersion !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1870
|
+
className: "xmimo-tts-update",
|
|
1871
|
+
href: RELEASES_URL,
|
|
1872
|
+
target: "_blank",
|
|
1873
|
+
rel: "noopener noreferrer",
|
|
1874
|
+
children: t("settings.updateAvailable")
|
|
1875
|
+
}) : null,
|
|
1876
|
+
uninstallState === "confirming" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1877
|
+
className: "xmimo-tts-uninstall-confirmation",
|
|
1878
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.uninstallQuestion") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1879
|
+
className: "xmimo-tts-uninstall-choice",
|
|
1880
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1881
|
+
type: "button",
|
|
1882
|
+
onClick: () => {
|
|
1883
|
+
uninstall();
|
|
1884
|
+
},
|
|
1885
|
+
children: t("settings.uninstallConfirm")
|
|
1886
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1887
|
+
type: "button",
|
|
1888
|
+
onClick: () => {
|
|
1889
|
+
setUninstallState("idle");
|
|
1890
|
+
},
|
|
1891
|
+
children: t("settings.uninstallCancel")
|
|
1892
|
+
})]
|
|
1893
|
+
})]
|
|
1894
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1895
|
+
type: "button",
|
|
1896
|
+
className: "xmimo-tts-uninstall",
|
|
1897
|
+
disabled: uninstallState === "uninstalling" || uninstallState === "uninstalled",
|
|
1898
|
+
onClick: () => {
|
|
1899
|
+
setUninstallState("confirming");
|
|
1900
|
+
},
|
|
1901
|
+
children: uninstallState === "uninstalling" ? t("settings.uninstalling") : t("settings.uninstall")
|
|
1902
|
+
}),
|
|
1903
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
1904
|
+
className: "xmimo-tts-star",
|
|
1905
|
+
href: "https://github.com/ppy-web/dsh-plugin-xiaomi-mimo-tts",
|
|
1906
|
+
target: "_blank",
|
|
1907
|
+
rel: "noopener noreferrer",
|
|
1908
|
+
children: t("settings.source")
|
|
1909
|
+
}),
|
|
1663
1910
|
!snapshot.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("settings.readOnly") }) : null,
|
|
1911
|
+
uninstallState === "uninstalled" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1912
|
+
role: "status",
|
|
1913
|
+
children: t("settings.uninstalled")
|
|
1914
|
+
}) : null,
|
|
1915
|
+
uninstallState === "failed" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1916
|
+
className: "xmimo-tts-failed",
|
|
1917
|
+
role: "status",
|
|
1918
|
+
children: t("settings.uninstallFailed")
|
|
1919
|
+
}) : null,
|
|
1664
1920
|
state === "saved" && !dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1665
1921
|
role: "status",
|
|
1666
1922
|
children: t("settings.saved")
|
|
@@ -1690,6 +1946,51 @@ function SettingsCard({ scope, t }) {
|
|
|
1690
1946
|
}) : null]
|
|
1691
1947
|
});
|
|
1692
1948
|
}
|
|
1949
|
+
|
|
1950
|
+
//#endregion
|
|
1951
|
+
//#region src/client/styles.ts
|
|
1952
|
+
const CLIENT_STYLES = `
|
|
1953
|
+
.xmimo-tts-action{width:28px;height:28px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:transparent;border:none;border-radius:28px;justify-content:center;align-items:center;padding:6px;display:inline-flex}.xmimo-tts-action:hover{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action:disabled{cursor:default;opacity:.45}.xmimo-tts-spin{animation:xmimo-spin 1s linear infinite}@keyframes xmimo-spin{to{transform:rotate(360deg)}}
|
|
1954
|
+
.xmimo-tts-inline-error{max-width:220px;color:var(--dsw-alias-state-error-primary,#dc2626);font-size:12px}
|
|
1955
|
+
.xmimo-tts-api-key-warning{color:var(--dsw-alias-state-error-primary,#dc2626)!important}
|
|
1956
|
+
.xmimo-tts-card{list-style:none;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:12px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-3,#fff);overflow:hidden;transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-card:hover{border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-open{background:var(--dsw-alias-bg-layer-2,#f7f8fa);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-header{appearance:none;display:flex;width:100%;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border:0;border-radius:12px;color:inherit;text-align:left;background:transparent;font:inherit;cursor:pointer}.xmimo-tts-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:-2px}.xmimo-tts-card-head-text{display:flex;min-width:0;flex:1;flex-direction:column;gap:4px}.xmimo-tts-card-title{font-size:15px;font-weight:600}.xmimo-tts-card-description{color:var(--dsw-alias-label-tertiary,#8b93a1);font-size:13px;line-height:18px}.xmimo-tts-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-chevron-open{transform:rotate(180deg)}.xmimo-tts-pending{flex:none;border-radius:999px;padding:1px 8px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;font-weight:500;line-height:17px}.xmimo-tts-card-body{border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);margin:0 16px;padding:0 0 16px}
|
|
1957
|
+
.xmimo-tts-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:0;align-items:start}.xmimo-tts-grid>*{box-sizing:border-box;padding:16px 0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb)}.xmimo-tts-grid>:first-child{border-top:0}.xmimo-tts-grid label,.xmimo-tts-api-key,.xmimo-tts-model,.xmimo-tts-voice-design-prompt,.xmimo-tts-select-column>div{display:flex;min-width:0;flex-direction:column;gap:6px;font-size:13px}.xmimo-tts-grid input,.xmimo-tts-grid select,.xmimo-tts-grid textarea{box-sizing:border-box;width:100%;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;padding:8px 10px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit}.xmimo-tts-grid select{color-scheme:light dark}.xmimo-tts-grid select option{color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-grid select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-grid small{color:var(--dsw-alias-label-tertiary,#8b93a1);line-height:17px}.xmimo-tts-field-heading{display:flex;min-width:0;min-height:20px;flex-direction:row!important;align-items:center;justify-content:space-between;gap:8px}.xmimo-tts-field-label{display:inline-flex;min-width:0;align-items:center;gap:8px}.xmimo-tts-api-key-link{color:var(--dsw-alias-brand-primary,#4f6ef7);font-size:12px;text-decoration:none}.xmimo-tts-api-key-link:hover{text-decoration:underline}.xmimo-tts-field-badges{display:flex!important;flex:none;flex-direction:row!important;align-items:center;gap:8px}.xmimo-tts-overridden{border-radius:999px;padding:1px 7px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;line-height:17px}.xmimo-tts-reset{padding:0;border:0;color:var(--dsw-alias-label-secondary,#5f6875);background:transparent;font:inherit;font-size:12px;cursor:pointer}.xmimo-tts-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328)}.xmimo-tts-reset:disabled{cursor:not-allowed;opacity:.45}.xmimo-tts-api-key-hints{display:flex;min-width:0;gap:8px;align-items:center}.xmimo-tts-api-key-hints small{min-width:0;white-space:nowrap}.xmimo-tts-wide{grid-column:1/-1}.xmimo-tts-switch-row{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:0}.xmimo-tts-switch-row>*:first-child{padding-right:14px}.xmimo-tts-switch-row>*+*{padding-left:14px;border-left:1px solid var(--dsw-alias-border-l2,#e5e7eb)}.xmimo-tts-checkbox-row{position:relative;flex-direction:row!important;align-items:center!important;gap:10px!important;cursor:pointer}.xmimo-tts-switch-copy{display:flex;min-width:0;flex-direction:column;gap:4px}.xmimo-tts-checkbox-row>input{position:absolute;width:1px!important;height:1px;margin:0!important;padding:0!important;overflow:hidden;border:0!important;opacity:0;clip-path:inset(50%)}.xmimo-tts-switch-control{box-sizing:border-box;position:relative;display:inline-block!important;width:36px;height:20px;min-width:36px;flex:none;border:1px solid var(--dsw-alias-border-l2,#c8ccd4);border-radius:999px;background:var(--dsw-alias-bg-module-platform,#e5e7eb);transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-switch-control:after{content:"";position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 1px 3px rgba(15,23,42,.24);transition:transform 160ms ease}.xmimo-tts-checkbox-row>input:checked+.xmimo-tts-switch-control{border-color:var(--dsw-alias-brand-primary,#4f6ef7);background:var(--dsw-alias-brand-primary,#4f6ef7)}.xmimo-tts-checkbox-row>input:checked+.xmimo-tts-switch-control:after{transform:translateX(16px)}.xmimo-tts-checkbox-row>input:focus-visible+.xmimo-tts-switch-control{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:2px}.xmimo-tts-checkbox-row>input:disabled+.xmimo-tts-switch-control{cursor:not-allowed;opacity:.45}.xmimo-tts-select-column{display:flex;min-width:0;flex-direction:row;gap:0}.xmimo-tts-select-column>div{flex:1}.xmimo-tts-select-column>div:first-child:not(:only-child){padding-right:16px}.xmimo-tts-select-column>div+div{padding-left:16px;border-left:1px solid var(--dsw-alias-border-l2,#e5e7eb)}
|
|
1958
|
+
.xmimo-tts-voice-picker{display:flex;min-width:0;flex-direction:column;gap:6px}.xmimo-tts-voice-picker-trigger,.xmimo-tts-voice-option{box-sizing:border-box;display:flex;width:100%;min-width:0;align-items:center;gap:10px;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit;text-align:left;cursor:pointer}.xmimo-tts-voice-picker-trigger{min-height:54px;border-radius:10px;padding:6px 10px}.xmimo-tts-voice-picker-trigger:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,#c8ccd4);background:var(--dsw-alias-interactive-bg-hover,#eef0f3)}.xmimo-tts-voice-picker-trigger:focus-visible,.xmimo-tts-voice-option:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-voice-picker-trigger:disabled{cursor:not-allowed;opacity:.55}.xmimo-tts-voice-avatar{box-sizing:border-box;display:block;width:40px;height:40px;flex:none;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,#e5e7eb) 80%,transparent);border-radius:50%;object-fit:cover;background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-custom-voice-avatar{display:grid;place-items:center;color:var(--dsw-alias-brand-primary,#4f6ef7);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 12%,var(--dsw-alias-bg-layer-1,#fff))}.xmimo-tts-custom-voice-avatar svg{width:30px;height:30px;overflow:visible}.xmimo-tts-custom-voice-avatar circle{fill:currentColor}.xmimo-tts-custom-voice-avatar path{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.xmimo-tts-voice-option-copy{display:flex;min-width:0;flex:1;flex-direction:column;gap:1px}.xmimo-tts-voice-option-copy strong{overflow:hidden;font-size:13px;font-weight:600;line-height:18px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-option-copy small{overflow:hidden;font-size:12px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-picker-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-voice-picker-chevron-open{transform:rotate(180deg)}.xmimo-tts-voice-picker-menu{display:grid;max-height:310px;overflow:auto;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:10px;padding:5px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 28px rgba(15,23,42,.12)}.xmimo-tts-voice-option{min-height:50px;border:0;border-radius:7px;padding:5px 7px;background:transparent}.xmimo-tts-voice-option:hover,.xmimo-tts-voice-option:focus-visible{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6)}.xmimo-tts-voice-option-selected{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 10%,transparent)}
|
|
1959
|
+
.xmimo-tts-card-actions{display:flex;align-items:center;justify-content:flex-end;gap:10px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1)}.xmimo-tts-card-actions button{border:1px solid var(--dsw-alias-brand-primary,#4f6ef7);border-radius:8px;padding:5px 14px;color:var(--dsw-alias-bg-layer-1,#fff);background:var(--dsw-alias-brand-primary,#4f6ef7);cursor:pointer;font:inherit}.xmimo-tts-card-actions button:hover:not(:disabled){filter:brightness(1.08)}.xmimo-tts-card-actions button:disabled{cursor:not-allowed;color:var(--dsw-alias-label-dimmed,#9ca3af);background:var(--dsw-alias-bg-layer-2,#f3f4f6);border-color:var(--dsw-alias-border-l2,#e5e7eb);opacity:1}.xmimo-tts-card-actions .xmimo-tts-update{display:inline-flex;align-items:center;border:1px solid var(--dsw-alias-brand-primary,#4f6ef7);border-radius:8px;padding:5px 14px;color:var(--dsw-alias-brand-primary,#4f6ef7);background:transparent;text-decoration:none}.xmimo-tts-card-actions .xmimo-tts-update:hover{filter:brightness(1.08)}.xmimo-tts-card-actions .xmimo-tts-star{border-color:transparent;color:var(--dsw-alias-brand-primary,#4f6ef7);background:transparent;font-weight:500}.xmimo-tts-card-actions .xmimo-tts-star:hover{text-decoration:underline}.xmimo-tts-card-actions .xmimo-tts-uninstall{margin-right:auto;border-color:#F56C6C;color:#F56C6C;background:transparent}.xmimo-tts-card-actions .xmimo-tts-uninstall:hover:not(:disabled){background:color-mix(in srgb,#F56C6C 10%,transparent)}.xmimo-tts-card-actions .xmimo-tts-uninstall:disabled{border-color:#F56C6C;color:#F56C6C;background:transparent;opacity:.55}.xmimo-tts-uninstall-confirmation{display:flex;align-items:center;gap:8px;margin-right:auto;color:#F56C6C}.xmimo-tts-uninstall-choice{display:inline-flex;overflow:hidden;border:1px solid #F56C6C;border-radius:8px}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button{border:0;border-radius:0;padding:5px 12px;color:#F56C6C;background:transparent}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button+button{border-left:1px solid #F56C6C}.xmimo-tts-card-actions .xmimo-tts-uninstall-choice button:hover{filter:none;background:color-mix(in srgb,#F56C6C 10%,transparent)}.xmimo-tts-card-actions .xmimo-tts-discard{border-color:var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-secondary,#5f6875);background:transparent}.xmimo-tts-card-actions .xmimo-tts-discard:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-failed{color:var(--dsw-alias-state-error-primary,#dc2626)}.xmimo-tts-version{color:var(--dsw-alias-label-tertiary,#8b93a1);font-size:11px;font-weight:400}
|
|
1960
|
+
@media(max-width:720px){.xmimo-tts-grid{grid-template-columns:1fr}.xmimo-tts-wide{grid-column:auto}.xmimo-tts-switch-row{grid-template-columns:1fr}.xmimo-tts-switch-row>*:first-child{padding-right:0;padding-bottom:16px}.xmimo-tts-switch-row>*+*{padding-top:16px;padding-left:0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-left:0}.xmimo-tts-select-column{grid-column:auto;flex-direction:column}.xmimo-tts-select-column>div:first-child:not(:only-child){padding-right:0;padding-bottom:16px}.xmimo-tts-select-column>div+div{padding-top:16px;padding-left:0;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-left:0}.xmimo-tts-api-key-hints{flex-wrap:wrap}.xmimo-tts-api-key-hints small{white-space:normal}}
|
|
1961
|
+
.xmimo-tts-card-actions .xmimo-tts-uninstall{margin-right:0}.xmimo-tts-card-actions .xmimo-tts-star{margin-right:auto}.xmimo-tts-uninstall-confirmation{margin-right:0}
|
|
1962
|
+
`;
|
|
1963
|
+
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region src/client/index.tsx
|
|
1966
|
+
/** Client services required by this plugin. */
|
|
1967
|
+
const inject = [
|
|
1968
|
+
"slots",
|
|
1969
|
+
"locale",
|
|
1970
|
+
"connection",
|
|
1971
|
+
"remote",
|
|
1972
|
+
"settingsScope"
|
|
1973
|
+
];
|
|
1974
|
+
function formatStartupError(error) {
|
|
1975
|
+
return error instanceof Error ? error.message : String(error);
|
|
1976
|
+
}
|
|
1977
|
+
function registerSlotContribution(ctx, name, register) {
|
|
1978
|
+
ctx.effect(() => {
|
|
1979
|
+
try {
|
|
1980
|
+
ctx.slots.inject(name, () => {
|
|
1981
|
+
try {
|
|
1982
|
+
return register();
|
|
1983
|
+
} catch (error) {
|
|
1984
|
+
ctx.logger.error(`dsh-xiaomi-tts: ${name} contribution disabled: ${formatStartupError(error)}`);
|
|
1985
|
+
return () => {};
|
|
1986
|
+
}
|
|
1987
|
+
});
|
|
1988
|
+
} catch (error) {
|
|
1989
|
+
ctx.logger.error(`dsh-xiaomi-tts: ${name} injection disabled: ${formatStartupError(error)}`);
|
|
1990
|
+
}
|
|
1991
|
+
return () => {};
|
|
1992
|
+
}, `xiaomi-mimo-tts: ${name}`);
|
|
1993
|
+
}
|
|
1693
1994
|
/** Register the Web action, settings card, locale dictionaries, and styles. */
|
|
1694
1995
|
function apply(ctx) {
|
|
1695
1996
|
const locale = ctx.locale;
|
|
@@ -1706,21 +2007,11 @@ function apply(ctx) {
|
|
|
1706
2007
|
const live = new LiveSpeechController();
|
|
1707
2008
|
live.setStateChangeListener((sessionId, messageId, status) => playback.updateLivePlayback(sessionId, messageId, status));
|
|
1708
2009
|
ctx.effect(() => () => playback.dispose(), "xiaomi-mimo-tts: playback");
|
|
1709
|
-
ctx.effect(() => () =>
|
|
1710
|
-
live.dispose();
|
|
1711
|
-
}, "xiaomi-mimo-tts: live playback");
|
|
2010
|
+
ctx.effect(() => () => live.dispose(), "xiaomi-mimo-tts: live playback");
|
|
1712
2011
|
ctx.effect(() => {
|
|
1713
2012
|
const style = document.createElement("style");
|
|
1714
2013
|
style.dataset.plugin = NS;
|
|
1715
|
-
style.textContent =
|
|
1716
|
-
.xmimo-tts-action{width:28px;height:28px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:transparent;border:none;border-radius:28px;justify-content:center;align-items:center;padding:6px;display:inline-flex}.xmimo-tts-action:hover{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6);color:var(--dsw-alias-label-secondary,#5f6875)}.xmimo-tts-action:disabled{cursor:default;opacity:.45}.xmimo-tts-spin{animation:xmimo-spin 1s linear infinite}@keyframes xmimo-spin{to{transform:rotate(360deg)}}
|
|
1717
|
-
.xmimo-tts-inline-error{max-width:220px;color:var(--dsw-alias-state-error-primary,#dc2626);font-size:12px}
|
|
1718
|
-
.xmimo-tts-card{list-style:none;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:12px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-3,#fff);overflow:hidden;transition:border-color 160ms ease,background 160ms ease}.xmimo-tts-card:hover{border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-open{background:var(--dsw-alias-bg-layer-2,#f7f8fa);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-card-header{appearance:none;display:flex;width:100%;align-items:center;justify-content:space-between;gap:12px;padding:14px 16px;border:0;border-radius:12px;color:inherit;text-align:left;background:transparent;font:inherit;cursor:pointer}.xmimo-tts-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:-2px}.xmimo-tts-card-head-text{display:flex;min-width:0;flex:1;flex-direction:column;gap:4px}.xmimo-tts-card-title{font-size:15px;font-weight:600}.xmimo-tts-card-description{color:var(--dsw-alias-label-tertiary,#8b93a1);font-size:13px;line-height:18px}.xmimo-tts-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-chevron-open{transform:rotate(180deg)}.xmimo-tts-pending{flex:none;border-radius:999px;padding:1px 8px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;font-weight:500;line-height:17px}.xmimo-tts-card-body{border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);margin:0 16px;padding:0 0 16px}
|
|
1719
|
-
.xmimo-tts-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:16px 14px;margin-top:16px;align-items:start}.xmimo-tts-grid label,.xmimo-tts-api-key,.xmimo-tts-model,.xmimo-tts-voice-design-prompt,.xmimo-tts-select-column>div{display:flex;min-width:0;flex-direction:column;gap:6px;font-size:13px}.xmimo-tts-grid input,.xmimo-tts-grid select,.xmimo-tts-grid textarea{box-sizing:border-box;width:100%;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;padding:8px 10px;color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit}.xmimo-tts-grid select{color-scheme:light dark}.xmimo-tts-grid select option{color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-grid select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-grid small{color:var(--dsw-alias-label-tertiary,#8b93a1);line-height:17px}.xmimo-tts-field-heading{display:flex;min-width:0;min-height:20px;flex-direction:row!important;align-items:center;justify-content:space-between;gap:8px}.xmimo-tts-field-label{display:inline-flex;min-width:0;align-items:center;gap:8px}.xmimo-tts-api-key-link{color:var(--dsw-alias-brand-primary,#4f6ef7);font-size:12px;text-decoration:none}.xmimo-tts-api-key-link:hover{text-decoration:underline}.xmimo-tts-field-badges{display:flex!important;flex:none;flex-direction:row!important;align-items:center;gap:8px}.xmimo-tts-overridden{border-radius:999px;padding:1px 7px;color:var(--dsw-alias-label-secondary,#5f6875);background:var(--dsw-alias-bg-module-platform,#eef0f3);font-size:11px;line-height:17px}.xmimo-tts-reset{padding:0;border:0;color:var(--dsw-alias-label-secondary,#5f6875);background:transparent;font:inherit;font-size:12px;cursor:pointer}.xmimo-tts-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328)}.xmimo-tts-reset:disabled{cursor:not-allowed;opacity:.45}.xmimo-tts-api-key-hints{display:flex;min-width:0;gap:8px;align-items:center}.xmimo-tts-api-key-hints small{min-width:0;white-space:nowrap}.xmimo-tts-wide{grid-column:1/-1}.xmimo-tts-switch-row{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:14px}.xmimo-tts-checkbox-row{flex-direction:row!important;align-items:flex-start!important}.xmimo-tts-checkbox-row input{width:auto!important;flex:none;margin-top:3px}.xmimo-tts-checkbox-row span{display:flex;min-width:0;flex-direction:column;gap:4px}.xmimo-tts-select-column{display:flex;min-width:0;flex-direction:row;gap:16px}.xmimo-tts-select-column>div{flex:1}
|
|
1720
|
-
.xmimo-tts-voice-picker{display:flex;min-width:0;flex-direction:column;gap:6px}.xmimo-tts-voice-picker-trigger,.xmimo-tts-voice-option{box-sizing:border-box;display:flex;width:100%;min-width:0;align-items:center;gap:10px;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-primary,#1f2328);background:var(--dsw-alias-bg-layer-2,#f3f4f6);font:inherit;text-align:left;cursor:pointer}.xmimo-tts-voice-picker-trigger{min-height:54px;border-radius:10px;padding:6px 10px}.xmimo-tts-voice-picker-trigger:hover:not(:disabled){border-color:var(--dsw-alias-label-dimmed,#c8ccd4);background:var(--dsw-alias-interactive-bg-hover,#eef0f3)}.xmimo-tts-voice-picker-trigger:focus-visible,.xmimo-tts-voice-option:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}.xmimo-tts-voice-picker-trigger:disabled{cursor:not-allowed;opacity:.55}.xmimo-tts-voice-avatar{box-sizing:border-box;display:block;width:40px;height:40px;flex:none;border:1px solid color-mix(in srgb,var(--dsw-alias-border-l2,#e5e7eb) 80%,transparent);border-radius:50%;object-fit:cover;background:var(--dsw-alias-bg-layer-1,#fff)}.xmimo-tts-custom-voice-avatar{display:grid;place-items:center;color:var(--dsw-alias-brand-primary,#4f6ef7);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 12%,var(--dsw-alias-bg-layer-1,#fff))}.xmimo-tts-custom-voice-avatar svg{width:30px;height:30px;overflow:visible}.xmimo-tts-custom-voice-avatar circle{fill:currentColor}.xmimo-tts-custom-voice-avatar path{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.xmimo-tts-voice-option-copy{display:flex;min-width:0;flex:1;flex-direction:column;gap:1px}.xmimo-tts-voice-option-copy strong{overflow:hidden;font-size:13px;font-weight:600;line-height:18px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-option-copy small{overflow:hidden;font-size:12px;text-overflow:ellipsis;white-space:nowrap}.xmimo-tts-voice-picker-chevron{flex:none;color:var(--dsw-alias-label-tertiary,#8b93a1);transition:transform 160ms ease}.xmimo-tts-voice-picker-chevron-open{transform:rotate(180deg)}.xmimo-tts-voice-picker-menu{display:grid;max-height:310px;overflow:auto;overscroll-behavior:contain;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:10px;padding:5px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 28px rgba(15,23,42,.12)}.xmimo-tts-voice-option{min-height:50px;border:0;border-radius:7px;padding:5px 7px;background:transparent}.xmimo-tts-voice-option:hover,.xmimo-tts-voice-option:focus-visible{background:var(--dsw-alias-interactive-bg-hover,#f3f4f6)}.xmimo-tts-voice-option-selected{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4f6ef7) 10%,transparent)}
|
|
1721
|
-
.xmimo-tts-card-actions{display:flex;align-items:center;justify-content:flex-end;gap:10px;margin-top:16px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);font-size:12px;color:var(--dsw-alias-label-tertiary,#8b93a1)}.xmimo-tts-card-actions button{border:1px solid var(--dsw-alias-brand-primary,#4f6ef7);border-radius:8px;padding:5px 14px;color:var(--dsw-alias-bg-layer-1,#fff);background:var(--dsw-alias-brand-primary,#4f6ef7);cursor:pointer;font:inherit}.xmimo-tts-card-actions button:hover:not(:disabled){filter:brightness(1.08)}.xmimo-tts-card-actions button:disabled{cursor:not-allowed;color:var(--dsw-alias-label-dimmed,#9ca3af);background:var(--dsw-alias-bg-layer-2,#f3f4f6);border-color:var(--dsw-alias-border-l2,#e5e7eb);opacity:1}.xmimo-tts-card-actions .xmimo-tts-discard{border-color:var(--dsw-alias-border-l2,#e5e7eb);color:var(--dsw-alias-label-secondary,#5f6875);background:transparent}.xmimo-tts-card-actions .xmimo-tts-discard:hover:not(:disabled){color:var(--dsw-alias-label-primary,#1f2328);border-color:var(--dsw-alias-label-dimmed,#c8ccd4)}.xmimo-tts-failed{color:var(--dsw-alias-state-error-primary,#dc2626)}
|
|
1722
|
-
@media(max-width:720px){.xmimo-tts-grid{grid-template-columns:1fr}.xmimo-tts-wide{grid-column:auto}.xmimo-tts-switch-row{grid-template-columns:1fr}.xmimo-tts-select-column{grid-column:auto;flex-direction:column}.xmimo-tts-api-key-hints{flex-wrap:wrap}.xmimo-tts-api-key-hints small{white-space:normal}}
|
|
1723
|
-
`;
|
|
2014
|
+
style.textContent = CLIENT_STYLES;
|
|
1724
2015
|
document.head.appendChild(style);
|
|
1725
2016
|
return () => style.remove();
|
|
1726
2017
|
}, "xiaomi-mimo-tts: styles");
|