mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
// Tts Local Cli live tests cover the real process and ffmpeg integration.
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import { runFfmpeg } from "openclaw/plugin-sdk/media-runtime";
|
|
import type { SpeechProviderConfig } from "openclaw/plugin-sdk/speech-core";
|
|
import { withTempDir } from "openclaw/plugin-sdk/test-env";
|
|
import { describe, expect, it } from "vitest";
|
|
import { buildCliSpeechProvider } from "./speech-provider.js";
|
|
|
|
const describeLive = process.env.OPENCLAW_LIVE_TEST === "1" ? describe : describe.skip;
|
|
|
|
describeLive("buildCliSpeechProvider live", () => {
|
|
it("synthesizes through a real local CLI fixture and ffmpeg", async () => {
|
|
await withTempDir("openclaw-cli-tts-live-", async (dir) => {
|
|
const script = path.join(dir, "copy-audio.mjs");
|
|
const wavPath = path.join(dir, "source.wav");
|
|
await runFfmpeg([
|
|
"-y",
|
|
"-f",
|
|
"lavfi",
|
|
"-i",
|
|
"sine=frequency=660:duration=0.1",
|
|
"-c:a",
|
|
"pcm_s16le",
|
|
wavPath,
|
|
]);
|
|
writeFileSync(
|
|
script,
|
|
`
|
|
import { copyFileSync } from "node:fs";
|
|
const outIndex = process.argv.indexOf("--out");
|
|
copyFileSync(${JSON.stringify(wavPath)}, process.argv[outIndex + 1]);
|
|
`,
|
|
);
|
|
const providerConfig: SpeechProviderConfig = {
|
|
command: process.execPath,
|
|
args: [script, "--out", "{{OutputPath}}"],
|
|
outputFormat: "wav",
|
|
timeoutMs: 30_000,
|
|
};
|
|
|
|
const result = await buildCliSpeechProvider().synthesize({
|
|
text: "hello world",
|
|
cfg: {} as OpenClawConfig,
|
|
providerConfig,
|
|
providerOverrides: {},
|
|
timeoutMs: 30_000,
|
|
target: "voice-note",
|
|
});
|
|
|
|
expect(result.outputFormat).toBe("opus");
|
|
expect(result.fileExtension).toBe(".ogg");
|
|
expect(result.voiceCompatible).toBe(true);
|
|
expect(result.audioBuffer.byteLength).toBeGreaterThan(0);
|
|
expect(readFileSync(wavPath).byteLength).toBeGreaterThan(0);
|
|
});
|
|
}, 30_000);
|
|
});
|