Skip to content

Write HTML. Render video. Built for agents.

fix(cli): restore tts --text-file compatibility (#2117)

Miguel Ángelef38321d5d1b
diff --git a/packages/cli/src/commands/tts.test.ts b/packages/cli/src/commands/tts.test.ts
new file mode 100644
index 0000000000..341c9964be
--- /dev/null
+++ b/packages/cli/src/commands/tts.test.ts
@@ -0,0 +1,45 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { assertKnownFlags } from "../utils/reject-unknown-flags.js";
+
+const synthesizeMock = vi.fn().mockResolvedValue({
+ durationSeconds: 1,
+ langApplied: true,
+ outputPath: "/tmp/speech.wav",
+});
+vi.mock("../tts/synthesize.js", () => ({ synthesize: synthesizeMock }));
+
+import ttsCommand from "./tts.js";
+
+describe("tts command", () => {
+ let dir: string;
+
+ beforeEach(() => {
+ dir = mkdtempSync(join(tmpdir(), "hf-tts-command-test-"));
+ synthesizeMock.mockClear();
+ vi.spyOn(console, "log").mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ rmSync(dir, { recursive: true, force: true });
+ vi.restoreAllMocks();
+ });
+
+ it("accepts --text-file as a compatibility alias for file input", async () => {
+ const input = join(dir, "script.txt");
+ writeFileSync(input, "Legacy file input\n");
+
+ expect(() =>
+ assertKnownFlags(ttsCommand as never, ["--text-file", input, "--json"]),
+ ).not.toThrow();
+ await ttsCommand.run!({ args: { "text-file": input, json: true } } as never);
+
+ expect(synthesizeMock).toHaveBeenCalledWith(
+ "Legacy file input",
+ expect.stringMatching(/speech\.wav$/),
+ expect.objectContaining({ lang: "en-us" }),
+ );
+ });
+});
diff --git a/packages/cli/src/commands/tts.ts b/packages/cli/src/commands/tts.ts
index 8ad0d3f412..3fa05f9530 100644
--- a/packages/cli/src/commands/tts.ts
+++ b/packages/cli/src/commands/tts.ts
@@ -46,6 +46,10 @@ export default defineCommand({
description: "Text to speak, or path to a .txt file",
required: false,
},
+ "text-file": {
+ type: "string",
+ description: "Read text from a .txt file (compatibility alias)",
+ },
output: {
type: "string",
description: "Output file path (default: speech.wav in current directory)",
@@ -85,13 +89,14 @@ export default defineCommand({
}
// ── Resolve input text ────────────────────────────────────────────
- if (!args.input) {
+ const input = args["text-file"] ?? args.input;
+ if (!input) {
console.error(c.error("Provide text to speak, or use --list to see available voices."));
process.exit(1);
}
let text: string;
- const maybeFile = resolve(args.input);
+ const maybeFile = resolve(input);
if (existsSync(maybeFile) && extname(maybeFile).toLowerCase() === ".txt") {
text = readFileSync(maybeFile, "utf-8").trim();
@@ -100,7 +105,7 @@ export default defineCommand({
process.exit(1);
}
} else {
- text = args.input;
+ text = input;
}
if (!text.trim()) {