Luca448 commited on
Commit
4edb981
·
1 Parent(s): ae9275e

Fix: Optimize TTS chunking to eliminate loading pauses (BUILD 1.5.22)

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. 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.21</div>
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 chunks = text.match(regex);
60
 
61
- if (!chunks) chunks = [text];
62
- else if (chunks.join('').length < text.length) {
63
- chunks.push(text.substring(chunks.join('').length));
64
  }
65
 
66
- // Trim and filter out empty chunks
67
- chunks = chunks.map(c => c.trim()).filter(c => c.length > 0);
68
 
69
- // If a chunk is extremely long (>200 chars), we should split it by commas or spaces to prevent timeouts
70
- let finalChunks = [];
71
- for (let chunk of chunks) {
72
- if (chunk.length > 200) {
73
- const subChunks = chunk.split(/(?<=[,;:])\s+/);
74
- for (let sub of subChunks) {
75
- if (sub.length > 200) {
76
- // Hard split by words
77
- const words = sub.split(/\s+/);
78
- let current = '';
79
- for (let w of words) {
80
- if ((current + ' ' + w).length > 150) {
81
- finalChunks.push(current.trim());
82
- current = w;
83
- } else {
84
- current += ' ' + w;
85
- }
86
- }
87
- if (current.trim()) finalChunks.push(current.trim());
88
- } else {
89
- finalChunks.push(sub.trim());
90
- }
91
- }
92
  } else {
93
- finalChunks.push(chunk);
 
 
 
 
94
  }
95
  }
 
 
 
96
 
97
- return finalChunks;
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) {