fix: honor zero-valued voice-call STT settings

Landed from contributor PR #39196 by @scoootscooob.

Co-authored-by: scoootscooob <zhentongfan@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-08 02:36:29 +00:00
parent a8c67affd8
commit 28b72e5cb0
3 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import type { RealtimeSTTConfig } from "./stt-openai-realtime.js";
import { OpenAIRealtimeSTTProvider } from "./stt-openai-realtime.js";
type ProviderInternals = OpenAIRealtimeSTTProvider & {
vadThreshold: number;
silenceDurationMs: number;
};
function createProvider(config: RealtimeSTTConfig): ProviderInternals {
return new OpenAIRealtimeSTTProvider(config) as ProviderInternals;
}
describe("OpenAIRealtimeSTTProvider constructor defaults", () => {
it("uses vadThreshold: 0 when explicitly configured (max sensitivity)", () => {
const provider = createProvider({
apiKey: "sk-test",
vadThreshold: 0,
});
expect(provider.vadThreshold).toBe(0);
});
it("uses silenceDurationMs: 0 when explicitly configured", () => {
const provider = createProvider({
apiKey: "sk-test",
silenceDurationMs: 0,
});
expect(provider.silenceDurationMs).toBe(0);
});
it("falls back to defaults when values are undefined", () => {
const provider = createProvider({
apiKey: "sk-test",
});
expect(provider.vadThreshold).toBe(0.5);
expect(provider.silenceDurationMs).toBe(800);
});
});

View File

@@ -62,8 +62,8 @@ export class OpenAIRealtimeSTTProvider {
}
this.apiKey = config.apiKey;
this.model = config.model || "gpt-4o-transcribe";
this.silenceDurationMs = config.silenceDurationMs || 800;
this.vadThreshold = config.vadThreshold || 0.5;
this.silenceDurationMs = config.silenceDurationMs ?? 800;
this.vadThreshold = config.vadThreshold ?? 0.5;
}
/**