@vellumai/assistant 0.12.2-dev.202609211515.9bea579 → 0.12.2-dev.202609211713.ad8242b
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/docs/voice-input-diagnostics.md +9 -4
- package/package.json +1 -1
- package/src/calls/__tests__/barge-in-guard.test.ts +3 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +34 -0
- package/src/calls/barge-in-guard.ts +5 -0
- package/src/calls/voice-session-bridge.ts +6 -4
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +316 -31
- package/src/live-voice/__tests__/live-voice-look-follow-up.test.ts +191 -10
- package/src/live-voice/__tests__/session-controls.test.ts +23 -0
- package/src/live-voice/live-voice-session.ts +212 -131
- package/src/live-voice/session-controls.ts +11 -3
- package/src/providers/speech-to-text/__tests__/vellum-managed-realtime.test.ts +50 -1
- package/src/providers/speech-to-text/vellum-managed-flux-realtime.ts +13 -0
|
@@ -30,8 +30,9 @@ Search the assistant log for `Live voice input diagnostics` or `voice_input_`. A
|
|
|
30
30
|
- `voice_input_window` summarizes each approximately five-second arrival window: received audio duration, zero-signal duration, duration-weighted mean amplitude, minimum/maximum chunk mean amplitude, classified speech/silence/echo duration, and maximum arrival gap. Window emission requires incoming audio; `voice_input_closed` flushes a partial window.
|
|
31
31
|
- The same window includes `sttSubmittedChunks`, `sttSubmittedAudioMs`, and `sttMaxSubmissionGapMs`. These measure handoff to the transcription adapter, not provider receipt. A probe can buffer audio before submission, and the final chunk of an arrival window can be submitted in the next window. Compare sustained windows to identify input that arrives normally but stops reaching transcription.
|
|
32
32
|
- `voice_input_provider_turn_start` and `voice_input_provider_turn_end` record provider boundaries alongside local VAD state. End records include confidence, the provider's `trigger` (`model`, `timeout`, or `manual`), decoded audio position in seconds from stream start, and elapsed time since locally detected speech. Missing provider fields are null. These records describe received decisions, including ones ignored as stale or after fallback; correlate with the turn metrics to identify the boundary that committed the request.
|
|
33
|
-
- `voice_input_microphone_gate_changed` records when the transcription audio gate closes or reopens. `microphoneGateClosed` is included with the other input diagnostics. Closing replaces room audio with silence; it does not commit a transcript or stop local
|
|
34
|
-
- `voice_input_barge_in_armed`, `voice_input_barge_in_fired`, and `voice_input_barge_in_expired` distinguish a candidate from an accepted or expired interruption. Fired events include accumulated speech duration, guard resets, and a bounded trace of the preceding two seconds (at most 40 input chunks).
|
|
33
|
+
- `voice_input_microphone_gate_changed` records when the transcription audio gate closes or reopens. `microphoneGateClosed` is included with the other input diagnostics. Closing replaces room audio with silence; it does not commit a transcript or stop local energy detection.
|
|
34
|
+
- `voice_input_barge_in_armed`, `voice_input_barge_in_fired`, and `voice_input_barge_in_expired` distinguish a candidate from an accepted or expired local interruption on providers without native turn detection. Fired events include accumulated speech duration, guard resets, and a bounded trace of the preceding two seconds (at most 40 input chunks).
|
|
35
|
+
- `voice_input_speech_started` includes `source: "provider"` when a Flux `StartOfTurn` triggers the client speech signal and any active-turn cancellation. `source: "local"` identifies local onset or a confirmed pre-dial guard replay; guards completed during ordinary streaming use `voice_input_barge_in_fired`.
|
|
35
36
|
- Each trace entry captures the amplitude and gate/echo state before classification, and classified durations, remaining probe buffer, and correlation result after classification. The classifier can hold a probe and release multiple older chunks together, so a row's classified duration can differ from its received duration. A null correlation means no comparison ran, not a measured zero correlation.
|
|
36
37
|
- `voice_input_speech_routed` binds the speech generation to the input turn that actually receives its audio. At onset, the prior spent cycle may still be installed, so use this routing record for correlation rather than assuming the onset's `inputTurnId` is the new utterance.
|
|
37
38
|
- `voice_input_transcript` reports committed character count and provider, never words. `voice_input_utterance_discarded` reports the discard reason and remaining transcript/partial state.
|
|
@@ -42,9 +43,13 @@ These are local diagnostic logs, not new analytics events or voice protocol fiel
|
|
|
42
43
|
|
|
43
44
|
## Flux pause handling
|
|
44
45
|
|
|
45
|
-
When Flux owns turn detection, microphone audio passes through for one second of received audio after the last locally detected speech. After that, the input gate replaces room audio with digital silence while the microphone and local
|
|
46
|
+
When Flux owns turn detection, microphone audio passes through for one second of received audio after the last locally detected speech. After that, the input gate replaces room audio with digital silence while the microphone and local energy detector keep listening. The cutoff is measured in PCM samples, so network batching does not change it. Flux continues receiving elapsed silence and owns the turn boundary; closing this gate does not release the question.
|
|
46
47
|
|
|
47
|
-
While closed, the gate holds the most recent 200 ms before deciding whether to send those samples as silence or as the lead-in to resumed speech. On speech onset, it forwards that lead-in and the new speech exactly once. The provider feed can lag input by up to 200 ms while idle, then catches up on speech onset. Confirmed playback echo is replaced with silence before entering this buffer.
|
|
48
|
+
While closed, the gate holds the most recent 200 ms before deciding whether to send those samples as silence or as the lead-in to resumed speech. On speech onset, it forwards that lead-in and the new speech exactly once. The provider feed can lag input by up to 200 ms while idle, then catches up on speech onset. Confirmed playback echo is replaced with silence before entering this buffer. Idle audio is not accumulated into request recordings. Manual capture and locally endpointed providers retain their existing routing.
|
|
49
|
+
|
|
50
|
+
Flux `StartOfTurn` owns hands-free interruption, independently of the provider end-of-turn setting. Above-threshold microphone audio alone cannot pause playback, cancel a reply, or trigger a speech-start screenshot. A provider turn start emits `speech_started` immediately, without the local sustained-speech delay, and cancels an active reply through the shared interruption path. Duplicate or older provider turn indices are ignored within a stream. Other providers retain the local guard. This waits for provider recognition and does not guarantee rejection of playback echo or background speech that Flux transcribes.
|
|
51
|
+
|
|
52
|
+
Managed Flux maps provider turn indices into one continuous sequence across transparent relay reconnects. A new relay connection restarting at zero therefore cannot make fresh speech look like a duplicate. If connection setup falls back to a provider without native turn detection, the suppressed local onset is replayed through the local interruption path, preserving its sustained-speech guard result even if the utterance ended during the dial.
|
|
48
53
|
|
|
49
54
|
The gate shares the existing adaptive energy classifier. Quiet speech within the one-second tail passes through; quiet onset in the 200 ms buffer is preserved if followed by detected speech. Sustained speech entirely below the local threshold can be suppressed, and noise classified as speech can reopen the gate. This limits background exposure rather than guaranteeing that every false transcript is eliminated.
|
|
50
55
|
|
package/package.json
CHANGED
|
@@ -12,13 +12,16 @@ describe("createBargeInGuard", () => {
|
|
|
12
12
|
expect(guard.track("speech", 100)).toBe("pending");
|
|
13
13
|
expect(guard.track("speech", 100)).toBe("pending");
|
|
14
14
|
expect(guard.speechMs).toBe(200);
|
|
15
|
+
expect(guard.fired).toBe(false);
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
test("sustained speech reaching the threshold fires once and stays fired", () => {
|
|
18
19
|
const guard = createBargeInGuard(250);
|
|
19
20
|
guard.track("speech", 200);
|
|
20
21
|
expect(guard.track("speech", 50)).toBe("fired");
|
|
22
|
+
expect(guard.fired).toBe(true);
|
|
21
23
|
expect(guard.track("silence", 1_000)).toBe("fired");
|
|
24
|
+
expect(guard.fired).toBe(true);
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
test("a brief sub-threshold gap does not reset the run", () => {
|
|
@@ -974,6 +974,22 @@ describe("startVoiceTurn triage-and-escalate control prompt", () => {
|
|
|
974
974
|
expect(installed()).toContain(frontDoorDecisionRule({ includeHold: true }));
|
|
975
975
|
});
|
|
976
976
|
|
|
977
|
+
test("a hidden look follow-up routes the original request", async () => {
|
|
978
|
+
const installed = captureInstalledPrompt();
|
|
979
|
+
const callerUtterance = "Show me where to add a new page.";
|
|
980
|
+
const content = "(fresh view taken; answer from it now)";
|
|
981
|
+
await startVoiceTurn({
|
|
982
|
+
...makeTurnOptions(),
|
|
983
|
+
content,
|
|
984
|
+
routingUtterance: callerUtterance,
|
|
985
|
+
hiddenSyntheticPrompt: true,
|
|
986
|
+
voiceControlPrompt: LIVE_VOICE_PROMPT,
|
|
987
|
+
routingLeg: "front-door",
|
|
988
|
+
});
|
|
989
|
+
expect(installed()).toContain(frontDoorDecisionRule({ callerUtterance }));
|
|
990
|
+
expect(installed()).not.toContain(JSON.stringify(content));
|
|
991
|
+
});
|
|
992
|
+
|
|
977
993
|
test("appends the escalated continuation rule to a caller-supplied prompt", async () => {
|
|
978
994
|
const installed = captureInstalledPrompt();
|
|
979
995
|
await startVoiceTurn({
|
|
@@ -3449,4 +3465,22 @@ describe("startVoiceTurn escalation judge", () => {
|
|
|
3449
3465
|
expect(handle.overrule).toBeUndefined();
|
|
3450
3466
|
}
|
|
3451
3467
|
});
|
|
3468
|
+
|
|
3469
|
+
test.each([
|
|
3470
|
+
"What do you see on my screen?",
|
|
3471
|
+
"Show me where to add a new page.",
|
|
3472
|
+
])("a captured look bypasses the text-only judge: %s", async (request) => {
|
|
3473
|
+
judgeEscalationVerdict = true;
|
|
3474
|
+
const handle = await startVoiceTurn({
|
|
3475
|
+
...makeTurnOptions(),
|
|
3476
|
+
content: "(fresh view taken; answer from it now)",
|
|
3477
|
+
routingUtterance: request,
|
|
3478
|
+
routingLeg: "front-door",
|
|
3479
|
+
hiddenSyntheticPrompt: true,
|
|
3480
|
+
});
|
|
3481
|
+
|
|
3482
|
+
expect(judgeEscalationCalls).toEqual([]);
|
|
3483
|
+
expect(handle.escalationJudgement).toBeUndefined();
|
|
3484
|
+
expect(handle.overrule).toBeUndefined();
|
|
3485
|
+
});
|
|
3452
3486
|
});
|
|
@@ -55,6 +55,8 @@ export type BargeInGuardStep = "pending" | "reset" | "fired";
|
|
|
55
55
|
export interface BargeInGuard {
|
|
56
56
|
/** Speech accumulated in the current run. */
|
|
57
57
|
readonly speechMs: number;
|
|
58
|
+
/** Whether this run has met the threshold, latched until the guard is replaced. */
|
|
59
|
+
readonly fired: boolean;
|
|
58
60
|
/** Feed one classified chunk of `chunkMs` audio. */
|
|
59
61
|
track(
|
|
60
62
|
classification: BargeInChunkClassification,
|
|
@@ -82,6 +84,9 @@ export function createBargeInGuard(minSpeechMs: number): BargeInGuard {
|
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
return {
|
|
87
|
+
get fired() {
|
|
88
|
+
return fired;
|
|
89
|
+
},
|
|
85
90
|
get speechMs() {
|
|
86
91
|
return speechMs;
|
|
87
92
|
},
|
|
@@ -524,6 +524,8 @@ export interface VoiceTurnOptions {
|
|
|
524
524
|
* fixed sentinel.
|
|
525
525
|
*/
|
|
526
526
|
hiddenSyntheticPrompt?: boolean;
|
|
527
|
+
/** Original caller request resumed by a synthetic turn, used for routing. */
|
|
528
|
+
routingUtterance?: string;
|
|
527
529
|
/**
|
|
528
530
|
* Unified front-door: this leg was dispatched speculatively at a silence
|
|
529
531
|
* boundary, so its decision rule includes the hold branch (leading token
|
|
@@ -988,10 +990,8 @@ export async function startVoiceTurn(
|
|
|
988
990
|
// control markers (ASK_GUARDIAN, END_CALL, etc.) and recognize opener turns.
|
|
989
991
|
const isCallerGuardian = opts.trustContext?.trustClass === "guardian";
|
|
990
992
|
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
// than the marker itself.
|
|
994
|
-
const routingLegRule = routingLegRuleFor(opts, persistedContent);
|
|
993
|
+
const routingUtterance = opts.routingUtterance?.trim() || persistedContent;
|
|
994
|
+
const routingLegRule = routingLegRuleFor(opts, routingUtterance);
|
|
995
995
|
let voiceCallControlPrompt: string | null;
|
|
996
996
|
if (opts.voiceControlPrompt === undefined) {
|
|
997
997
|
voiceCallControlPrompt = buildVoiceCallControlPrompt({
|
|
@@ -1997,6 +1997,8 @@ export async function startVoiceTurn(
|
|
|
1997
1997
|
// The escalation judge runs beside the front-door leg's model call, so its
|
|
1998
1998
|
// verdict is usually in before the leg's first answer word. Snapshot the
|
|
1999
1999
|
// history now: the leg's own reply must not be part of what is judged.
|
|
2000
|
+
// Hidden fresh-view follow-ups route with their image; this text-only judge
|
|
2001
|
+
// cannot assess that context.
|
|
2000
2002
|
const escalationJudgement =
|
|
2001
2003
|
opts.routingLeg === "front-door" && !isHiddenSyntheticPrompt
|
|
2002
2004
|
? judgeEscalation({
|
|
@@ -55,10 +55,9 @@ const LOUD_CHUNK = pcm(8_000);
|
|
|
55
55
|
const SUSTAINED_LOUD_CHUNK = pcm(8_000, 7_200);
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Flux
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* exactly as Flux does: its transcript is committed by EndOfTurn.
|
|
58
|
+
* Flux has no `finalizeUtterance`: the session keeps the stream open when
|
|
59
|
+
* provider end-of-turn owns the boundary, otherwise it closes each cycle.
|
|
60
|
+
* Events are scripted, and `stop()` only flushes explicitly supplied text.
|
|
62
61
|
*/
|
|
63
62
|
class MockFluxTranscriber implements StreamingTranscriber {
|
|
64
63
|
readonly boundaryId = "daemon-streaming" as const;
|
|
@@ -81,12 +80,19 @@ class MockFluxTranscriber implements StreamingTranscriber {
|
|
|
81
80
|
// Transcript Flux answers `CloseStream` with, for a turn still in flight
|
|
82
81
|
// when the caller released. Null models a stop with nothing left to flush.
|
|
83
82
|
pendingFlushText: string | null = null;
|
|
83
|
+
holdStopEvents = false;
|
|
84
84
|
|
|
85
85
|
stop(): void {
|
|
86
86
|
if (this.stopped) {
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
this.stopped = true;
|
|
90
|
+
if (!this.holdStopEvents) {
|
|
91
|
+
this.flushStopEvents();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
flushStopEvents(): void {
|
|
90
96
|
if (this.pendingFlushText !== null) {
|
|
91
97
|
this.onEvent?.({ type: "final", text: this.pendingFlushText });
|
|
92
98
|
}
|
|
@@ -115,6 +121,7 @@ class MockFluxTranscriber implements StreamingTranscriber {
|
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
function createHarness(options: {
|
|
124
|
+
startFrame?: LiveVoiceClientStartFrame;
|
|
118
125
|
providerId?: SttProviderId;
|
|
119
126
|
fluxConfig?: Partial<LiveVoiceFluxConfig>;
|
|
120
127
|
silenceThresholdMs?: number;
|
|
@@ -126,6 +133,7 @@ function createHarness(options: {
|
|
|
126
133
|
streamTtsAudio?: LiveVoiceTtsStreamer | null;
|
|
127
134
|
emitMetrics?: boolean;
|
|
128
135
|
archiveAudio?: LiveVoiceSessionAudioArchiver;
|
|
136
|
+
bargeInMinSpeechMs?: number;
|
|
129
137
|
// Holds the STT dial open so a test can drive a whole utterance through the
|
|
130
138
|
// window between `ready` and the resolved provider.
|
|
131
139
|
resolveGate?: Promise<unknown>;
|
|
@@ -134,7 +142,7 @@ function createHarness(options: {
|
|
|
134
142
|
const frames: LiveVoiceServerFrame[] = [];
|
|
135
143
|
const context: LiveVoiceSessionFactoryContext = {
|
|
136
144
|
sessionId: "session-123",
|
|
137
|
-
startFrame: VAD_START_FRAME,
|
|
145
|
+
startFrame: options.startFrame ?? VAD_START_FRAME,
|
|
138
146
|
sendFrame: mock(async (payload) => {
|
|
139
147
|
const frame = sequencer.next(payload);
|
|
140
148
|
frames.push(frame);
|
|
@@ -169,6 +177,7 @@ function createHarness(options: {
|
|
|
169
177
|
streamTtsAudio: options.streamTtsAudio ?? null,
|
|
170
178
|
emitMetrics: options.emitMetrics ?? false,
|
|
171
179
|
archiveAudio: options.archiveAudio,
|
|
180
|
+
bargeInMinSpeechMs: options.bargeInMinSpeechMs,
|
|
172
181
|
continuationAnnounceSilenceMs: options.continuationAnnounceSilenceMs,
|
|
173
182
|
spawnBackgroundContinuation: mock(async () => ""),
|
|
174
183
|
turnDetectorConfig: {
|
|
@@ -657,6 +666,8 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
657
666
|
expect(turnCalls).toHaveLength(1);
|
|
658
667
|
await sleep(PAST_SILENCE_BOUNDARY_MS);
|
|
659
668
|
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
669
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
670
|
+
transcriber.startOfTurn(1);
|
|
660
671
|
await waitFor(() => countFrames(frames, "turn_cancelled") === 1);
|
|
661
672
|
expect(transcriber.received.at(-1)).toEqual(
|
|
662
673
|
Buffer.concat([
|
|
@@ -959,10 +970,7 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
959
970
|
// The caller draws breath and keeps going before the provider's turn-end
|
|
960
971
|
// for the speech that boundary closed reaches the session.
|
|
961
972
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
962
|
-
|
|
963
|
-
() => countFrames(frames, "speech_started") === 2,
|
|
964
|
-
"The resumed speech never re-opened a detector turn",
|
|
965
|
-
);
|
|
973
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
966
974
|
const receivedBeforeResume = transcriber?.received.length ?? 0;
|
|
967
975
|
|
|
968
976
|
transcriber?.emit({
|
|
@@ -1006,10 +1014,7 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1006
1014
|
// the cycle to Flux, and then the caller keeps going.
|
|
1007
1015
|
await sleep(PAST_SILENCE_BOUNDARY_MS);
|
|
1008
1016
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1009
|
-
|
|
1010
|
-
() => countFrames(frames, "speech_started") === 2,
|
|
1011
|
-
"The resumed speech never re-opened a detector turn",
|
|
1012
|
-
);
|
|
1017
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1013
1018
|
|
|
1014
1019
|
// Flux ends the turn it kept open across the pause, beating the next local
|
|
1015
1020
|
// silence boundary: the fast commit this feature exists for. Nothing here
|
|
@@ -1053,10 +1058,7 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1053
1058
|
await sleep(PAST_SILENCE_BOUNDARY_MS);
|
|
1054
1059
|
|
|
1055
1060
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1056
|
-
|
|
1057
|
-
() => countFrames(frames, "speech_started") === 2,
|
|
1058
|
-
"The resumed speech never re-opened a detector turn",
|
|
1059
|
-
);
|
|
1061
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1060
1062
|
const receivedBeforeResume = transcriber?.received.length ?? 0;
|
|
1061
1063
|
|
|
1062
1064
|
// Flux closed turn 0 and opened turn 1 for the resumed speech, so the
|
|
@@ -1105,7 +1107,7 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1105
1107
|
await sleep(PAST_SILENCE_BOUNDARY_MS);
|
|
1106
1108
|
|
|
1107
1109
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1108
|
-
|
|
1110
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1109
1111
|
transcribers[0]?.emit({
|
|
1110
1112
|
type: "turn-end",
|
|
1111
1113
|
text: "what is the",
|
|
@@ -1165,10 +1167,14 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1165
1167
|
await session.close("client_end");
|
|
1166
1168
|
}, 10_000);
|
|
1167
1169
|
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1170
|
+
test.each([
|
|
1171
|
+
{ providerId: "deepgram-flux" as const, flagOn: true },
|
|
1172
|
+
{ providerId: "deepgram-flux" as const, flagOn: false },
|
|
1173
|
+
{ providerId: "vellum-flux" as const, flagOn: true },
|
|
1174
|
+
{ providerId: "vellum-flux" as const, flagOn: false },
|
|
1175
|
+
])(
|
|
1176
|
+
"only provider speech starts interrupt playback: %j",
|
|
1177
|
+
async ({ providerId, flagOn }) => {
|
|
1172
1178
|
const streamTtsAudio = mock(async (ttsOptions: LiveVoiceTtsOptions) => {
|
|
1173
1179
|
ttsOptions.onAudioChunk({
|
|
1174
1180
|
type: "tts_audio",
|
|
@@ -1185,7 +1191,8 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1185
1191
|
} satisfies LiveVoiceTtsResult;
|
|
1186
1192
|
});
|
|
1187
1193
|
const { frames, session, transcribers } = createHarness({
|
|
1188
|
-
|
|
1194
|
+
providerId,
|
|
1195
|
+
fluxConfig: flagOn ? FLUX_ON : FLUX_OFF,
|
|
1189
1196
|
silenceThresholdMs: 10_000,
|
|
1190
1197
|
streamTtsAudio,
|
|
1191
1198
|
// The leg never completes, so the turn is still in flight when the
|
|
@@ -1201,28 +1208,182 @@ describe("LiveVoiceSession Flux end-of-turn", () => {
|
|
|
1201
1208
|
await session.start();
|
|
1202
1209
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1203
1210
|
await waitFor(() => transcribers.length > 0);
|
|
1211
|
+
transcribers[0]?.startOfTurn(0);
|
|
1204
1212
|
if (flagOn) {
|
|
1205
1213
|
transcribers[0]?.endOfTurn("tell me a story");
|
|
1206
1214
|
} else {
|
|
1207
1215
|
transcribers[0]?.emit({ type: "final", text: "tell me a story" });
|
|
1208
1216
|
await session.handleClientFrame({ type: "ptt_release" });
|
|
1209
1217
|
}
|
|
1210
|
-
await waitFor(() => frames.some((frame) => frame.type === "
|
|
1218
|
+
await waitFor(() => frames.some((frame) => frame.type === "tts_audio"));
|
|
1211
1219
|
|
|
1212
|
-
|
|
1213
|
-
// interrupts the assistant.
|
|
1220
|
+
const speechStarts = countFrames(frames, "speech_started");
|
|
1214
1221
|
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1222
|
+
await flushAsyncCallbacks();
|
|
1223
|
+
expect(countFrames(frames, "speech_started")).toBe(speechStarts);
|
|
1224
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1225
|
+
|
|
1226
|
+
// Per-cycle streams restart the provider's turn numbering.
|
|
1227
|
+
transcribers.at(-1)?.startOfTurn(flagOn ? 1 : 0);
|
|
1215
1228
|
await waitFor(
|
|
1216
|
-
() => frames
|
|
1217
|
-
"
|
|
1229
|
+
() => countFrames(frames, "speech_started") === speechStarts + 1,
|
|
1230
|
+
"Provider speech start did not interrupt playback",
|
|
1218
1231
|
);
|
|
1219
1232
|
await waitFor(() =>
|
|
1220
1233
|
frames.some((frame) => frame.type === "turn_cancelled"),
|
|
1221
1234
|
);
|
|
1235
|
+
const types = frames.map((frame) => frame.type);
|
|
1236
|
+
expect(types.lastIndexOf("speech_started")).toBeLessThan(
|
|
1237
|
+
types.indexOf("turn_cancelled"),
|
|
1238
|
+
);
|
|
1239
|
+
|
|
1240
|
+
await session.close("client_end");
|
|
1241
|
+
},
|
|
1242
|
+
);
|
|
1243
|
+
|
|
1244
|
+
test("provider speech starts are immediate and ignore duplicate or older turn indices", async () => {
|
|
1245
|
+
const { frames, session, transcribers } = createHarness({
|
|
1246
|
+
fluxConfig: FLUX_ON,
|
|
1247
|
+
bargeInMinSpeechMs: 5_000,
|
|
1248
|
+
});
|
|
1249
|
+
try {
|
|
1250
|
+
await session.start();
|
|
1251
|
+
await waitFor(() => transcribers.length === 1);
|
|
1252
|
+
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1253
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1222
1254
|
|
|
1255
|
+
const transcriber = transcribers[0]!;
|
|
1256
|
+
transcriber.startOfTurn(2);
|
|
1257
|
+
await waitFor(() => countFrames(frames, "speech_started") === 1);
|
|
1258
|
+
transcriber.startOfTurn(2);
|
|
1259
|
+
transcriber.startOfTurn(1);
|
|
1260
|
+
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1261
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1262
|
+
transcriber.startOfTurn(3);
|
|
1263
|
+
await waitFor(() => countFrames(frames, "speech_started") === 2);
|
|
1264
|
+
} finally {
|
|
1223
1265
|
await session.close("client_end");
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
|
|
1269
|
+
test("provider-confirmed quiet speech interrupts a thinking turn", async () => {
|
|
1270
|
+
const abort = mock();
|
|
1271
|
+
const { frames, session, transcribers, turnCalls } = createHarness({
|
|
1272
|
+
fluxConfig: FLUX_ON,
|
|
1273
|
+
bargeInMinSpeechMs: 5_000,
|
|
1274
|
+
startVoiceTurn: async () => ({ turnId: "thinking-turn", abort }),
|
|
1224
1275
|
});
|
|
1225
|
-
|
|
1276
|
+
try {
|
|
1277
|
+
await session.start();
|
|
1278
|
+
await waitFor(() => transcribers.length === 1);
|
|
1279
|
+
const transcriber = transcribers[0]!;
|
|
1280
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1281
|
+
transcriber.startOfTurn(0);
|
|
1282
|
+
transcriber.endOfTurn("start an investigation", 0);
|
|
1283
|
+
await waitFor(() => turnCalls.length === 1);
|
|
1284
|
+
await session.handleBinaryAudio(pcm(100));
|
|
1285
|
+
|
|
1286
|
+
// The previous turn's duplicate cannot interrupt the reply it caused.
|
|
1287
|
+
transcriber.startOfTurn(0);
|
|
1288
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1289
|
+
transcriber.startOfTurn(1);
|
|
1290
|
+
await waitFor(() => countFrames(frames, "turn_cancelled") === 1);
|
|
1291
|
+
expect(countFrames(frames, "speech_started")).toBe(2);
|
|
1292
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
1293
|
+
} finally {
|
|
1294
|
+
await session.close("client_end");
|
|
1295
|
+
}
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
test("provider speech start flushes the playback tail of a completed turn", async () => {
|
|
1299
|
+
const { frames, session, transcribers } = createHarness({
|
|
1300
|
+
fluxConfig: FLUX_ON,
|
|
1301
|
+
startVoiceTurn: autoCompletingTurn(),
|
|
1302
|
+
streamTtsAudio: async (options) => {
|
|
1303
|
+
const audio = pcm(100, SAMPLE_RATE * 2);
|
|
1304
|
+
options.onAudioChunk({
|
|
1305
|
+
type: "tts_audio",
|
|
1306
|
+
contentType: "audio/pcm",
|
|
1307
|
+
sampleRate: SAMPLE_RATE,
|
|
1308
|
+
dataBase64: Buffer.from(audio).toString("base64"),
|
|
1309
|
+
});
|
|
1310
|
+
return {
|
|
1311
|
+
provider: "fish-audio",
|
|
1312
|
+
contentType: "audio/pcm",
|
|
1313
|
+
sampleRate: SAMPLE_RATE,
|
|
1314
|
+
chunks: 1,
|
|
1315
|
+
bytes: audio.byteLength,
|
|
1316
|
+
};
|
|
1317
|
+
},
|
|
1318
|
+
});
|
|
1319
|
+
try {
|
|
1320
|
+
await session.start();
|
|
1321
|
+
await waitFor(() => transcribers.length === 1);
|
|
1322
|
+
const transcriber = transcribers[0]!;
|
|
1323
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1324
|
+
transcriber.startOfTurn(0);
|
|
1325
|
+
transcriber.endOfTurn("tell me a story", 0);
|
|
1326
|
+
await waitFor(() => countFrames(frames, "tts_done") === 1);
|
|
1327
|
+
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1328
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1329
|
+
|
|
1330
|
+
transcriber.startOfTurn(1);
|
|
1331
|
+
await waitFor(() => countFrames(frames, "speech_started") === 2);
|
|
1332
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1333
|
+
} finally {
|
|
1334
|
+
await session.close("client_end");
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
test("provider speech start does not interrupt manual sessions", async () => {
|
|
1339
|
+
const { frames, session, transcribers } = createHarness({
|
|
1340
|
+
startFrame: { ...VAD_START_FRAME, turnDetection: "manual" },
|
|
1341
|
+
fluxConfig: FLUX_ON,
|
|
1342
|
+
});
|
|
1343
|
+
try {
|
|
1344
|
+
await session.start();
|
|
1345
|
+
await waitFor(() => transcribers.length === 1);
|
|
1346
|
+
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1347
|
+
transcribers[0]?.startOfTurn(0);
|
|
1348
|
+
await flushAsyncCallbacks();
|
|
1349
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1350
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1351
|
+
} finally {
|
|
1352
|
+
await session.close("client_end");
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
test("provider speech start discards a pending speculative reply", async () => {
|
|
1357
|
+
const discard = mock(async () => {});
|
|
1358
|
+
const { frames, session, transcribers, turnCalls } = createHarness({
|
|
1359
|
+
fluxConfig: FLUX_OFF,
|
|
1360
|
+
startVoiceTurn: async () => ({
|
|
1361
|
+
turnId: "speculative-turn",
|
|
1362
|
+
abort: mock(),
|
|
1363
|
+
discard,
|
|
1364
|
+
}),
|
|
1365
|
+
});
|
|
1366
|
+
try {
|
|
1367
|
+
await session.start();
|
|
1368
|
+
await waitFor(() => transcribers.length === 1);
|
|
1369
|
+
const transcriber = transcribers[0]!;
|
|
1370
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1371
|
+
transcriber.startOfTurn(0);
|
|
1372
|
+
transcriber.emit({ type: "final", text: "what is the" });
|
|
1373
|
+
await waitFor(() => turnCalls.length === 1);
|
|
1374
|
+
expect(turnCalls[0]?.unifiedVerdict).toBeDefined();
|
|
1375
|
+
|
|
1376
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1377
|
+
expect(discard).not.toHaveBeenCalled();
|
|
1378
|
+
transcriber.startOfTurn(1);
|
|
1379
|
+
await waitFor(() => discard.mock.calls.length === 1);
|
|
1380
|
+
await flushAsyncCallbacks();
|
|
1381
|
+
expect(countFrames(frames, "speech_started")).toBe(2);
|
|
1382
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1383
|
+
} finally {
|
|
1384
|
+
await session.close("client_end");
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1226
1387
|
});
|
|
1227
1388
|
|
|
1228
1389
|
/**
|
|
@@ -1339,6 +1500,7 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
|
|
|
1339
1500
|
() => countFrames(frames, "utterance_end") === 1,
|
|
1340
1501
|
"The utterance deferred under the seeded latch never released",
|
|
1341
1502
|
);
|
|
1503
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1342
1504
|
await waitFor(
|
|
1343
1505
|
() => transcribers[0]?.stopped === true,
|
|
1344
1506
|
"The utterance never finished releasing",
|
|
@@ -1351,6 +1513,127 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
|
|
|
1351
1513
|
await session.close("client_end");
|
|
1352
1514
|
});
|
|
1353
1515
|
|
|
1516
|
+
test.each([true, false])(
|
|
1517
|
+
"replays local onset when the dial falls back from Flux (turn-end %s)",
|
|
1518
|
+
async (flagOn) => {
|
|
1519
|
+
const gate = createDialGate();
|
|
1520
|
+
const { frames, session } = createHarness({
|
|
1521
|
+
providerId: "vellum",
|
|
1522
|
+
fluxConfig: flagOn ? FLUX_ON : FLUX_OFF,
|
|
1523
|
+
silenceThresholdMs: 10_000,
|
|
1524
|
+
resolveGate: gate.promise,
|
|
1525
|
+
});
|
|
1526
|
+
try {
|
|
1527
|
+
await session.start();
|
|
1528
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1529
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1530
|
+
gate.open();
|
|
1531
|
+
await waitFor(() => countFrames(frames, "speech_started") === 1);
|
|
1532
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1533
|
+
expect(countFrames(frames, "speech_started")).toBe(1);
|
|
1534
|
+
} finally {
|
|
1535
|
+
gate.open();
|
|
1536
|
+
await session.close("client_end");
|
|
1537
|
+
}
|
|
1538
|
+
},
|
|
1539
|
+
);
|
|
1540
|
+
|
|
1541
|
+
test.each([
|
|
1542
|
+
{ providerId: "vellum" as const, audio: LOUD_CHUNK, interrupts: false },
|
|
1543
|
+
{
|
|
1544
|
+
providerId: "vellum" as const,
|
|
1545
|
+
audio: SUSTAINED_LOUD_CHUNK,
|
|
1546
|
+
interrupts: true,
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
providerId: "deepgram-flux" as const,
|
|
1550
|
+
audio: LOUD_CHUNK,
|
|
1551
|
+
interrupts: true,
|
|
1552
|
+
},
|
|
1553
|
+
])(
|
|
1554
|
+
"speech released before the dial interrupts only after provider or guard confirmation: $providerId",
|
|
1555
|
+
async ({ providerId, audio, interrupts }) => {
|
|
1556
|
+
const gate = createDialGate();
|
|
1557
|
+
const abort = mock();
|
|
1558
|
+
const { frames, session, transcribers } = createHarness({
|
|
1559
|
+
providerId,
|
|
1560
|
+
fluxConfig: FLUX_OFF,
|
|
1561
|
+
resolveGate: gate.promise,
|
|
1562
|
+
startVoiceTurn: async () => ({ turnId: "greeting-turn", abort }),
|
|
1563
|
+
});
|
|
1564
|
+
try {
|
|
1565
|
+
await session.start();
|
|
1566
|
+
await session.handleClientFrame({
|
|
1567
|
+
type: "text",
|
|
1568
|
+
text: "Say hello.",
|
|
1569
|
+
hidden: true,
|
|
1570
|
+
});
|
|
1571
|
+
await waitFor(() => countFrames(frames, "thinking") === 1);
|
|
1572
|
+
await session.handleBinaryAudio(audio);
|
|
1573
|
+
await waitFor(() => countFrames(frames, "utterance_end") === 1);
|
|
1574
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1575
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1576
|
+
|
|
1577
|
+
gate.open();
|
|
1578
|
+
await gate.promise;
|
|
1579
|
+
const transcriber = transcribers[0]!;
|
|
1580
|
+
if (providerId === "deepgram-flux") {
|
|
1581
|
+
transcriber.onAudio = () => {
|
|
1582
|
+
transcriber.startOfTurn(0);
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
await waitFor(() => transcriber.stopped);
|
|
1586
|
+
await flushAsyncCallbacks();
|
|
1587
|
+
expect(countFrames(frames, "speech_started")).toBe(interrupts ? 1 : 0);
|
|
1588
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(interrupts ? 1 : 0);
|
|
1589
|
+
expect(abort).toHaveBeenCalledTimes(interrupts ? 1 : 0);
|
|
1590
|
+
} finally {
|
|
1591
|
+
gate.open();
|
|
1592
|
+
await session.close("client_end");
|
|
1593
|
+
}
|
|
1594
|
+
},
|
|
1595
|
+
);
|
|
1596
|
+
|
|
1597
|
+
test("a fully parked follow-up retains its guard when the next dial falls back", async () => {
|
|
1598
|
+
const abort = mock();
|
|
1599
|
+
const options = {
|
|
1600
|
+
providerId: "deepgram-flux" as SttProviderId,
|
|
1601
|
+
fluxConfig: FLUX_ON,
|
|
1602
|
+
startVoiceTurn: async () => ({ turnId: "reply-turn", abort }),
|
|
1603
|
+
};
|
|
1604
|
+
const { frames, session, transcribers } = createHarness(options);
|
|
1605
|
+
try {
|
|
1606
|
+
await session.start();
|
|
1607
|
+
await waitFor(() => transcribers.length === 1);
|
|
1608
|
+
const first = transcribers[0]!;
|
|
1609
|
+
first.holdStopEvents = true;
|
|
1610
|
+
first.pendingFlushText = "tell me a story";
|
|
1611
|
+
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1612
|
+
first.startOfTurn(0);
|
|
1613
|
+
await session.handleClientFrame({ type: "ptt_release" });
|
|
1614
|
+
await waitFor(() => first.stopped);
|
|
1615
|
+
|
|
1616
|
+
// The first input is released but cannot dispatch until its final arrives.
|
|
1617
|
+
await session.handleBinaryAudio(SUSTAINED_LOUD_CHUNK);
|
|
1618
|
+
await sleep(PAST_SILENCE_BOUNDARY_MS);
|
|
1619
|
+
options.providerId = "vellum";
|
|
1620
|
+
first.flushStopEvents();
|
|
1621
|
+
await waitFor(() => countFrames(frames, "thinking") === 1);
|
|
1622
|
+
expect(countFrames(frames, "turn_cancelled")).toBe(0);
|
|
1623
|
+
|
|
1624
|
+
// Idle input arms the parked follow-up without any further speech.
|
|
1625
|
+
await session.handleBinaryAudio(pcm(0));
|
|
1626
|
+
await waitFor(() => transcribers.length === 2);
|
|
1627
|
+
await waitFor(() => countFrames(frames, "turn_cancelled") === 1);
|
|
1628
|
+
expect(abort).toHaveBeenCalledTimes(1);
|
|
1629
|
+
expect(transcribers[1]!.received).toContainEqual(
|
|
1630
|
+
Buffer.from(SUSTAINED_LOUD_CHUNK),
|
|
1631
|
+
);
|
|
1632
|
+
} finally {
|
|
1633
|
+
await session.close("client_end");
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1354
1637
|
test("seeds the latch from the live-voice role, not the global provider", async () => {
|
|
1355
1638
|
// The configuration roles exist for: live voice on flux while the global
|
|
1356
1639
|
// stays on a family that owns no turn boundary. Seeding from the global
|
|
@@ -1377,6 +1660,7 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
|
|
|
1377
1660
|
|
|
1378
1661
|
// Deferred under the seeded latch: Flux owns this boundary.
|
|
1379
1662
|
expect(countFrames(frames, "utterance_end")).toBe(0);
|
|
1663
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1380
1664
|
expect(turnCalls).toHaveLength(0);
|
|
1381
1665
|
|
|
1382
1666
|
gate.open();
|
|
@@ -1393,7 +1677,7 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
|
|
|
1393
1677
|
await session.close("client_end");
|
|
1394
1678
|
});
|
|
1395
1679
|
|
|
1396
|
-
test("
|
|
1680
|
+
test("seeds only provider starts when provider end-of-turn is disabled", async () => {
|
|
1397
1681
|
const gate = createDialGate();
|
|
1398
1682
|
const { frames, session, transcribers, turnCalls } = createHarness({
|
|
1399
1683
|
// Turn-end explicitly off while config still selects the flux family.
|
|
@@ -1406,12 +1690,13 @@ describe("LiveVoiceSession Flux end-of-turn during the STT dial", () => {
|
|
|
1406
1690
|
await session.start();
|
|
1407
1691
|
await session.handleBinaryAudio(LOUD_CHUNK);
|
|
1408
1692
|
|
|
1409
|
-
//
|
|
1693
|
+
// The local silence boundary releases, but local onset cannot interrupt.
|
|
1410
1694
|
await waitFor(
|
|
1411
1695
|
() => countFrames(frames, "utterance_end") === 1,
|
|
1412
1696
|
"The flag-off silence boundary stopped releasing during the dial",
|
|
1413
1697
|
);
|
|
1414
1698
|
expect(turnCalls).toHaveLength(0);
|
|
1699
|
+
expect(countFrames(frames, "speech_started")).toBe(0);
|
|
1415
1700
|
|
|
1416
1701
|
gate.open();
|
|
1417
1702
|
await waitFor(() => transcribers.length > 0);
|