Skip to content

Commit b48a0f1

Browse files
fix(assemblyai): respect mode silence presets (#1882)
Co-authored-by: rosetta-livekit-bot[bot] <282703043+rosetta-livekit-bot[bot]@users.noreply.github.com>
1 parent ff77fb0 commit b48a0f1

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/agents-plugin-assemblyai': patch
3+
---
4+
5+
Respect AssemblyAI `mode` presets when defaulting turn silence and remap deprecated `u3-pro` to `universal-3-5-pro`.

plugins/assemblyai/src/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type STTModels =
88
| 'u3-rt-pro'
99
| 'u3-rt-pro-beta-1'
1010
| 'universal-3-5-pro'
11-
// Deprecated alias — AssemblyAI maps this to `u3-rt-pro` server-side, but the
11+
// Deprecated alias — AssemblyAI maps this to `universal-3-5-pro`, but the
1212
// Python plugin emits a warning and rewrites it. Kept here so TS users don't
1313
// break if they already pass it.
1414
| 'u3-pro';

plugins/assemblyai/src/stt.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type { RawData } from 'ws';
2020
import { WebSocket } from 'ws';
2121
import type { STTEncoding, STTModels, VoiceFocus } from './models.js';
2222

23+
// Speech models in the Universal-3 Pro family, which share the same parameter support.
2324
const U3_PRO_MODELS = ['u3-rt-pro', 'u3-rt-pro-beta-1', 'universal-3-5-pro'] as const;
2425

2526
function isU3ProModel(model: STTModels): boolean {
@@ -72,11 +73,11 @@ export interface STTOptions {
7273
maxTurnSilence?: number;
7374
formatTurns?: boolean;
7475
keytermsPrompt?: string[];
75-
/** Only supported with the `u3-rt-pro` model family. */
76+
/** Only supported with the Universal-3 Pro model family. */
7677
prompt?: string;
77-
/** Only supported with the `u3-rt-pro` model family. */
78+
/** Only supported with the Universal-3 Pro model family. */
7879
agentContext?: string;
79-
/** Only supported with the `u3-rt-pro` model family. Set at connection time only. */
80+
/** Only supported with the Universal-3 Pro model family. Set at connection time only. */
8081
previousContextNTurns?: number;
8182
vadThreshold?: number;
8283
/**
@@ -95,8 +96,8 @@ export interface STTOptions {
9596
/** Background audio suppression aggressiveness, from 0.0 to 1.0. Connect-time only. */
9697
voiceFocusThreshold?: number;
9798
/**
98-
* Accuracy/latency preset for u3-rt-pro: `min_latency`, `balanced`, or `max_accuracy`.
99-
* Explicit silence, partials, or VAD options still take precedence over mode defaults.
99+
* Accuracy/latency preset for the Universal-3 Pro model family: `min_latency`, `balanced`,
100+
* or `max_accuracy`. Explicit turn-silence values still take precedence over mode defaults.
100101
*/
101102
mode?: 'min_latency' | 'balanced' | 'max_accuracy';
102103
baseUrl: string;
@@ -132,8 +133,8 @@ export class STT extends stt.STT {
132133
});
133134

134135
if (opts.speechModel === 'u3-pro') {
135-
log().warn("'u3-pro' is deprecated, use 'u3-rt-pro' instead.");
136-
opts.speechModel = 'u3-rt-pro';
136+
log().warn("'u3-pro' is deprecated, use 'universal-3-5-pro' instead.");
137+
opts.speechModel = 'universal-3-5-pro';
137138
}
138139

139140
const speechModel = opts.speechModel ?? defaultSTTOptions.speechModel;
@@ -161,8 +162,8 @@ export class STT extends stt.STT {
161162
);
162163
}
163164

164-
// Minimize latency; matches LK's end-of-turn detector well.
165-
const minTurnSilence = opts.minTurnSilence ?? 100;
165+
// Minimize latency by default, but let AssemblyAI's mode preset control silence tuning.
166+
const minTurnSilence = opts.minTurnSilence ?? (opts.mode === undefined ? 100 : undefined);
166167

167168
this.#opts = {
168169
...defaultSTTOptions,
@@ -296,11 +297,13 @@ export class SpeechStream extends stt.SpeechStream {
296297
}
297298

298299
async #connectWS(): Promise<WebSocket> {
299-
// u3-rt-pro family models default both min and max silence to 100ms when unset.
300+
// Universal-3 Pro family models default both min and max silence to 100ms when unset.
301+
// When a mode preset is selected, leave them unset unless explicitly provided so the
302+
// server's per-mode silence tuning is not overridden by the latency-optimized default.
300303
let minSilence = this.#opts.minTurnSilence;
301304
let maxSilence = this.#opts.maxTurnSilence;
302305
if (isU3ProModel(this.#opts.speechModel)) {
303-
if (minSilence === undefined) minSilence = 100;
306+
if (minSilence === undefined && this.#opts.mode === undefined) minSilence = 100;
304307
if (maxSilence === undefined) maxSilence = minSilence;
305308
}
306309

0 commit comments

Comments
 (0)