fix(tts): carry OpenAI talk response format

This commit is contained in:
Ayaan Zaidi
2026-04-07 12:38:52 +05:30
parent eb4bc200d7
commit 91a3af4e24
2 changed files with 28 additions and 0 deletions

View File

@@ -77,6 +77,32 @@ describe("buildOpenAISpeechProvider", () => {
});
});
it("preserves talk responseFormat overrides", () => {
const provider = buildOpenAISpeechProvider();
expect(
provider.resolveTalkConfig?.({
cfg: {} as never,
timeoutMs: 30_000,
baseTtsConfig: {
providers: {
openai: {
apiKey: "sk-base",
responseFormat: "mp3",
},
},
},
talkProviderConfig: {
apiKey: "sk-talk",
responseFormat: " WAV ",
},
}),
).toMatchObject({
apiKey: "sk-talk",
responseFormat: "wav",
});
});
it("uses wav for Groq-compatible OpenAI TTS endpoints", async () => {
const provider = buildOpenAISpeechProvider();
const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => {

View File

@@ -184,6 +184,7 @@ export function buildOpenAISpeechProvider(): SpeechProviderPlugin {
parseDirectiveToken,
resolveTalkConfig: ({ baseTtsConfig, talkProviderConfig }) => {
const base = normalizeOpenAIProviderConfig(baseTtsConfig);
const responseFormat = normalizeOpenAISpeechResponseFormat(talkProviderConfig.responseFormat);
return {
...base,
...(talkProviderConfig.apiKey === undefined
@@ -209,6 +210,7 @@ export function buildOpenAISpeechProvider(): SpeechProviderPlugin {
...(trimToUndefined(talkProviderConfig.instructions) == null
? {}
: { instructions: trimToUndefined(talkProviderConfig.instructions) }),
...(responseFormat == null ? {} : { responseFormat }),
};
},
resolveTalkOverrides: ({ params }) => ({