Skip to content

Commit 1bbbb3f

Browse files
feat(elevenlabs): add noVerbatim STT option (#1769)
Co-authored-by: rosetta-livekit-bot[bot] <282703043+rosetta-livekit-bot[bot]@users.noreply.github.com> Co-authored-by: Tina Nguyen <72938484+tinalenguyen@users.noreply.github.com>
1 parent 33c09ec commit 1bbbb3f

2 files changed

Lines changed: 28 additions & 2 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-elevenlabs': patch
3+
---
4+
5+
Add ElevenLabs STT `noVerbatim` option.

plugins/elevenlabs/src/stt.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export interface STTOptions {
5959
httpSession?: STTHTTPSession;
6060
modelId?: ElevenLabsSTTModels | string;
6161
keyterms?: string[];
62+
noVerbatim?: boolean;
6263
}
6364

6465
interface ResolvedSTTOptions {
@@ -71,6 +72,7 @@ interface ResolvedSTTOptions {
7172
sampleRate: STTRealtimeSampleRates;
7273
serverVad?: VADOptions | null;
7374
keyterms?: string[];
75+
noVerbatim: boolean;
7476
}
7577

7678
export interface STTRecognizeOptions {
@@ -234,6 +236,7 @@ export class STT extends stt.STT {
234236
includeTimestamps,
235237
modelId,
236238
keyterms: opts.keyterms,
239+
noVerbatim: opts.noVerbatim ?? false,
237240
};
238241
this.#session = opts.httpSession ?? {};
239242
}
@@ -347,6 +350,9 @@ export class STT extends stt.STT {
347350
form.append('keyterms', keyterm);
348351
}
349352
}
353+
if (this.#opts.noVerbatim) {
354+
form.append('no_verbatim', 'true');
355+
}
350356

351357
try {
352358
const fetchFn = this.#session.fetch ?? fetch;
@@ -428,6 +434,7 @@ export class STT extends stt.STT {
428434
tagAudioEvents?: boolean;
429435
serverVad?: VADOptions | null;
430436
keyterms?: string[];
437+
noVerbatim?: boolean;
431438
}): void {
432439
if (opts.tagAudioEvents !== undefined) {
433440
this.#opts.tagAudioEvents = opts.tagAudioEvents;
@@ -441,10 +448,14 @@ export class STT extends stt.STT {
441448
this.#opts.keyterms = opts.keyterms;
442449
}
443450

451+
if (opts.noVerbatim !== undefined) {
452+
this.#opts.noVerbatim = opts.noVerbatim;
453+
}
454+
444455
for (const ref of this.#streams) {
445456
const stream = ref.deref();
446457
if (stream) {
447-
stream.updateOptions({ serverVad: opts.serverVad });
458+
stream.updateOptions({ serverVad: opts.serverVad, noVerbatim: opts.noVerbatim });
448459
} else {
449460
this.#streams.delete(ref);
450461
}
@@ -494,13 +505,19 @@ export class SpeechStream extends stt.SpeechStream {
494505
);
495506
}
496507

497-
updateOptions(opts: { serverVad?: VADOptions | null }): void {
508+
updateOptions(opts: { serverVad?: VADOptions | null; noVerbatim?: boolean }): void {
498509
if (opts.serverVad !== undefined) {
499510
this.#opts.serverVad = opts.serverVad;
500511
if (!this.#reconnectEvent.done) {
501512
this.#reconnectEvent.resolve();
502513
}
503514
}
515+
if (opts.noVerbatim !== undefined) {
516+
this.#opts.noVerbatim = opts.noVerbatim;
517+
if (!this.#reconnectEvent.done) {
518+
this.#reconnectEvent.resolve();
519+
}
520+
}
504521
}
505522

506523
#onAudioDurationReport(duration: number): void {
@@ -696,6 +713,10 @@ export class SpeechStream extends stt.SpeechStream {
696713
params.push('include_timestamps=true');
697714
}
698715

716+
if (this.#opts.noVerbatim) {
717+
params.push('no_verbatim=true');
718+
}
719+
699720
const baseURL = this.#opts.baseURL.replace('https://', 'wss://').replace('http://', 'ws://');
700721
const wsUrl = `${baseURL}/speech-to-text/realtime?${params.join('&')}`;
701722
const headers = { [AUTHORIZATION_HEADER]: this.#opts.apiKey };

0 commit comments

Comments
 (0)