@vellumai/assistant 0.10.10-dev.202607201540.7d8113a → 0.10.10-dev.202607201635.61498a8
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/package.json
CHANGED
|
@@ -73,6 +73,12 @@ const LOUD_CHUNK = pcm(8_000);
|
|
|
73
73
|
// chunk trips barge-in. Must stay above that default.
|
|
74
74
|
const SUSTAINED_LOUD_CHUNK = pcm(8_000, 7_200);
|
|
75
75
|
const SILENT_CHUNK = pcm(0);
|
|
76
|
+
// A sub-threshold "ducked" chunk. While the assistant is audibly playing, the
|
|
77
|
+
// browser's half-duplex echo canceller attenuates the user's near-end voice, so
|
|
78
|
+
// the server classifies the post-AEC audio as below the speech-energy gate:
|
|
79
|
+
// a barge-in mid-playback arrives as loud runs split by these ducked gaps.
|
|
80
|
+
// 10 ms at 24 kHz, mean amplitude well under the 800 threshold.
|
|
81
|
+
const DUCKED_CHUNK = pcm(200);
|
|
76
82
|
|
|
77
83
|
class MockStreamingTranscriber implements StreamingTranscriber {
|
|
78
84
|
readonly providerId = "deepgram" as const;
|
|
@@ -2443,31 +2449,118 @@ describe("LiveVoiceSession sustained-speech barge-in guard", () => {
|
|
|
2443
2449
|
await waitFor(() => abort.mock.calls.length === 1);
|
|
2444
2450
|
});
|
|
2445
2451
|
|
|
2446
|
-
test("a
|
|
2447
|
-
const { frames, session, speakFirstReply } =
|
|
2448
|
-
bargeInMinSpeechMs: 60
|
|
2449
|
-
});
|
|
2452
|
+
test("a brief sub-threshold gap does not reset the sustained-speech run", async () => {
|
|
2453
|
+
const { frames, session, abort, speakFirstReply } =
|
|
2454
|
+
createSpeakingTurnHarness({ bargeInMinSpeechMs: 60 });
|
|
2450
2455
|
await speakFirstReply();
|
|
2451
2456
|
|
|
2452
|
-
// 50 ms of speech,
|
|
2453
|
-
//
|
|
2457
|
+
// 50 ms of speech, then one ducked gap: while the assistant is playing, the
|
|
2458
|
+
// half-duplex echo canceller attenuates the user's voice, so the server
|
|
2459
|
+
// sees a sub-threshold chunk mid-utterance. The gap (10 ms) is far shorter
|
|
2460
|
+
// than BARGE_IN_GAP_TOLERANCE_MS, so it must NOT zero the run.
|
|
2454
2461
|
for (let index = 0; index < 5; index += 1) {
|
|
2455
2462
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2456
2463
|
}
|
|
2457
|
-
await session.handleBinaryAudio(
|
|
2464
|
+
await session.handleBinaryAudio(DUCKED_CHUNK);
|
|
2465
|
+
await flushAsyncCallbacks();
|
|
2466
|
+
expect(countType(frames, "turn_cancelled")).toBe(0);
|
|
2467
|
+
|
|
2468
|
+
// A single further speech chunk carries the retained 50 ms run across the
|
|
2469
|
+
// gap to the 60 ms guard and cancels: the gap left the accumulator intact,
|
|
2470
|
+
// so one more 10 ms chunk is enough rather than a fresh 60 ms run.
|
|
2471
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2472
|
+
await waitFor(() =>
|
|
2473
|
+
frames.some((frame) => frame.type === "turn_cancelled"),
|
|
2474
|
+
);
|
|
2475
|
+
expect(
|
|
2476
|
+
frames.find((frame) => frame.type === "turn_cancelled"),
|
|
2477
|
+
).toMatchObject({ type: "turn_cancelled", turnId: "live-turn-1" });
|
|
2478
|
+
await waitFor(() => abort.mock.calls.length === 1);
|
|
2479
|
+
});
|
|
2480
|
+
|
|
2481
|
+
test("a gap longer than the tolerance resets the sustained-speech run", async () => {
|
|
2482
|
+
const { frames, session, abort, speakFirstReply } =
|
|
2483
|
+
createSpeakingTurnHarness({ bargeInMinSpeechMs: 60 });
|
|
2484
|
+
await speakFirstReply();
|
|
2485
|
+
|
|
2486
|
+
// 50 ms of speech, then a ducked gap longer than BARGE_IN_GAP_TOLERANCE_MS
|
|
2487
|
+
// (25 chunks = 250 ms): a real pause rather than a syllable boundary, so the
|
|
2488
|
+
// run resets. The harness silence threshold is 5 s, so the detector never
|
|
2489
|
+
// ends the utterance here — the reset is the gap-tolerance logic, not
|
|
2490
|
+
// utterance end.
|
|
2491
|
+
for (let index = 0; index < 5; index += 1) {
|
|
2492
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2493
|
+
}
|
|
2494
|
+
for (let index = 0; index < 25; index += 1) {
|
|
2495
|
+
await session.handleBinaryAudio(DUCKED_CHUNK);
|
|
2496
|
+
}
|
|
2497
|
+
// 50 ms more speech: because the run reset, this accumulates from zero and
|
|
2498
|
+
// stays under the 60 ms guard — the two stretches do not sum across the long
|
|
2499
|
+
// gap into a false barge-in.
|
|
2458
2500
|
for (let index = 0; index < 5; index += 1) {
|
|
2459
2501
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2460
2502
|
}
|
|
2461
2503
|
await flushAsyncCallbacks();
|
|
2462
2504
|
expect(countType(frames, "turn_cancelled")).toBe(0);
|
|
2505
|
+
expect(abort).not.toHaveBeenCalled();
|
|
2463
2506
|
|
|
2464
|
-
// A 6th consecutive speech chunk completes a
|
|
2507
|
+
// A 6th consecutive speech chunk (with the 5 above) completes a fresh 60 ms
|
|
2508
|
+
// run after the reset and cancels normally.
|
|
2465
2509
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2466
2510
|
await waitFor(() =>
|
|
2467
2511
|
frames.some((frame) => frame.type === "turn_cancelled"),
|
|
2468
2512
|
);
|
|
2469
2513
|
});
|
|
2470
2514
|
|
|
2515
|
+
test("a gap of exactly the tolerance is tolerated and does not reset the run", async () => {
|
|
2516
|
+
const { frames, session, abort, speakFirstReply } =
|
|
2517
|
+
createSpeakingTurnHarness({ bargeInMinSpeechMs: 60 });
|
|
2518
|
+
await speakFirstReply();
|
|
2519
|
+
|
|
2520
|
+
// 50 ms of speech, then a ducked gap of exactly BARGE_IN_GAP_TOLERANCE_MS
|
|
2521
|
+
// (20 chunks = 200 ms). The tolerance is inclusive — the web client batches
|
|
2522
|
+
// PCM into 50 ms frames, so a ducked run lands on the boundary exactly — so
|
|
2523
|
+
// this gap does not reset the accumulated speech.
|
|
2524
|
+
for (let index = 0; index < 5; index += 1) {
|
|
2525
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2526
|
+
}
|
|
2527
|
+
for (let index = 0; index < 20; index += 1) {
|
|
2528
|
+
await session.handleBinaryAudio(DUCKED_CHUNK);
|
|
2529
|
+
}
|
|
2530
|
+
// One more speech chunk carries the retained 50 ms run to the 60 ms guard
|
|
2531
|
+
// and cancels — proof the exactly-200 ms gap left the accumulator intact.
|
|
2532
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2533
|
+
await waitFor(() =>
|
|
2534
|
+
frames.some((frame) => frame.type === "turn_cancelled"),
|
|
2535
|
+
);
|
|
2536
|
+
expect(
|
|
2537
|
+
frames.find((frame) => frame.type === "turn_cancelled"),
|
|
2538
|
+
).toMatchObject({ type: "turn_cancelled", turnId: "live-turn-1" });
|
|
2539
|
+
await waitFor(() => abort.mock.calls.length === 1);
|
|
2540
|
+
});
|
|
2541
|
+
|
|
2542
|
+
test("sparse periodic blips separated by boundary gaps do not accumulate into a barge-in", async () => {
|
|
2543
|
+
const { frames, session, abort, speakFirstReply } =
|
|
2544
|
+
createSpeakingTurnHarness({ bargeInMinSpeechMs: 60 });
|
|
2545
|
+
await speakFirstReply();
|
|
2546
|
+
|
|
2547
|
+
// A 10 ms blip every 200 ms models residual echo/noise, not sustained
|
|
2548
|
+
// speech: each blip clears the consecutive-gap timer while the boundary gap
|
|
2549
|
+
// (20 chunks = 200 ms) escapes the per-gap reset. Enough cycles to reach the
|
|
2550
|
+
// 60 ms guard by pure blip-summing (6 blips) plus margin. The duty-cycle
|
|
2551
|
+
// ceiling (cumulative tolerated silence > bargeInMinSpeechMs * 4 = 240 ms)
|
|
2552
|
+
// resets the run every few cycles, so the blips never sum into a barge-in.
|
|
2553
|
+
for (let cycle = 0; cycle < 9; cycle += 1) {
|
|
2554
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
2555
|
+
for (let index = 0; index < 20; index += 1) {
|
|
2556
|
+
await session.handleBinaryAudio(DUCKED_CHUNK);
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
await flushAsyncCallbacks();
|
|
2560
|
+
expect(countType(frames, "turn_cancelled")).toBe(0);
|
|
2561
|
+
expect(abort).not.toHaveBeenCalled();
|
|
2562
|
+
});
|
|
2563
|
+
|
|
2471
2564
|
test("bargeInMinSpeechMs 0 restores instant barge-in", async () => {
|
|
2472
2565
|
const { frames, session, abort, speakFirstReply } =
|
|
2473
2566
|
createSpeakingTurnHarness({ bargeInMinSpeechMs: 0 });
|
|
@@ -109,6 +109,24 @@ const FINALIZE_GRACE_MS = 1_000;
|
|
|
109
109
|
// liveVoice.vad.bargeInMinSpeechMs schema default; 0 disables the guard for
|
|
110
110
|
// instant barge-in.
|
|
111
111
|
const DEFAULT_BARGE_IN_MIN_SPEECH_MS = 250;
|
|
112
|
+
// Longest continuous sub-threshold gap the sustained-speech barge-in run
|
|
113
|
+
// tolerates without resetting. A gap this short is a syllable boundary, or the
|
|
114
|
+
// choppy energy the browser's half-duplex echo canceller produces while the
|
|
115
|
+
// assistant is still playing (it ducks the user's near-end voice, so post-AEC
|
|
116
|
+
// user speech arrives as intermittent above-gate chunks) — so the run keeps
|
|
117
|
+
// accumulating across it and a barge-in during playback still lands. Only a
|
|
118
|
+
// longer continuous silence (a real end of speech, or an isolated cough) resets
|
|
119
|
+
// the run.
|
|
120
|
+
const BARGE_IN_GAP_TOLERANCE_MS = 200;
|
|
121
|
+
// Ceiling on cumulative sub-threshold time across a whole barge-in run, as a
|
|
122
|
+
// multiple of bargeInMinSpeechMs. Per-gap tolerance alone lets sparse isolated
|
|
123
|
+
// blips (e.g. a 10 ms echo spike every 200 ms) each clear the consecutive-gap
|
|
124
|
+
// timer while retaining prior speech, so they would sum to the guard over
|
|
125
|
+
// several seconds and fire a barge-in with no sustained user speech. Capping the
|
|
126
|
+
// run's total tolerated silence imposes a minimum above-gate duty cycle
|
|
127
|
+
// (1 / (1 + ratio) ≈ 20%): once the run is mostly silence it resets, so genuine
|
|
128
|
+
// choppy speech still lands but periodic noise cannot accumulate into one.
|
|
129
|
+
const BARGE_IN_MAX_TOLERATED_SILENCE_RATIO = 4;
|
|
112
130
|
// At most this many TTS segment jobs are open (provider stream started,
|
|
113
131
|
// frames not yet fully emitted) per turn: the emitting job plus one
|
|
114
132
|
// prefetching job. The prefetch buffers its chunks in memory until promoted;
|
|
@@ -457,15 +475,25 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
457
475
|
// sensitivity" live (see applyConfigUpdate).
|
|
458
476
|
private bargeInMinSpeechMs: number;
|
|
459
477
|
// Sustained-speech barge-in guard, armed at speech onset while the
|
|
460
|
-
// assistant turn is audibly speaking:
|
|
478
|
+
// assistant turn is audibly speaking: above-gate speech-chunk duration
|
|
461
479
|
// accumulates until it reaches bargeInMinSpeechMs, then the deferred
|
|
462
|
-
// speech_started + barge-in fire (at most once per onset).
|
|
463
|
-
//
|
|
480
|
+
// speech_started + barge-in fire (at most once per onset). Brief sub-threshold
|
|
481
|
+
// gaps are tolerated (see BARGE_IN_GAP_TOLERANCE_MS); the run resets on a
|
|
482
|
+
// single longer continuous silence, or once cumulative tolerated silence
|
|
483
|
+
// exceeds the duty-cycle ceiling (see BARGE_IN_MAX_TOLERATED_SILENCE_RATIO).
|
|
484
|
+
// The detector's utterance end discards the guard.
|
|
464
485
|
private pendingBargeIn: {
|
|
465
486
|
// Null when guarding only the post-tts_done drain window (the turn is
|
|
466
487
|
// already finalized but the client is still playing its tail).
|
|
467
488
|
turn: ActiveAssistantTurn | null;
|
|
468
489
|
speechMs: number;
|
|
490
|
+
// Consecutive sub-threshold (non-speech) time since the last speech chunk;
|
|
491
|
+
// resets speechMs once it exceeds BARGE_IN_GAP_TOLERANCE_MS.
|
|
492
|
+
silenceMs: number;
|
|
493
|
+
// Cumulative sub-threshold time over the whole run (not reset by speech
|
|
494
|
+
// chunks); resets speechMs once it exceeds the duty-cycle ceiling so sparse
|
|
495
|
+
// periodic blips cannot sum into a barge-in.
|
|
496
|
+
toleratedSilenceMs: number;
|
|
469
497
|
} | null = null;
|
|
470
498
|
// Estimated wall-clock ms until the client finishes draining the
|
|
471
499
|
// assistant audio sent so far. The server clears the turn right after
|
|
@@ -1091,7 +1119,12 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1091
1119
|
if ((bargeableTurn || drainingPlayback) && this.bargeInMinSpeechMs > 0) {
|
|
1092
1120
|
// Onset audio keeps flowing into the cycle/pre-roll while the guard
|
|
1093
1121
|
// accumulates (trackBargeInGuard), so no speech is lost either way.
|
|
1094
|
-
this.pendingBargeIn = {
|
|
1122
|
+
this.pendingBargeIn = {
|
|
1123
|
+
turn: bargeableTurn,
|
|
1124
|
+
speechMs: 0,
|
|
1125
|
+
silenceMs: 0,
|
|
1126
|
+
toleratedSilenceMs: 0,
|
|
1127
|
+
};
|
|
1095
1128
|
return;
|
|
1096
1129
|
}
|
|
1097
1130
|
|
|
@@ -1104,22 +1137,42 @@ export class LiveVoiceSession implements LiveVoiceSessionContract {
|
|
|
1104
1137
|
}
|
|
1105
1138
|
|
|
1106
1139
|
// Advances the sustained-speech barge-in guard by one server-VAD chunk:
|
|
1107
|
-
//
|
|
1108
|
-
//
|
|
1109
|
-
//
|
|
1140
|
+
// above-gate speech accumulates toward bargeInMinSpeechMs while brief
|
|
1141
|
+
// sub-threshold gaps are tolerated (a single continuous silence longer than
|
|
1142
|
+
// BARGE_IN_GAP_TOLERANCE_MS, or cumulative tolerated silence past the
|
|
1143
|
+
// duty-cycle ceiling, zeroes the run), and once met the deferred
|
|
1144
|
+
// speech_started + barge-in fire.
|
|
1110
1145
|
private trackBargeInGuard(hasSpeech: boolean, chunk: Buffer): void {
|
|
1111
1146
|
const guard = this.pendingBargeIn;
|
|
1112
1147
|
if (!guard) {
|
|
1113
1148
|
return;
|
|
1114
1149
|
}
|
|
1115
|
-
|
|
1116
|
-
guard.speechMs = 0;
|
|
1117
|
-
return;
|
|
1118
|
-
}
|
|
1119
|
-
guard.speechMs += pcm16DurationMs(
|
|
1150
|
+
const chunkMs = pcm16DurationMs(
|
|
1120
1151
|
chunk.byteLength,
|
|
1121
1152
|
this.context.startFrame.audio.sampleRate,
|
|
1122
1153
|
);
|
|
1154
|
+
if (!hasSpeech) {
|
|
1155
|
+
guard.silenceMs += chunkMs;
|
|
1156
|
+
guard.toleratedSilenceMs += chunkMs;
|
|
1157
|
+
// Strictly greater on the per-gap check: a gap of exactly
|
|
1158
|
+
// BARGE_IN_GAP_TOLERANCE_MS is still tolerated. The web client batches PCM
|
|
1159
|
+
// into 50 ms frames, so a run of ducked frames lands on the boundary
|
|
1160
|
+
// exactly (e.g. four frames = 200 ms). The run also resets once its total
|
|
1161
|
+
// tolerated silence outweighs the speech by the duty-cycle ceiling, so
|
|
1162
|
+
// sparse periodic blips can never sum to the guard.
|
|
1163
|
+
if (
|
|
1164
|
+
guard.silenceMs > BARGE_IN_GAP_TOLERANCE_MS ||
|
|
1165
|
+
guard.toleratedSilenceMs >
|
|
1166
|
+
this.bargeInMinSpeechMs * BARGE_IN_MAX_TOLERATED_SILENCE_RATIO
|
|
1167
|
+
) {
|
|
1168
|
+
guard.speechMs = 0;
|
|
1169
|
+
guard.silenceMs = 0;
|
|
1170
|
+
guard.toleratedSilenceMs = 0;
|
|
1171
|
+
}
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
guard.silenceMs = 0;
|
|
1175
|
+
guard.speechMs += chunkMs;
|
|
1123
1176
|
if (guard.speechMs < this.bargeInMinSpeechMs) {
|
|
1124
1177
|
return;
|
|
1125
1178
|
}
|