import { describe, expect, it } from
"vitest";
import { isLiveTestEnabled } from
"../../src/agents/live-test-helpers.js";
import { buildOpenAISpeechProvider } from
"./speech-provider.js";
const OPENAI_API_KEY = process.env.OPENAI_API_KEY?.trim() ??
"";
const LIVE = isLiveTestEnabled() && OPENAI_API_KEY.length >
0;
const describeLive = LIVE ? describe : describe.skip;
describeLive(
"openai tts live", () => {
it(
"synthesizes audio through the speech provider", async () => {
const speechProvider = buildOpenAISpeechProvider();
const voices = await speechProvider.listVoices?.({});
expect(voices).toEqual(expect.arrayContaining([expect.objectContaining({ id:
"alloy" })]));
const providerConfig = {
apiKey: OPENAI_API_KEY,
baseUrl:
"https://api.openai.com/v1",
model:
"gpt-4o-mini-tts",
voice:
"alloy",
};
const audioFile = await speechProvider.synthesize({
text:
"OpenClaw OpenAI text to speech integration test OK.",
cfg: { plugins: { enabled:
true } } as never,
providerConfig,
target:
"audio-file",
timeoutMs:
45_
000,
});
expect(audioFile.outputFormat).toBe(
"mp3");
expect(audioFile.fileExtension).toBe(
".mp3");
expect(audioFile.audioBuffer.byteLength).toBeGreaterThan(
512);
const telephony = await speechProvider.synthesizeTelephony?.({
text:
"OpenClaw OpenAI telephony integration test OK.",
cfg: { plugins: { enabled:
true } } as never,
providerConfig,
timeoutMs:
45_
000,
});
expect(telephony?.outputFormat).toBe(
"pcm");
expect(telephony?.sampleRate).toBe(
24_
000);
expect(telephony?.audioBuffer.byteLength).toBeGreaterThan(
512);
},
60_
000);
});