Spaces:
Running
Running
Preserve full transcripts across overlapping speech chunks
Browse files- app.js +6 -11
- index.html +1 -1
- pnc-worker.js +7 -6
- worker.js +4 -0
app.js
CHANGED
|
@@ -91,8 +91,8 @@ const state = {
|
|
| 91 |
level: 0,
|
| 92 |
};
|
| 93 |
|
| 94 |
-
const worker = new Worker(signedAsset("worker.js?v=
|
| 95 |
-
const pncWorker = new Worker(signedAsset("pnc-worker.js?v=
|
| 96 |
|
| 97 |
function setStatus(text, detail = "", kind = "loading") {
|
| 98 |
elements.statusText.textContent = text;
|
|
@@ -301,28 +301,23 @@ function setConversationVisible(visible) {
|
|
| 301 |
|
| 302 |
function renderWords(paragraph, segment, animate) {
|
| 303 |
paragraph.replaceChildren();
|
| 304 |
-
const words =
|
| 305 |
-
? segment.words
|
| 306 |
-
: String(segment.text || "").split(/\s+/).filter(Boolean).map((text) => ({text}));
|
| 307 |
words.forEach((word, index) => {
|
| 308 |
if (index) paragraph.appendChild(document.createTextNode(" "));
|
| 309 |
const span = document.createElement("span");
|
| 310 |
span.className = `word${animate ? " reveal-word" : ""}`;
|
| 311 |
-
span.textContent = word
|
| 312 |
if (animate) span.style.animationDelay = `${Math.min(index * 45, 180)}ms`;
|
| 313 |
paragraph.appendChild(span);
|
| 314 |
});
|
| 315 |
}
|
| 316 |
|
| 317 |
function updateWords(paragraph, segment, animate) {
|
| 318 |
-
const words =
|
| 319 |
-
? segment.words
|
| 320 |
-
: String(segment.text || "").split(/\s+/).filter(Boolean).map((text) => ({text}));
|
| 321 |
const spans = Array.from(paragraph.querySelectorAll(".word"));
|
| 322 |
if (!animate && spans.length === words.length) {
|
| 323 |
spans.forEach((span, index) => {
|
| 324 |
-
|
| 325 |
-
span.textContent = word.text;
|
| 326 |
});
|
| 327 |
return;
|
| 328 |
}
|
|
|
|
| 91 |
level: 0,
|
| 92 |
};
|
| 93 |
|
| 94 |
+
const worker = new Worker(signedAsset("worker.js?v=20260927-1"));
|
| 95 |
+
const pncWorker = new Worker(signedAsset("pnc-worker.js?v=20260927-1"));
|
| 96 |
|
| 97 |
function setStatus(text, detail = "", kind = "loading") {
|
| 98 |
elements.statusText.textContent = text;
|
|
|
|
| 301 |
|
| 302 |
function renderWords(paragraph, segment, animate) {
|
| 303 |
paragraph.replaceChildren();
|
| 304 |
+
const words = String(segment.text || "").split(/\s+/).filter(Boolean);
|
|
|
|
|
|
|
| 305 |
words.forEach((word, index) => {
|
| 306 |
if (index) paragraph.appendChild(document.createTextNode(" "));
|
| 307 |
const span = document.createElement("span");
|
| 308 |
span.className = `word${animate ? " reveal-word" : ""}`;
|
| 309 |
+
span.textContent = word;
|
| 310 |
if (animate) span.style.animationDelay = `${Math.min(index * 45, 180)}ms`;
|
| 311 |
paragraph.appendChild(span);
|
| 312 |
});
|
| 313 |
}
|
| 314 |
|
| 315 |
function updateWords(paragraph, segment, animate) {
|
| 316 |
+
const words = String(segment.text || "").split(/\s+/).filter(Boolean);
|
|
|
|
|
|
|
| 317 |
const spans = Array.from(paragraph.querySelectorAll(".word"));
|
| 318 |
if (!animate && spans.length === words.length) {
|
| 319 |
spans.forEach((span, index) => {
|
| 320 |
+
span.textContent = words[index];
|
|
|
|
| 321 |
});
|
| 322 |
return;
|
| 323 |
}
|
index.html
CHANGED
|
@@ -195,6 +195,6 @@
|
|
| 195 |
</form>
|
| 196 |
</dialog>
|
| 197 |
|
| 198 |
-
<script src="app.js?v=
|
| 199 |
</body>
|
| 200 |
</html>
|
|
|
|
| 195 |
</form>
|
| 196 |
</dialog>
|
| 197 |
|
| 198 |
+
<script src="app.js?v=20260927-1" type="module"></script>
|
| 199 |
</body>
|
| 200 |
</html>
|
pnc-worker.js
CHANGED
|
@@ -266,20 +266,21 @@ async function punctuateSegments(segments) {
|
|
| 266 |
const counts = [];
|
| 267 |
const sourceWords = [];
|
| 268 |
segments.forEach((segment) => {
|
| 269 |
-
const words =
|
| 270 |
-
? segment.words.map((word) => word.text)
|
| 271 |
-
: String(segment.text || "").trim().split(/\s+/).filter(Boolean);
|
| 272 |
counts.push(words.length);
|
| 273 |
sourceWords.push(...words);
|
| 274 |
});
|
| 275 |
const renderedWords = stabilizeRenderedWords(await punctuateWords(sourceWords));
|
| 276 |
let offset = 0;
|
| 277 |
return segments.map((segment, segmentIndex) => {
|
| 278 |
-
const
|
|
|
|
| 279 |
offset += counts[segmentIndex];
|
| 280 |
-
const
|
|
|
|
|
|
|
| 281 |
? segment.words.map((word, wordIndex) => ({...word, text: rendered[wordIndex]}))
|
| 282 |
-
:
|
| 283 |
return {
|
| 284 |
...segment,
|
| 285 |
rawText: segment.rawText || segment.text,
|
|
|
|
| 266 |
const counts = [];
|
| 267 |
const sourceWords = [];
|
| 268 |
segments.forEach((segment) => {
|
| 269 |
+
const words = String(segment.text || "").trim().split(/\s+/).filter(Boolean);
|
|
|
|
|
|
|
| 270 |
counts.push(words.length);
|
| 271 |
sourceWords.push(...words);
|
| 272 |
});
|
| 273 |
const renderedWords = stabilizeRenderedWords(await punctuateWords(sourceWords));
|
| 274 |
let offset = 0;
|
| 275 |
return segments.map((segment, segmentIndex) => {
|
| 276 |
+
const start = offset;
|
| 277 |
+
const rendered = renderedWords.slice(start, start + counts[segmentIndex]);
|
| 278 |
offset += counts[segmentIndex];
|
| 279 |
+
const timedWords = Array.isArray(segment.words) && segment.words.length === rendered.length
|
| 280 |
+
&& segment.words.every((word, index) => word.text === sourceWords[start + index]);
|
| 281 |
+
const words = timedWords
|
| 282 |
? segment.words.map((word, wordIndex) => ({...word, text: rendered[wordIndex]}))
|
| 283 |
+
: [];
|
| 284 |
return {
|
| 285 |
...segment,
|
| 286 |
rawText: segment.rawText || segment.text,
|
worker.js
CHANGED
|
@@ -303,6 +303,10 @@ function toWords(result, duration, timeOffset = 0) {
|
|
| 303 |
const fallback = timestamps.length ? Number(timestamps[timestamps.length - 1]) + 0.08 : start;
|
| 304 |
finish(fallback);
|
| 305 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
return words;
|
| 307 |
}
|
| 308 |
|
|
|
|
| 303 |
const fallback = timestamps.length ? Number(timestamps[timestamps.length - 1]) + 0.08 : start;
|
| 304 |
finish(fallback);
|
| 305 |
}
|
| 306 |
+
// The recognizer's text is authoritative. A partial token/timestamp list
|
| 307 |
+
// must never become a partial transcript downstream.
|
| 308 |
+
const decodedText = String(result.text || "").trim().replace(/\s+/g, " ");
|
| 309 |
+
if (words.map((word) => word.text).join(" ") !== decodedText) return [];
|
| 310 |
return words;
|
| 311 |
}
|
| 312 |
|