Spaces:
Paused
Paused
Fix: Optimize TTS chunking to eliminate loading pauses (BUILD 1.5.22)
Browse files- index.html +1 -1
- src/services/tts-service.js +30 -32
index.html
CHANGED
|
@@ -51,7 +51,7 @@
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
-
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.5.
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
|
|
|
| 51 |
</head>
|
| 52 |
<body class="dark-theme in-chat-view">
|
| 53 |
|
| 54 |
+
<div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.5.22</div>
|
| 55 |
|
| 56 |
<!-- SVG Filters for Liquid Glass Refraction -->
|
| 57 |
<svg width="0" height="0" style="position: absolute; pointer-events: none;">
|
src/services/tts-service.js
CHANGED
|
@@ -54,47 +54,45 @@ class TTSService {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
splitIntoChunks(text) {
|
| 57 |
-
// Cut at sentence boundaries (. ! ?) to keep intonation natural
|
| 58 |
const regex = /[^.!?\n]+[.!?\n]+/g;
|
| 59 |
-
let
|
| 60 |
|
| 61 |
-
if (!
|
| 62 |
-
else if (
|
| 63 |
-
|
| 64 |
}
|
| 65 |
|
| 66 |
-
|
| 67 |
-
chunks = chunks.map(c => c.trim()).filter(c => c.length > 0);
|
| 68 |
|
| 69 |
-
|
| 70 |
-
let
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
}
|
| 86 |
-
}
|
| 87 |
-
if (current.trim()) finalChunks.push(current.trim());
|
| 88 |
-
} else {
|
| 89 |
-
finalChunks.push(sub.trim());
|
| 90 |
-
}
|
| 91 |
-
}
|
| 92 |
} else {
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
}
|
| 95 |
}
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
return
|
| 98 |
}
|
| 99 |
|
| 100 |
queuePreload(index) {
|
|
|
|
| 54 |
}
|
| 55 |
|
| 56 |
splitIntoChunks(text) {
|
|
|
|
| 57 |
const regex = /[^.!?\n]+[.!?\n]+/g;
|
| 58 |
+
let sentences = text.match(regex);
|
| 59 |
|
| 60 |
+
if (!sentences) sentences = [text];
|
| 61 |
+
else if (sentences.join('').length < text.length) {
|
| 62 |
+
sentences.push(text.substring(sentences.join('').length));
|
| 63 |
}
|
| 64 |
|
| 65 |
+
sentences = sentences.map(c => c.trim()).filter(c => c.length > 0);
|
|
|
|
| 66 |
|
| 67 |
+
let chunks = [];
|
| 68 |
+
let currentChunk = '';
|
| 69 |
+
|
| 70 |
+
for (let i = 0; i < sentences.length; i++) {
|
| 71 |
+
const sentence = sentences[i];
|
| 72 |
+
|
| 73 |
+
// Erster Satz: So kurz wie möglich, damit es SOFORT losgeht
|
| 74 |
+
if (chunks.length === 0 && currentChunk === '') {
|
| 75 |
+
chunks.push(sentence);
|
| 76 |
+
continue;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Ab hier: Größere Chunks bilden, damit Generierung < Sprechdauer ist
|
| 80 |
+
if ((currentChunk + ' ' + sentence).length > 250 && currentChunk.length > 0) {
|
| 81 |
+
chunks.push(currentChunk.trim());
|
| 82 |
+
currentChunk = sentence;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
} else {
|
| 84 |
+
currentChunk += (currentChunk.length === 0 ? '' : ' ') + sentence;
|
| 85 |
+
if (currentChunk.length >= 150) {
|
| 86 |
+
chunks.push(currentChunk.trim());
|
| 87 |
+
currentChunk = '';
|
| 88 |
+
}
|
| 89 |
}
|
| 90 |
}
|
| 91 |
+
if (currentChunk.trim().length > 0) {
|
| 92 |
+
chunks.push(currentChunk.trim());
|
| 93 |
+
}
|
| 94 |
|
| 95 |
+
return chunks;
|
| 96 |
}
|
| 97 |
|
| 98 |
queuePreload(index) {
|