dsh-xiaomi-tts 2.3.3 → 2.3.4
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 +198 -198
- package/README.md +193 -194
- package/assets/menu.png +0 -0
- package/assets/preset.png +0 -0
- package/lib/client/conversation.d.ts.map +1 -1
- package/lib/client/live-speech-controller.d.ts.map +1 -1
- package/lib/client/localization.d.ts +5 -0
- package/lib/client/localization.d.ts.map +1 -1
- package/lib/client/playback-controller.d.ts +4 -0
- package/lib/client/playback-controller.d.ts.map +1 -1
- package/lib/client/playback-types.d.ts +1 -1
- package/lib/client/playback-types.d.ts.map +1 -1
- package/lib/client/settings-card.d.ts.map +1 -1
- package/lib/client/settings-scope.d.ts.map +1 -1
- package/lib/client.js +321 -18
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/{shared-Cf9qZwUl.js → shared-CIx9nBxX.js} +124 -14
- package/lib/shared.d.ts +19 -4
- package/lib/shared.d.ts.map +1 -1
- package/lib/shared.js +2 -2
- package/package.json +104 -103
package/lib/client.js
CHANGED
|
@@ -161,6 +161,11 @@ const TTS_FORMATS = [
|
|
|
161
161
|
"mp3",
|
|
162
162
|
"wav"
|
|
163
163
|
];
|
|
164
|
+
/** Voice-design playback strategies. Segmented playback keeps each upstream request short. */
|
|
165
|
+
const TTS_VOICE_DESIGN_PLAYBACK_MODES = ["complete", "segmented"];
|
|
166
|
+
const DEFAULT_TTS_SEGMENT_CHARACTERS = 120;
|
|
167
|
+
const MAX_TTS_SEGMENT_CHARACTERS = 180;
|
|
168
|
+
const MIN_TTS_SEGMENT_CHARACTERS = 40;
|
|
164
169
|
/** Minimum spoken characters to accumulate before starting one PCM stream request. */
|
|
165
170
|
const MIN_TTS_STREAM_CHARACTERS = 20;
|
|
166
171
|
/** Maximum decoded complete MP3 payload accepted from Xiaomi MiMo. */
|
|
@@ -184,21 +189,33 @@ const TTS_PUNCTUATION = {
|
|
|
184
189
|
/** Decorative punctuation can make TTS emit non-speech artifacts, so omit it entirely. */
|
|
185
190
|
const TTS_NON_SPEECH_PUNCTUATION = /[()\[\]【】[]〔〕〖〗{}{}「」『』《》〈〉“”‘’"'`<>:…—–-~]/gu;
|
|
186
191
|
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;
|
|
187
|
-
const TTS_WINDOWS_PATH_PATTERN = /(?:\b[A-Za-z]:[\\/]|\\\\)(?:[A-Za-z0-9._ -]+[\\/])
|
|
188
|
-
const TTS_UNIX_PATH_PATTERN = /\/(?:[A-Za-z0-9._-]+\/)
|
|
192
|
+
const TTS_WINDOWS_PATH_PATTERN = /(?:\b[A-Za-z]:[\\/]|\\\\)(?:[A-Za-z0-9._ -]+[\\/])+(?:[A-Za-z0-9._ -]+)/gu;
|
|
193
|
+
const TTS_UNIX_PATH_PATTERN = /\/(?:[A-Za-z0-9._-]+\/)+(?:[A-Za-z0-9._-]+)/gu;
|
|
189
194
|
const TTS_RELATIVE_PATH_PATTERN = /(?:\.\.?[\\/])(?:[A-Za-z0-9._-]+[\\/])*(?:[A-Za-z0-9._-]+(?:\.[A-Za-z0-9_-]+)?)/gu;
|
|
190
195
|
const TTS_PROJECT_PATH_PATTERN = /\b(?:[A-Za-z0-9_-]+[\\/])+[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu;
|
|
196
|
+
/** Combined Markdown syntax and path removal in a single pass. */
|
|
197
|
+
const MARKDOWN_CODE_BLOCK_RE = /```[\s\S]*?```|~~~[\s\S]*?~~~/g;
|
|
198
|
+
const MARKDOWN_INDENTED_CODE_RE = /(^|\n)(?: {4}|\t)[^\n]*(?=\n|$)/g;
|
|
199
|
+
const MARKDOWN_IMAGE_RE = /!\[([^\]\r\n]*)\]\([^\)\r\n]*\)/g;
|
|
200
|
+
const MARKDOWN_LINK_RE = /\[([^\]\r\n]*)\]\([^\)\r\n]*\)/g;
|
|
201
|
+
const MARKDOWN_HTML_TAG_RE = /<[^>\r\n]*>/g;
|
|
202
|
+
const MARKDOWN_HEADING_RE = /(^|\n)\s{0,3}#{1,6}\s+/g;
|
|
203
|
+
const MARKDOWN_LIST_RE = /(^|\n)\s*(?:[-*+]|\d+[.)])\s+/g;
|
|
204
|
+
const MARKDOWN_BLOCKQUOTE_RE = /(^|\n)\s*>\s?/g;
|
|
205
|
+
const MARKDOWN_INLINE_FORMAT_RE = /`+|[*_~]{1,3}/g;
|
|
206
|
+
const MARKDOWN_TABLE_SEP_RE = /[|]/g;
|
|
191
207
|
function removeTtsPaths(value) {
|
|
192
208
|
return value.replace(TTS_WINDOWS_PATH_PATTERN, " ").replace(TTS_RELATIVE_PATH_PATTERN, " ").replace(TTS_PROJECT_PATH_PATTERN, " ").replace(TTS_UNIX_PATH_PATTERN, " ");
|
|
193
209
|
}
|
|
194
210
|
function removeTtsMarkup(value) {
|
|
195
|
-
let text = value.replace(
|
|
211
|
+
let text = value.replace(MARKDOWN_CODE_BLOCK_RE, " ").replace(MARKDOWN_INDENTED_CODE_RE, "$1").replace(MARKDOWN_IMAGE_RE, " ").replace(MARKDOWN_LINK_RE, "$1").replace(MARKDOWN_HTML_TAG_RE, " ").replace(MARKDOWN_HEADING_RE, "$1").replace(MARKDOWN_LIST_RE, "$1").replace(MARKDOWN_BLOCKQUOTE_RE, "$1").replace(MARKDOWN_INLINE_FORMAT_RE, "").replace(MARKDOWN_TABLE_SEP_RE, " ");
|
|
196
212
|
text = text.replace(TTS_URL_PATTERN, " ");
|
|
197
213
|
return removeTtsPaths(text);
|
|
198
214
|
}
|
|
199
215
|
function removeTtsSymbols(value) {
|
|
200
216
|
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, " ");
|
|
201
217
|
}
|
|
218
|
+
/** Combined punctuation normalization: collapse adjacent punctuation, remove non-speech characters, and normalize Chinese punctuation. */
|
|
202
219
|
function normalizeTtsPunctuation(value) {
|
|
203
220
|
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");
|
|
204
221
|
}
|
|
@@ -212,24 +229,116 @@ function prepareTtsText(value) {
|
|
|
212
229
|
if (value.length === 0) return "";
|
|
213
230
|
return normalizeTtsPunctuation(removeTtsSymbols(removeTtsMarkup(value).replace(/\\[rn]|\/n/gi, " ").replace(/\r\n?|\n/g, "."))).replace(/\s+/g, " ").trim();
|
|
214
231
|
}
|
|
215
|
-
/**
|
|
232
|
+
/** Locate fenced code blocks in raw streaming text so their content is never read aloud. */
|
|
233
|
+
function findFencedCodeRegions(value) {
|
|
234
|
+
const regions = [];
|
|
235
|
+
let pendingStart = null;
|
|
236
|
+
const fence = /(^|\n)[ \t]{0,3}(`{3,}|~{3,})[^\r\n]*/g;
|
|
237
|
+
let open = null;
|
|
238
|
+
for (const match of value.matchAll(fence)) {
|
|
239
|
+
const lineStart = match.index + (match[1] === "\n" ? 1 : 0);
|
|
240
|
+
const char = match[2][0];
|
|
241
|
+
if (open === null) open = {
|
|
242
|
+
start: lineStart,
|
|
243
|
+
char
|
|
244
|
+
};
|
|
245
|
+
else if (open.char === char) {
|
|
246
|
+
regions.push([open.start, match.index + match[0].length]);
|
|
247
|
+
open = null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (open !== null) pendingStart = open.start;
|
|
251
|
+
return {
|
|
252
|
+
regions,
|
|
253
|
+
pendingStart
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/** Split an accumulated model delta at completed sentence-ending punctuation, skipping fenced code blocks whole. */
|
|
216
257
|
function splitCompletedTtsSentences(value) {
|
|
217
|
-
const
|
|
258
|
+
const { regions, pendingStart } = findFencedCodeRegions(value);
|
|
259
|
+
const limit = pendingStart ?? value.length;
|
|
218
260
|
const boundary = /[。!?!?;;\n]+(?:[”’)】》〕\]}'"]*\s*)/gu;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
261
|
+
const sentences = [];
|
|
262
|
+
let sentenceStart = 0;
|
|
263
|
+
let consumed = 0;
|
|
264
|
+
const splitSegment = (from, to) => {
|
|
265
|
+
boundary.lastIndex = from;
|
|
266
|
+
let match;
|
|
267
|
+
while ((match = boundary.exec(value)) !== null) {
|
|
268
|
+
const end = match.index + match[0].length;
|
|
269
|
+
if (end > to) break;
|
|
270
|
+
const sentence = value.slice(sentenceStart, end);
|
|
271
|
+
if (sentence.trim().length > 0) sentences.push(sentence);
|
|
272
|
+
sentenceStart = end;
|
|
273
|
+
consumed = end;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
let pos = 0;
|
|
277
|
+
for (const [start, end] of regions) {
|
|
278
|
+
if (start >= limit) break;
|
|
279
|
+
if (pos < start) splitSegment(pos, Math.min(start, limit));
|
|
280
|
+
sentenceStart = Math.max(sentenceStart, end);
|
|
281
|
+
consumed = Math.max(consumed, end);
|
|
282
|
+
pos = end;
|
|
224
283
|
}
|
|
284
|
+
if (pos < limit) splitSegment(pos, limit);
|
|
285
|
+
if (pendingStart !== null) return {
|
|
286
|
+
sentences,
|
|
287
|
+
remainder: value.slice(pendingStart),
|
|
288
|
+
consumed: pendingStart,
|
|
289
|
+
inCode: true
|
|
290
|
+
};
|
|
225
291
|
return {
|
|
226
292
|
sentences,
|
|
227
|
-
remainder: value.slice(
|
|
293
|
+
remainder: value.slice(consumed),
|
|
294
|
+
consumed,
|
|
295
|
+
inCode: false
|
|
228
296
|
};
|
|
229
297
|
}
|
|
230
298
|
/** Count text-bearing characters only, excluding punctuation and whitespace. */
|
|
231
299
|
function countTtsSpeechCharacters(value) {
|
|
232
|
-
return
|
|
300
|
+
return (value.match(/[\p{L}\p{N}]/gu) ?? []).length;
|
|
301
|
+
}
|
|
302
|
+
/** Split cleaned speech text on natural boundaries while bounding VoiceDesign requests. */
|
|
303
|
+
function splitTtsSegments(value, target = DEFAULT_TTS_SEGMENT_CHARACTERS, maximum = MAX_TTS_SEGMENT_CHARACTERS) {
|
|
304
|
+
const text = prepareTtsText(value);
|
|
305
|
+
if (text.length === 0) return [];
|
|
306
|
+
const preferred = Math.max(MIN_TTS_SEGMENT_CHARACTERS, Math.min(target, maximum));
|
|
307
|
+
const pieces = text.match(/[^.!?;]+[.!?;]*|[.!?;]+/gu) ?? [text];
|
|
308
|
+
const segments = [];
|
|
309
|
+
let pending = "";
|
|
310
|
+
const append = (piece) => {
|
|
311
|
+
const candidate = `${pending}${piece}`.trim();
|
|
312
|
+
if (candidate.length === 0) return;
|
|
313
|
+
if (countTtsSpeechCharacters(candidate) <= maximum) {
|
|
314
|
+
pending = candidate;
|
|
315
|
+
if (countTtsSpeechCharacters(pending) >= preferred) {
|
|
316
|
+
segments.push(pending);
|
|
317
|
+
pending = "";
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (pending.length > 0) {
|
|
322
|
+
segments.push(pending);
|
|
323
|
+
pending = "";
|
|
324
|
+
}
|
|
325
|
+
let rest = piece.trim();
|
|
326
|
+
while (countTtsSpeechCharacters(rest) > maximum) {
|
|
327
|
+
let cut = Math.min(rest.length, maximum);
|
|
328
|
+
const boundary = Math.max(rest.lastIndexOf(",", cut), rest.lastIndexOf(" ", cut), rest.lastIndexOf(":", cut));
|
|
329
|
+
if (boundary >= MIN_TTS_SEGMENT_CHARACTERS) cut = boundary + 1;
|
|
330
|
+
segments.push(rest.slice(0, cut).trim());
|
|
331
|
+
rest = rest.slice(cut).trim();
|
|
332
|
+
}
|
|
333
|
+
pending = rest;
|
|
334
|
+
};
|
|
335
|
+
for (const piece of pieces) append(piece);
|
|
336
|
+
if (pending.length > 0) {
|
|
337
|
+
const last = segments.at(-1);
|
|
338
|
+
if (last !== void 0 && countTtsSpeechCharacters(pending) < MIN_TTS_SEGMENT_CHARACTERS && countTtsSpeechCharacters(`${last}${pending}`) <= maximum) segments[segments.length - 1] = `${last}${pending}`;
|
|
339
|
+
else segments.push(pending);
|
|
340
|
+
}
|
|
341
|
+
return segments;
|
|
233
342
|
}
|
|
234
343
|
/** Accumulate short sentences so a PCM stream has enough text to sound natural. */
|
|
235
344
|
function batchTtsStreamText(pending, next, flush) {
|
|
@@ -320,6 +429,7 @@ const DEFAULT_TTS_SETTINGS = {
|
|
|
320
429
|
voiceDesignCustomPrompt: "青年女性,声线清亮、亲切自然,吐字清楚,语速适中,情绪温柔克制。",
|
|
321
430
|
presetStylePrompt: "使用清晰、自然、准确的声音朗读,语速适中,停顿自然,语气平和克制,避免夸张表达。",
|
|
322
431
|
format: "pcm",
|
|
432
|
+
voiceDesignPlaybackMode: "complete",
|
|
323
433
|
autoPlay: true,
|
|
324
434
|
instruction: "请忠实朗读原文,根据文本语气自然表达,不添加或改写内容。",
|
|
325
435
|
maxTextLength: 12e3,
|
|
@@ -619,9 +729,9 @@ var LiveSpeechController = class {
|
|
|
619
729
|
return `${cursor.sessionId}:${cursor.turn}:${cursor.step}`;
|
|
620
730
|
}
|
|
621
731
|
drain(flush) {
|
|
622
|
-
const { sentences, remainder } = splitCompletedTtsSentences(this.observed.slice(this.consumed));
|
|
623
|
-
const ready = flush && remainder.trim().length > 0 ? [...sentences, remainder] : sentences;
|
|
624
|
-
this.consumed +=
|
|
732
|
+
const { sentences, remainder, consumed, inCode } = splitCompletedTtsSentences(this.observed.slice(this.consumed));
|
|
733
|
+
const ready = flush && !inCode && remainder.trim().length > 0 ? [...sentences, remainder] : sentences;
|
|
734
|
+
this.consumed += consumed;
|
|
625
735
|
if (flush) this.consumed = this.observed.length;
|
|
626
736
|
for (const sentence of ready) this.stageSentence(sentence, false);
|
|
627
737
|
if (flush) this.stageSentence("", true);
|
|
@@ -745,6 +855,8 @@ var PlaybackController = class {
|
|
|
745
855
|
completedSessions = /* @__PURE__ */ new Set();
|
|
746
856
|
completedMessages = /* @__PURE__ */ new Map();
|
|
747
857
|
current = null;
|
|
858
|
+
segmentQueue = [];
|
|
859
|
+
segmentedState = null;
|
|
748
860
|
request = null;
|
|
749
861
|
generation = 0;
|
|
750
862
|
activeSessionId = null;
|
|
@@ -757,6 +869,7 @@ var PlaybackController = class {
|
|
|
757
869
|
if (this.activeSessionId === sessionId) return;
|
|
758
870
|
this.generation += 1;
|
|
759
871
|
this.stopCurrent();
|
|
872
|
+
this.segmentedState = null;
|
|
760
873
|
this.liveSessions.clear();
|
|
761
874
|
this.completedSessions.clear();
|
|
762
875
|
this.completedMessages.clear();
|
|
@@ -765,6 +878,7 @@ var PlaybackController = class {
|
|
|
765
878
|
}
|
|
766
879
|
cancelPlayback(sessionId) {
|
|
767
880
|
if (this.activeSessionId !== sessionId) return;
|
|
881
|
+
this.segmentedState = null;
|
|
768
882
|
this.generation += 1;
|
|
769
883
|
this.stopCurrent();
|
|
770
884
|
this.publish(this.emptyView());
|
|
@@ -773,6 +887,7 @@ var PlaybackController = class {
|
|
|
773
887
|
if (this.activeSessionId !== sessionId) return;
|
|
774
888
|
this.generation += 1;
|
|
775
889
|
this.stopCurrent();
|
|
890
|
+
this.segmentedState = null;
|
|
776
891
|
this.liveSessions.clear();
|
|
777
892
|
this.completedSessions.clear();
|
|
778
893
|
this.completedMessages.clear();
|
|
@@ -814,6 +929,124 @@ var PlaybackController = class {
|
|
|
814
929
|
error: status === "error" ? "play-failed" : null
|
|
815
930
|
});
|
|
816
931
|
}
|
|
932
|
+
pauseSegmented(sessionId, messageId) {
|
|
933
|
+
if (this.activeSessionId !== sessionId || this.view.source !== "segmented" || this.view.messageId !== messageId) return;
|
|
934
|
+
this.generation += 1;
|
|
935
|
+
this.stopCurrent();
|
|
936
|
+
this.publish({
|
|
937
|
+
sessionId,
|
|
938
|
+
messageId,
|
|
939
|
+
source: "segmented",
|
|
940
|
+
status: "paused",
|
|
941
|
+
error: null
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
async segmented(sessionId, messageId, text, automatic) {
|
|
945
|
+
if (this.activeSessionId !== sessionId) return;
|
|
946
|
+
const previous = this.segmentedState;
|
|
947
|
+
const resume = previous !== null && previous.sessionId === sessionId && previous.messageId === messageId;
|
|
948
|
+
this.stopCurrent();
|
|
949
|
+
const segments = resume ? previous.segments : splitTtsSegments(text);
|
|
950
|
+
const startIndex = resume ? previous.index : 0;
|
|
951
|
+
if (segments.length === 0) {
|
|
952
|
+
this.publish({
|
|
953
|
+
sessionId,
|
|
954
|
+
messageId,
|
|
955
|
+
source: "segmented",
|
|
956
|
+
status: "error",
|
|
957
|
+
error: "no-text"
|
|
958
|
+
});
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
this.segmentedState = {
|
|
962
|
+
sessionId,
|
|
963
|
+
messageId,
|
|
964
|
+
segments,
|
|
965
|
+
index: startIndex
|
|
966
|
+
};
|
|
967
|
+
const generation = ++this.generation;
|
|
968
|
+
const controller = new AbortController();
|
|
969
|
+
this.request = controller;
|
|
970
|
+
this.publish({
|
|
971
|
+
sessionId,
|
|
972
|
+
messageId,
|
|
973
|
+
source: "segmented",
|
|
974
|
+
status: "loading",
|
|
975
|
+
error: null
|
|
976
|
+
});
|
|
977
|
+
try {
|
|
978
|
+
const synthesize = async (segment) => {
|
|
979
|
+
let lastError = null;
|
|
980
|
+
for (let attempt = 0; attempt < 2; attempt += 1) try {
|
|
981
|
+
const response = await fetch(TTS_ROUTE, {
|
|
982
|
+
method: "POST",
|
|
983
|
+
headers: { "content-type": "application/json" },
|
|
984
|
+
body: JSON.stringify({
|
|
985
|
+
text: segment,
|
|
986
|
+
format: "wav"
|
|
987
|
+
}),
|
|
988
|
+
signal: controller.signal
|
|
989
|
+
});
|
|
990
|
+
if (!response.ok) throw new Error(`segment-request-${response.status}`);
|
|
991
|
+
return await response.blob();
|
|
992
|
+
} catch (error) {
|
|
993
|
+
lastError = error;
|
|
994
|
+
}
|
|
995
|
+
throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error("segment-request-failed");
|
|
996
|
+
};
|
|
997
|
+
let nextAudio = synthesize(segments[startIndex]);
|
|
998
|
+
for (let index = startIndex; index < segments.length; index += 1) {
|
|
999
|
+
const blob = await nextAudio;
|
|
1000
|
+
if (generation !== this.generation || this.activeSessionId !== sessionId) return;
|
|
1001
|
+
if (this.segmentedState !== null) this.segmentedState.index = index;
|
|
1002
|
+
if (index + 1 < segments.length) nextAudio = synthesize(segments[index + 1]);
|
|
1003
|
+
const audio = new Audio(URL.createObjectURL(blob));
|
|
1004
|
+
this.segmentQueue.push(audio);
|
|
1005
|
+
await new Promise((resolve, reject) => {
|
|
1006
|
+
const cleanup = () => {
|
|
1007
|
+
audio.removeEventListener("ended", ended);
|
|
1008
|
+
audio.removeEventListener("error", failed);
|
|
1009
|
+
};
|
|
1010
|
+
const ended = () => {
|
|
1011
|
+
cleanup();
|
|
1012
|
+
URL.revokeObjectURL(audio.src);
|
|
1013
|
+
resolve();
|
|
1014
|
+
};
|
|
1015
|
+
const failed = () => {
|
|
1016
|
+
cleanup();
|
|
1017
|
+
URL.revokeObjectURL(audio.src);
|
|
1018
|
+
reject(/* @__PURE__ */ new Error("segment-play-failed"));
|
|
1019
|
+
};
|
|
1020
|
+
audio.addEventListener("ended", ended);
|
|
1021
|
+
audio.addEventListener("error", failed);
|
|
1022
|
+
audio.play().then(() => {
|
|
1023
|
+
if (generation === this.generation && this.activeSessionId === sessionId) this.publish({
|
|
1024
|
+
sessionId,
|
|
1025
|
+
messageId,
|
|
1026
|
+
source: "segmented",
|
|
1027
|
+
status: "playing",
|
|
1028
|
+
error: null
|
|
1029
|
+
});
|
|
1030
|
+
}).catch(() => reject(/* @__PURE__ */ new Error(automatic ? "autoplay-blocked" : "play-failed")));
|
|
1031
|
+
});
|
|
1032
|
+
this.segmentQueue = this.segmentQueue.filter((item) => item !== audio);
|
|
1033
|
+
}
|
|
1034
|
+
if (generation === this.generation && this.activeSessionId === sessionId) {
|
|
1035
|
+
this.segmentedState = null;
|
|
1036
|
+
this.publish(this.emptyView());
|
|
1037
|
+
}
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
if (!controller.signal.aborted && generation === this.generation && this.activeSessionId === sessionId) this.publish({
|
|
1040
|
+
sessionId,
|
|
1041
|
+
messageId,
|
|
1042
|
+
source: "segmented",
|
|
1043
|
+
status: "error",
|
|
1044
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1045
|
+
});
|
|
1046
|
+
} finally {
|
|
1047
|
+
if (generation === this.generation) this.request = null;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
817
1050
|
async toggle(sessionId, messageId, text, automatic) {
|
|
818
1051
|
if (this.activeSessionId !== sessionId) return;
|
|
819
1052
|
if (this.view.source === "complete" && this.view.sessionId === sessionId && this.view.messageId === messageId && this.current !== null) {
|
|
@@ -951,6 +1184,7 @@ var PlaybackController = class {
|
|
|
951
1184
|
dispose() {
|
|
952
1185
|
this.generation += 1;
|
|
953
1186
|
this.stopCurrent();
|
|
1187
|
+
this.segmentedState = null;
|
|
954
1188
|
this.liveSessions.clear();
|
|
955
1189
|
this.completedSessions.clear();
|
|
956
1190
|
this.completedMessages.clear();
|
|
@@ -960,6 +1194,11 @@ var PlaybackController = class {
|
|
|
960
1194
|
stopCurrent() {
|
|
961
1195
|
this.request?.abort();
|
|
962
1196
|
this.request = null;
|
|
1197
|
+
for (const audio of this.segmentQueue) {
|
|
1198
|
+
audio.pause();
|
|
1199
|
+
URL.revokeObjectURL(audio.src);
|
|
1200
|
+
}
|
|
1201
|
+
this.segmentQueue = [];
|
|
963
1202
|
if (this.current !== null) this.releaseCurrentAudio(this.current.audio);
|
|
964
1203
|
}
|
|
965
1204
|
releaseCurrentAudio(audio) {
|
|
@@ -1005,6 +1244,7 @@ function decodeSettings(value) {
|
|
|
1005
1244
|
if (typeof value.voiceDesignPrompt === "string") decoded.voiceDesignPrompt = value.voiceDesignPrompt;
|
|
1006
1245
|
if (typeof value.voiceDesignCustomPrompt === "string") decoded.voiceDesignCustomPrompt = value.voiceDesignCustomPrompt;
|
|
1007
1246
|
if (TTS_FORMATS.includes(value.format)) decoded.format = value.format;
|
|
1247
|
+
if (TTS_VOICE_DESIGN_PLAYBACK_MODES.includes(value.voiceDesignPlaybackMode)) decoded.voiceDesignPlaybackMode = value.voiceDesignPlaybackMode;
|
|
1008
1248
|
if (typeof value.autoPlay === "boolean") decoded.autoPlay = value.autoPlay;
|
|
1009
1249
|
if (typeof value.maxTextLength === "number") decoded.maxTextLength = value.maxTextLength;
|
|
1010
1250
|
if (typeof value.requestTimeoutMs === "number") decoded.requestTimeoutMs = value.requestTimeoutMs;
|
|
@@ -1151,6 +1391,11 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1151
1391
|
const resolvedSettings = resolveTtsSettings(settingsSnapshot.value);
|
|
1152
1392
|
const view = (0, react.useSyncExternalStore)(playback.subscribe, playback.getSnapshot, playback.getSnapshot);
|
|
1153
1393
|
const playCompletedReply = (automatic) => {
|
|
1394
|
+
if (resolvedSettings.model === "mimo-v2.5-tts-voicedesign" && resolvedSettings.voiceDesignPlaybackMode === "segmented") {
|
|
1395
|
+
live.cancelSession(sessionId);
|
|
1396
|
+
playback.segmented(sessionId, messageId, text, automatic);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1154
1399
|
if (resolvedSettings.model === "mimo-v2.5-tts" && resolvedSettings.format === "pcm") {
|
|
1155
1400
|
playback.cancelPlayback(sessionId);
|
|
1156
1401
|
live.playCompleted(sessionId, messageId, text, () => {
|
|
@@ -1177,6 +1422,7 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1177
1422
|
playback,
|
|
1178
1423
|
resolvedSettings.format,
|
|
1179
1424
|
resolvedSettings.model,
|
|
1425
|
+
resolvedSettings.voiceDesignPlaybackMode,
|
|
1180
1426
|
sessionId,
|
|
1181
1427
|
settingsSnapshot.value?.autoPlay,
|
|
1182
1428
|
settingsSnapshot.value?.enabled,
|
|
@@ -1212,6 +1458,11 @@ function ReadAloudAction({ sessionId, messageId, useSession, playback, live, set
|
|
|
1212
1458
|
playback.toggle(sessionId, messageId, text, false);
|
|
1213
1459
|
return;
|
|
1214
1460
|
}
|
|
1461
|
+
if (mine && source === "segmented") {
|
|
1462
|
+
if (status === "playing" || status === "loading") playback.pauseSegmented(sessionId, messageId);
|
|
1463
|
+
else if (status === "paused") playback.segmented(sessionId, messageId, text, false);
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1215
1466
|
playCompletedReply(false);
|
|
1216
1467
|
},
|
|
1217
1468
|
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, {})
|
|
@@ -1266,6 +1517,11 @@ const zh = {
|
|
|
1266
1517
|
"settings.customVoiceOption": "自定义",
|
|
1267
1518
|
"settings.customVoiceSummary": "手动编写音色描述",
|
|
1268
1519
|
"settings.voiceDesignPromptHint": "按“年龄段 + 性别、声音质感、语速节奏、情绪底色”描述声音本身;不写场景或动作。",
|
|
1520
|
+
"settings.voiceDesignPlaybackMode": "朗读方式",
|
|
1521
|
+
"settings.voiceDesignPlaybackComplete": "完整朗读",
|
|
1522
|
+
"settings.voiceDesignPlaybackSegmented": "分片朗读",
|
|
1523
|
+
"settings.voiceDesignPlaybackCompleteHint": "整篇生成后播放,语调连续性更好。长文本会出现模型幻觉。",
|
|
1524
|
+
"settings.voiceDesignPlaybackSegmentedHint": "适合长文本,分段生成、更快播放。但会重新推导音色细节,语调连续性略差。",
|
|
1269
1525
|
"settings.save": "保存",
|
|
1270
1526
|
"settings.saving": "保存中…",
|
|
1271
1527
|
"settings.saved": "已保存",
|
|
@@ -1328,6 +1584,11 @@ const en = {
|
|
|
1328
1584
|
"settings.customVoiceOption": "Custom",
|
|
1329
1585
|
"settings.customVoiceSummary": "Write a custom voice description",
|
|
1330
1586
|
"settings.voiceDesignPromptHint": "Describe the voice itself with age/gender, texture, pace, and emotional baseline; avoid scenes or actions.",
|
|
1587
|
+
"settings.voiceDesignPlaybackMode": "Read-aloud mode",
|
|
1588
|
+
"settings.voiceDesignPlaybackComplete": "Complete",
|
|
1589
|
+
"settings.voiceDesignPlaybackSegmented": "Segmented",
|
|
1590
|
+
"settings.voiceDesignPlaybackCompleteHint": "Generates the entire reply before playback for better continuity.",
|
|
1591
|
+
"settings.voiceDesignPlaybackSegmentedHint": "Generates and plays semantic segments in order; better for long text and faster start.",
|
|
1331
1592
|
"settings.save": "Save",
|
|
1332
1593
|
"settings.saving": "Saving…",
|
|
1333
1594
|
"settings.saved": "Saved",
|
|
@@ -1697,7 +1958,8 @@ const EDITABLE_SETTING_FIELDS = [
|
|
|
1697
1958
|
"voice",
|
|
1698
1959
|
"voiceDesignPrompt",
|
|
1699
1960
|
"voiceDesignCustomPrompt",
|
|
1700
|
-
"format"
|
|
1961
|
+
"format",
|
|
1962
|
+
"voiceDesignPlaybackMode"
|
|
1701
1963
|
];
|
|
1702
1964
|
const RELEASES_URL = "https://github.com/ppy-web/dsh-plugin-xiaomi-mimo-tts/releases";
|
|
1703
1965
|
function hostRoute(path) {
|
|
@@ -1745,6 +2007,7 @@ function SettingsCard({ scope, t }) {
|
|
|
1745
2007
|
const [model, setModel] = (0, react.useState)(initial.model);
|
|
1746
2008
|
const [voice, setVoice] = (0, react.useState)(initial.voice);
|
|
1747
2009
|
const [format, setFormat] = (0, react.useState)(initial.format);
|
|
2010
|
+
const [voiceDesignPlaybackMode, setVoiceDesignPlaybackMode] = (0, react.useState)(initial.voiceDesignPlaybackMode);
|
|
1748
2011
|
const [voiceDesignPrompt, setVoiceDesignPrompt] = (0, react.useState)(initial.voiceDesignPrompt);
|
|
1749
2012
|
const [voiceDesignCustomPrompt, setVoiceDesignCustomPrompt] = (0, react.useState)(initial.voiceDesignCustomPrompt);
|
|
1750
2013
|
const [changes, setChanges] = (0, react.useState)({});
|
|
@@ -1762,7 +2025,8 @@ function SettingsCard({ scope, t }) {
|
|
|
1762
2025
|
voice,
|
|
1763
2026
|
voiceDesignPrompt,
|
|
1764
2027
|
voiceDesignCustomPrompt,
|
|
1765
|
-
format
|
|
2028
|
+
format,
|
|
2029
|
+
voiceDesignPlaybackMode
|
|
1766
2030
|
};
|
|
1767
2031
|
const acceptedValue = (field) => {
|
|
1768
2032
|
const raw = value?.[field];
|
|
@@ -1830,6 +2094,7 @@ function SettingsCard({ scope, t }) {
|
|
|
1830
2094
|
setModel(next.model);
|
|
1831
2095
|
setVoice(next.voice);
|
|
1832
2096
|
setFormat(next.format);
|
|
2097
|
+
setVoiceDesignPlaybackMode(next.voiceDesignPlaybackMode);
|
|
1833
2098
|
setVoiceDesignPrompt(next.voiceDesignPrompt);
|
|
1834
2099
|
setVoiceDesignCustomPrompt(next.voiceDesignCustomPrompt);
|
|
1835
2100
|
setChanges({});
|
|
@@ -1849,6 +2114,7 @@ function SettingsCard({ scope, t }) {
|
|
|
1849
2114
|
if (field === "model") setModel(base.model);
|
|
1850
2115
|
if (field === "voice") setVoice(base.voice);
|
|
1851
2116
|
if (field === "format") setFormat(base.format);
|
|
2117
|
+
if (field === "voiceDesignPlaybackMode") setVoiceDesignPlaybackMode(base.voiceDesignPlaybackMode);
|
|
1852
2118
|
if (field === "voiceDesignPrompt") setVoiceDesignPrompt(base.voiceDesignPrompt);
|
|
1853
2119
|
if (field === "voiceDesignCustomPrompt") setVoiceDesignCustomPrompt(base.voiceDesignCustomPrompt);
|
|
1854
2120
|
};
|
|
@@ -1859,6 +2125,7 @@ function SettingsCard({ scope, t }) {
|
|
|
1859
2125
|
setModel(next.model);
|
|
1860
2126
|
setVoice(next.voice);
|
|
1861
2127
|
setFormat(next.format);
|
|
2128
|
+
setVoiceDesignPlaybackMode(next.voiceDesignPlaybackMode);
|
|
1862
2129
|
setVoiceDesignPrompt(next.voiceDesignPrompt);
|
|
1863
2130
|
setVoiceDesignCustomPrompt(next.voiceDesignCustomPrompt);
|
|
1864
2131
|
setApiKey("");
|
|
@@ -2050,7 +2317,43 @@ function SettingsCard({ scope, t }) {
|
|
|
2050
2317
|
setState("idle");
|
|
2051
2318
|
}
|
|
2052
2319
|
}),
|
|
2053
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.voiceDesignPromptHint") })
|
|
2320
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("settings.voiceDesignPromptHint") }),
|
|
2321
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2322
|
+
className: "xmimo-tts-format xmimo-tts-wide",
|
|
2323
|
+
children: [
|
|
2324
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingFieldHeading, {
|
|
2325
|
+
label: t("settings.voiceDesignPlaybackMode"),
|
|
2326
|
+
overriddenLabel: t("settings.overridden"),
|
|
2327
|
+
resetLabel: t("settings.reset"),
|
|
2328
|
+
overridden: fieldOverridden("voiceDesignPlaybackMode"),
|
|
2329
|
+
resettable: true,
|
|
2330
|
+
disabled: !snapshot.writable,
|
|
2331
|
+
onReset: () => {
|
|
2332
|
+
resetField("voiceDesignPlaybackMode");
|
|
2333
|
+
}
|
|
2334
|
+
}),
|
|
2335
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2336
|
+
className: "xmimo-tts-format-options",
|
|
2337
|
+
role: "radiogroup",
|
|
2338
|
+
"aria-label": t("settings.voiceDesignPlaybackMode"),
|
|
2339
|
+
children: TTS_VOICE_DESIGN_PLAYBACK_MODES.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
2340
|
+
className: voiceDesignPlaybackMode === item ? "xmimo-tts-format-option xmimo-tts-format-option-selected" : "xmimo-tts-format-option",
|
|
2341
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
2342
|
+
type: "radio",
|
|
2343
|
+
name: "xmimo-tts-voice-design-playback",
|
|
2344
|
+
value: item,
|
|
2345
|
+
checked: voiceDesignPlaybackMode === item,
|
|
2346
|
+
disabled: !snapshot.writable,
|
|
2347
|
+
onChange: () => {
|
|
2348
|
+
setVoiceDesignPlaybackMode(item);
|
|
2349
|
+
markChange("voiceDesignPlaybackMode");
|
|
2350
|
+
}
|
|
2351
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(item === "complete" ? "settings.voiceDesignPlaybackComplete" : "settings.voiceDesignPlaybackSegmented") })]
|
|
2352
|
+
}, item))
|
|
2353
|
+
}),
|
|
2354
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t(voiceDesignPlaybackMode === "complete" ? "settings.voiceDesignPlaybackCompleteHint" : "settings.voiceDesignPlaybackSegmentedHint") })
|
|
2355
|
+
]
|
|
2356
|
+
})
|
|
2054
2357
|
]
|
|
2055
2358
|
}) : null,
|
|
2056
2359
|
model === "mimo-v2.5-tts" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|