@ph0ny/cli 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +93 -20
  2. package/SKILL.md +73 -0
  3. package/bin/phony.js +3 -1
  4. package/dist/commands/account.d.ts +9 -0
  5. package/dist/commands/account.d.ts.map +1 -0
  6. package/dist/commands/account.js +48 -0
  7. package/dist/commands/account.js.map +1 -0
  8. package/dist/commands/agents.d.ts +1 -0
  9. package/dist/commands/agents.d.ts.map +1 -1
  10. package/dist/commands/agents.js +48 -29
  11. package/dist/commands/agents.js.map +1 -1
  12. package/dist/commands/call.d.ts +10 -8
  13. package/dist/commands/call.d.ts.map +1 -1
  14. package/dist/commands/call.js +87 -31
  15. package/dist/commands/call.js.map +1 -1
  16. package/dist/commands/contacts.d.ts.map +1 -1
  17. package/dist/commands/contacts.js +5 -1
  18. package/dist/commands/contacts.js.map +1 -1
  19. package/dist/commands/observability.d.ts.map +1 -1
  20. package/dist/commands/observability.js +2 -10
  21. package/dist/commands/observability.js.map +1 -1
  22. package/dist/commands/raw.d.ts.map +1 -1
  23. package/dist/commands/raw.js +1 -0
  24. package/dist/commands/raw.js.map +1 -1
  25. package/dist/commands/synthesize.d.ts +3 -0
  26. package/dist/commands/synthesize.d.ts.map +1 -0
  27. package/dist/commands/synthesize.js +71 -0
  28. package/dist/commands/synthesize.js.map +1 -0
  29. package/dist/commands/transcribe.d.ts +3 -0
  30. package/dist/commands/transcribe.d.ts.map +1 -0
  31. package/dist/commands/transcribe.js +47 -0
  32. package/dist/commands/transcribe.js.map +1 -0
  33. package/dist/commands/translate-job.d.ts +6 -0
  34. package/dist/commands/translate-job.d.ts.map +1 -0
  35. package/dist/commands/translate-job.js +73 -0
  36. package/dist/commands/translate-job.js.map +1 -0
  37. package/dist/commands/translate-options.d.ts +42 -0
  38. package/dist/commands/translate-options.d.ts.map +1 -0
  39. package/dist/commands/translate-options.js +147 -0
  40. package/dist/commands/translate-options.js.map +1 -0
  41. package/dist/commands/translate.d.ts +3 -0
  42. package/dist/commands/translate.d.ts.map +1 -0
  43. package/dist/commands/translate.js +77 -0
  44. package/dist/commands/translate.js.map +1 -0
  45. package/dist/commands/video.d.ts +13 -0
  46. package/dist/commands/video.d.ts.map +1 -0
  47. package/dist/commands/video.js +83 -0
  48. package/dist/commands/video.js.map +1 -0
  49. package/dist/commands/voices.d.ts.map +1 -1
  50. package/dist/commands/voices.js +27 -43
  51. package/dist/commands/voices.js.map +1 -1
  52. package/dist/index.d.ts +10 -4
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +70 -54
  55. package/dist/index.js.map +1 -1
  56. package/dist/lib/agent-payload.d.ts +27 -12
  57. package/dist/lib/agent-payload.d.ts.map +1 -1
  58. package/dist/lib/agent-payload.js +33 -20
  59. package/dist/lib/agent-payload.js.map +1 -1
  60. package/dist/lib/call-payload.d.ts +6 -0
  61. package/dist/lib/call-payload.d.ts.map +1 -1
  62. package/dist/lib/call-payload.js +14 -0
  63. package/dist/lib/call-payload.js.map +1 -1
  64. package/dist/lib/call-trace.d.ts +14 -0
  65. package/dist/lib/call-trace.d.ts.map +1 -0
  66. package/dist/lib/call-trace.js +30 -0
  67. package/dist/lib/call-trace.js.map +1 -0
  68. package/dist/lib/errors.d.ts +7 -4
  69. package/dist/lib/errors.d.ts.map +1 -1
  70. package/dist/lib/errors.js +11 -10
  71. package/dist/lib/errors.js.map +1 -1
  72. package/package.json +13 -11
  73. package/dist/commands/campaign.d.ts +0 -11
  74. package/dist/commands/campaign.d.ts.map +0 -1
  75. package/dist/commands/campaign.js +0 -26
  76. package/dist/commands/campaign.js.map +0 -1
@@ -0,0 +1,73 @@
1
+ /** Shared upload, polling and download path for video and audio translation. */
2
+ import { spawnSync } from 'node:child_process';
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import { UsageError } from '../lib/exit.js';
7
+ const DIRECT_MEDIA = /\.(mp4|m4v|mov|webm|mkv|avi|mp3|m4a|wav)(\?|#|$)/i;
8
+ const POLL_MS = 3000;
9
+ export async function submitTranslation(client, input, request, output, status) {
10
+ if (/^https?:\/\//i.test(input) && DIRECT_MEDIA.test(new URL(input).pathname)) {
11
+ status('Submitting');
12
+ return output === 'audio'
13
+ ? client.voice.video.translateAudio({ ...request, media_url: input })
14
+ : client.voice.video.translate({ ...request, video_url: input });
15
+ }
16
+ let temporaryDir;
17
+ try {
18
+ const file = /^https?:\/\//i.test(input) ? fetchWithYtDlp(input, status, (dir) => { temporaryDir = dir; }) : input;
19
+ if (!fs.existsSync(file))
20
+ throw new UsageError(`No such file: ${file}`);
21
+ status('Uploading');
22
+ const bytes = fs.readFileSync(file);
23
+ return output === 'audio'
24
+ ? client.voice.video.translateAudioFile(bytes, request, path.basename(file))
25
+ : client.voice.video.translateFile(bytes, request, path.basename(file));
26
+ }
27
+ finally {
28
+ if (temporaryDir)
29
+ fs.rmSync(temporaryDir, { recursive: true, force: true });
30
+ }
31
+ }
32
+ /** Page URLs are fetched locally with yt-dlp, then uploaded as media. */
33
+ function fetchWithYtDlp(url, status, created) {
34
+ status('Fetching with yt-dlp');
35
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ph0ny-translate-'));
36
+ created(dir);
37
+ const result = spawnSync('yt-dlp', [
38
+ '--no-playlist', '-f', 'bv*[height<=1080]+ba/b[height<=1080]/b', '--merge-output-format', 'mp4',
39
+ '-o', path.join(dir, 'input.%(ext)s'), url,
40
+ ], { encoding: 'utf8' });
41
+ if (result.error)
42
+ throw new UsageError('yt-dlp is needed to fetch page URLs (https://github.com/yt-dlp/yt-dlp). Install it, or pass a file or direct media URL.', 'YT_DLP_MISSING');
43
+ if (result.status !== 0)
44
+ throw new Error(`yt-dlp could not fetch ${url}: ${(result.stderr ?? '').trim().split('\n').pop()}`);
45
+ const file = fs.readdirSync(dir).find((name) => name.startsWith('input.'));
46
+ if (!file)
47
+ throw new Error(`yt-dlp produced no file for ${url}.`);
48
+ return path.join(dir, file);
49
+ }
50
+ export async function followTranslation(client, jobId, timeoutMs, onUpdate) {
51
+ const deadline = Date.now() + timeoutMs;
52
+ for (;;) {
53
+ const job = await client.voice.video.getJob(jobId);
54
+ onUpdate(job);
55
+ if (job.status === 'completed' || job.status === 'failed')
56
+ return job;
57
+ if (Date.now() > deadline)
58
+ throw new Error(`Job ${jobId} is still ${job.stage ?? job.status}; check it later with: ph0ny raw GET /video/${jobId}`);
59
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
60
+ }
61
+ }
62
+ export async function downloadTranslation(client, job, output, target) {
63
+ const url = output === 'video' ? job.result?.video_url : job.result?.audio_url;
64
+ const response = url
65
+ ? await fetch(url)
66
+ : await client.voice.fetchResponse(client.voice.resolveUrl(`/video/${job.id}`), {
67
+ headers: { Authorization: `Bearer ${client.context.apiKey}`, Accept: output === 'audio' ? 'audio/wav' : 'video/mp4' },
68
+ });
69
+ if (!response.ok)
70
+ throw new Error(`Downloading the ${output} failed: HTTP ${response.status}`);
71
+ fs.writeFileSync(target, Buffer.from(await response.arrayBuffer()));
72
+ }
73
+ //# sourceMappingURL=translate-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate-job.js","sourceRoot":"","sources":["../../src/commands/translate-job.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,YAAY,GAAG,mDAAmD,CAAA;AACxE,MAAM,OAAO,GAAG,IAAI,CAAA;AAEpB,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAiB,EACjB,KAAa,EACb,OAAmE,EACnE,MAA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AAM,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;YAC9E,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE;SACtH,CAAC,CAAA;IACJ,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,iBAAiB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9F,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;AACrE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { AudioTranslateOpts, VideoTranslateOpts } from '@ph0ny/sdk';
2
+ import { Command } from 'commander';
3
+ export interface SharedTranslateOptions {
4
+ to: string;
5
+ from?: string;
6
+ voice: string;
7
+ speakerVoice?: string[];
8
+ /** Preferred flag; speakerConsents preserves the existing video flag. */
9
+ consent?: string;
10
+ speakerConsents?: string;
11
+ speakers: string;
12
+ originalAudio?: string;
13
+ originalVolume?: string;
14
+ out?: string;
15
+ timeout: string;
16
+ json?: boolean;
17
+ }
18
+ export interface VideoTranslateCommandOptions extends SharedTranslateOptions {
19
+ captions: string;
20
+ captionStyle?: string;
21
+ captionPosition: string;
22
+ coverCaptions?: boolean;
23
+ audio: string;
24
+ lipsync?: boolean;
25
+ }
26
+ export interface AudioTranslateCommandOptions extends SharedTranslateOptions {
27
+ transcript: string;
28
+ }
29
+ /** Keep the two translate commands' option groups in the same order. */
30
+ export declare function groupTranslateHelp(command: Command): void;
31
+ export declare function oneOf(value: string, allowed: string[], flag: string): string;
32
+ export declare function buildVideoTranslateRequest(options: VideoTranslateCommandOptions): Omit<VideoTranslateOpts, 'video_url'>;
33
+ export declare function buildAudioTranslateRequest(options: AudioTranslateCommandOptions): AudioTranslateOpts;
34
+ export declare function videoOutputPaths(input: string, options: Pick<VideoTranslateCommandOptions, 'out' | 'to' | 'captions'>): {
35
+ video: string;
36
+ captions?: string;
37
+ };
38
+ export declare function audioOutputPaths(input: string, options: Pick<AudioTranslateCommandOptions, 'out' | 'to' | 'transcript'>): {
39
+ audio: string;
40
+ transcript?: string;
41
+ };
42
+ //# sourceMappingURL=translate-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate-options.d.ts","sourceRoot":"","sources":["../../src/commands/translate-options.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,OAAO,EAAQ,MAAM,WAAW,CAAA;AAGzC,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,MAAM,WAAW,4BAA6B,SAAQ,sBAAsB;IAC1E,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,4BAA6B,SAAQ,sBAAsB;IAC1E,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,wEAAwE;AACxE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuBzD;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG5E;AA2DD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAoBvH;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,4BAA4B,GAAG,kBAAkB,CAGpG;AAUD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,4BAA4B,EAAE,KAAK,GAAG,IAAI,GAAG,UAAU,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAM5J;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,4BAA4B,EAAE,KAAK,GAAG,IAAI,GAAG,YAAY,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAKhK"}
@@ -0,0 +1,147 @@
1
+ /** Options shared by `ph0ny video translate` and `ph0ny audio translate`. */
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import { Help } from 'commander';
5
+ import { UsageError } from '../lib/exit.js';
6
+ /** Keep the two translate commands' option groups in the same order. */
7
+ export function groupTranslateHelp(command) {
8
+ const groups = [
9
+ ['Language', ['--to', '--from']],
10
+ ['Speech', ['--voice', '--speaker-voice', '--consent', '--speaker-consents', '--speakers']],
11
+ ['Original track', ['--audio', '--original-audio', '--original-volume']],
12
+ ['Text', ['--captions', '--caption-style', '--transcript', '--caption-position', '--cover-captions']],
13
+ ['Picture', ['--lipsync']],
14
+ ['Output', ['--out', '--timeout', '--json', '--help']],
15
+ ];
16
+ command.configureHelp({
17
+ formatHelp(cmd, helper) {
18
+ const standard = Help.prototype.formatHelp.call(helper, cmd, helper);
19
+ const optionsAt = standard.indexOf('\nOptions:\n');
20
+ if (optionsAt < 0)
21
+ return standard;
22
+ const width = helper.padWidth(cmd, helper) + 2;
23
+ const lines = groups.flatMap(([name, flags]) => {
24
+ const options = helper.visibleOptions(cmd).filter((option) => flags.some((flag) => option.long === flag));
25
+ if (!options.length)
26
+ return [];
27
+ return [`${name}:`, ...options.map((option) => ` ${helper.optionTerm(option).padEnd(width)}${helper.optionDescription(option)}`), ''];
28
+ });
29
+ return `${standard.slice(0, optionsAt)}\n${lines.join('\n')}`;
30
+ },
31
+ });
32
+ }
33
+ export function oneOf(value, allowed, flag) {
34
+ if (!allowed.includes(value))
35
+ throw new UsageError(`${flag} must be one of ${allowed.join(', ')}.`);
36
+ return value;
37
+ }
38
+ function commonRequest(options) {
39
+ const originalAudio = options.originalAudio === undefined ? undefined : oneOf(options.originalAudio, ['full', 'background', 'none'], '--original-audio');
40
+ const originalVolume = options.originalVolume === undefined ? undefined : Number(options.originalVolume);
41
+ if (originalVolume !== undefined && (!options.originalVolume?.trim() || !Number.isFinite(originalVolume) || originalVolume < 0 || originalVolume > 1)) {
42
+ throw new UsageError('--original-volume must be a number from 0 to 1.');
43
+ }
44
+ const speakerVoices = {};
45
+ for (const pair of options.speakerVoice ?? []) {
46
+ const match = /^(speaker_\d+)=(.+)$/.exec(pair);
47
+ if (!match)
48
+ throw new UsageError(`--speaker-voice expects speaker_N=<voiceId>, got "${pair}".`);
49
+ speakerVoices[match[1]] = match[2];
50
+ }
51
+ if (options.voice === 'clone' && Object.keys(speakerVoices).length === 0) {
52
+ throw new UsageError('Dubbing a speaker in a cloned voice needs a clone made with that person\'s recorded consent. ph0ny clones only your own voice: ' +
53
+ 'create one with `ph0ny voices clone --consent "..."` and pass it with --speaker-voice speaker_0=<voiceId>, or dub with --voice neutral.', 'CONSENT_REQUIRED');
54
+ }
55
+ if (options.voice === 'speakers' && Object.keys(speakerVoices).length) {
56
+ throw new UsageError('--speaker-voice cannot override --voice speakers; use --consent for each cloned speaker.');
57
+ }
58
+ if (options.consent && options.speakerConsents)
59
+ throw new UsageError('Use either --consent or --speaker-consents, not both.');
60
+ const consentFile = options.consent ?? options.speakerConsents;
61
+ if (options.voice === 'speakers' && !consentFile) {
62
+ throw new UsageError('--voice speakers needs --consent <json-file>.', 'CONSENT_REQUIRED');
63
+ }
64
+ let speakerConsents;
65
+ if (consentFile) {
66
+ try {
67
+ const value = JSON.parse(fs.readFileSync(consentFile, 'utf8'));
68
+ if (!value || typeof value !== 'object' || Array.isArray(value) || !Object.keys(value).every((key) => /^speaker_\d+$/.test(key)))
69
+ throw new Error('expected an object keyed by speaker_N');
70
+ speakerConsents = value;
71
+ }
72
+ catch (err) {
73
+ throw new UsageError(`--consent must name a JSON object keyed by speaker_N: ${err.message}`);
74
+ }
75
+ }
76
+ let speakers;
77
+ if (options.speakers !== 'auto') {
78
+ speakers = Number(options.speakers);
79
+ if (!Number.isInteger(speakers) || speakers < 1 || speakers > 32)
80
+ throw new UsageError('--speakers must be "auto" or a number from 1 to 32.');
81
+ }
82
+ if (!Number.isFinite(Number(options.timeout)) || Number(options.timeout) <= 0) {
83
+ throw new UsageError('--timeout must be a positive number of minutes.');
84
+ }
85
+ return {
86
+ target_language: options.to,
87
+ ...(options.from && options.from !== 'auto' ? { source_language: options.from } : {}),
88
+ ...(originalVolume !== undefined ? { originalVolume } : {}),
89
+ ...(originalAudio !== undefined ? { original_audio: originalAudio } : {}),
90
+ voice: options.voice,
91
+ ...(Object.keys(speakerVoices).length ? { speaker_voices: speakerVoices } : {}),
92
+ ...(speakerConsents ? { speaker_consents: speakerConsents } : {}),
93
+ ...(speakers ? { speakers } : {}),
94
+ };
95
+ }
96
+ export function buildVideoTranslateRequest(options) {
97
+ const captions = oneOf(options.captions, ['burn', 'srt', 'vtt', 'none'], '--captions');
98
+ const captionStyle = oneOf(options.captionStyle ?? 'plain', ['plain', 'viral', 'karaoke'], '--caption-style');
99
+ const audio = oneOf(options.audio, ['original', 'dub'], '--audio');
100
+ const position = oneOf(options.captionPosition, ['bottom', 'top'], '--caption-position');
101
+ if (captions === 'none' && audio === 'original')
102
+ throw new UsageError('--captions none with --audio original produces nothing; caption it or dub it.');
103
+ if (options.lipsync && audio !== 'dub')
104
+ throw new UsageError('--lipsync needs --audio dub.');
105
+ if (options.voice !== 'neutral' && audio !== 'dub')
106
+ throw new UsageError('--voice applies to dubs; add --audio dub.');
107
+ if (options.originalVolume !== undefined && audio !== 'dub')
108
+ throw new UsageError('--original-volume needs --audio dub.');
109
+ if (options.originalAudio !== undefined && audio !== 'dub')
110
+ throw new UsageError('--original-audio needs --audio dub.');
111
+ const shared = commonRequest(options);
112
+ return {
113
+ ...shared,
114
+ captions: captions === 'burn' ? 'burn' : 'none',
115
+ captionStyle: captionStyle,
116
+ caption_position: position,
117
+ cover_source_captions: !!options.coverCaptions,
118
+ audio: audio,
119
+ lipsync: !!options.lipsync,
120
+ };
121
+ }
122
+ export function buildAudioTranslateRequest(options) {
123
+ oneOf(options.transcript, ['srt', 'vtt', 'txt', 'none'], '--transcript');
124
+ return commonRequest(options);
125
+ }
126
+ function outputStem(input, target) {
127
+ const language = target.toLowerCase().replace(/[^a-z0-9-]+/g, '-');
128
+ const base = /^https?:\/\//i.test(input)
129
+ ? (new URL(input).pathname.split('/').filter(Boolean).pop() ?? 'media').replace(/\.[^.]+$/, '')
130
+ : path.basename(input).replace(/\.[^.]+$/, '');
131
+ return `${base || 'media'}.${language}`;
132
+ }
133
+ export function videoOutputPaths(input, options) {
134
+ const video = options.out ?? `${outputStem(input, options.to)}.mp4`;
135
+ const stem = video.replace(/\.[^./]+$/, '');
136
+ // A caption file only for --captions srt|vtt; burned captions are in the video.
137
+ const sidecar = options.captions === 'srt' || options.captions === 'vtt';
138
+ return { video, ...(sidecar ? { captions: `${stem}.${options.captions}` } : {}) };
139
+ }
140
+ export function audioOutputPaths(input, options) {
141
+ if (options.out && !/\.wav$/i.test(options.out))
142
+ throw new UsageError('--out must end in .wav for translated audio.');
143
+ const audio = options.out ?? `${outputStem(input, options.to)}.wav`;
144
+ const stem = audio.replace(/\.[^./]+$/, '');
145
+ return { audio, ...(options.transcript === 'none' ? {} : { transcript: `${stem}.${options.transcript}` }) };
146
+ }
147
+ //# sourceMappingURL=translate-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate-options.js","sourceRoot":"","sources":["../../src/commands/translate-options.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAW,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AA+B3C,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,MAAM,MAAM,GAA8B;QACxC,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChC,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC;QAC3F,CAAC,gBAAgB,EAAE,CAAC,SAAS,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;QACxE,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;QACrG,CAAC,SAAS,EAAE,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;KACvD,CAAA;IACD,OAAO,CAAC,aAAa,C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 export declare function createTranslateCommand(): Command;
3
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/commands/translate.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,wBAAgB,sBAAsB,IAAI,OAAO,CA0DhD"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * `phony translate <file|url> --to <language>` — speech in another language.
3
+ *
4
+ * Uploads audio or video (or sends a media URL), follows the job on
5
+ * POST /v1/video/translate with `output: audio`, and saves the dubbed WAV. The
6
+ * JSON result carries the translated text, the files written and the job.
7
+ * `phony video translate` is the same pipeline when the output is a video.
8
+ */
9
+ import * as fs from 'node:fs';
10
+ import { Command } from 'commander';
11
+ import { createCliClient } from '../lib/client.js';
12
+ import { run } from '../lib/errors.js';
13
+ import { printJson, spinner, success } from '../lib/output.js';
14
+ import { audioOutputPaths, buildAudioTranslateRequest, groupTranslateHelp } from './translate-options.js';
15
+ import { downloadTranslation, followTranslation, submitTranslation } from './translate-job.js';
16
+ export function createTranslateCommand() {
17
+ const translate = new Command('translate')
18
+ .description('Translate speech in an audio or video file into another language: a dubbed WAV and the translated text')
19
+ .argument('<input>', 'Audio/video file, direct media URL, or a page URL yt-dlp can fetch')
20
+ .requiredOption('--to <language>', 'Target language (ISO code or name, e.g. en, es, "Japanese")')
21
+ .option('--from <language>', 'Spoken language (default: detected)')
22
+ .option('--voice <voice>', 'neutral | speakers | clone | a stock voice name | your consented clone id', 'neutral')
23
+ .option('--speaker-voice <speaker=voiceId...>', 'Voice per speaker, e.g. speaker_0=<your consented clone id>')
24
+ .option('--consent <json-file>', 'Consent attestations for --voice speakers, keyed by speaker_0, ...')
25
+ .option('--speakers <n>', 'auto | number of speakers', 'auto')
26
+ .option('--original-audio <mode>', 'full | background | none under the dub (default: full)')
27
+ .option('--original-volume <0..1>', 'Original-audio level under the dub (default: 0.15; 0 = dub only)')
28
+ .option('--transcript <format>', 'srt | vtt | txt | none', 'none')
29
+ .option('--out <path>', 'Output WAV path (default: <input>.<lang>.wav)')
30
+ .option('--timeout <minutes>', 'Give up waiting after this many minutes', '45')
31
+ .option('--json', 'Print the translated text, files written and the job as JSON')
32
+ .action(run(async (input, options) => {
33
+ const request = buildAudioTranslateRequest(options);
34
+ const outputs = audioOutputPaths(input, options);
35
+ const client = createCliClient();
36
+ const progress = spinner('Preparing', !!options.json).start();
37
+ let finished;
38
+ try {
39
+ const job = await submitTranslation(client, input, request, 'audio', (text) => { progress.text = text; });
40
+ finished = await followTranslation(client, job.id, Number(options.timeout) * 60_000, (j) => {
41
+ progress.text = `${j.stage ?? j.status}${j.progress ? ` ${j.progress}%` : ''}`;
42
+ });
43
+ }
44
+ finally {
45
+ progress.stop();
46
+ }
47
+ if (finished.status === 'failed')
48
+ throw new Error(`${finished.error?.code ?? 'FAILED'}: ${finished.error?.message ?? 'the job failed'}`);
49
+ const translation = finished.result?.translation;
50
+ if (!translation?.has_audio_file)
51
+ throw new Error(`Job ${finished.id} finished without a translated audio file.`);
52
+ await downloadTranslation(client, finished, 'audio', outputs.audio);
53
+ const written = [outputs.audio];
54
+ if (outputs.transcript) {
55
+ const text = options.transcript === 'vtt' ? translation.captions.vtt
56
+ : options.transcript === 'srt' ? translation.captions.srt
57
+ : translation.cues.map((cue) => cue.text).join('\n') + '\n';
58
+ fs.writeFileSync(outputs.transcript, text);
59
+ written.push(outputs.transcript);
60
+ }
61
+ if (options.json) {
62
+ return printJson({
63
+ text: translation.cues.map((cue) => cue.text).join(' '),
64
+ source_language: translation.source_language,
65
+ target_language: translation.target_language,
66
+ files: written,
67
+ job: finished,
68
+ });
69
+ }
70
+ success(`Translated ${translation.source_language} -> ${translation.target_language} (${Math.round(translation.duration_seconds)} s)`);
71
+ for (const file of written)
72
+ success(file);
73
+ }));
74
+ groupTranslateHelp(translate);
75
+ return translate;
76
+ }
77
+ //# sourceMappingURL=translate.js.map
@@ -0,0 +1 @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d,GAAG,EAAE,QAAQ;aACd,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,CAAC,cAAc,WAAW,CAAC,eAAe,OAAO,WAAW,CAAC,eAAe,KAAK,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QACtI,KAAK,MAAM,IAAI,IAAI,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAC,CAAA;IAEL,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAE7B,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `ph0ny video translate …` — turn a video (file or URL) into another
3
+ * language: captions burned in or as SRT/VTT, an optional per-speaker dub,
4
+ * optional lip sync. The work runs server-side (POST /v1/video/translate);
5
+ * this command gets the video there, follows the job, and saves the outputs.
6
+ */
7
+ import { Command } from 'commander';
8
+ import { buildVideoTranslateRequest, videoOutputPaths, type VideoTranslateCommandOptions } from './translate-options.js';
9
+ export type TranslateCommandOptions = VideoTranslateCommandOptions;
10
+ export declare const buildTranslateRequest: typeof buildVideoTranslateRequest;
11
+ export declare const outputPaths: typeof videoOutputPaths;
12
+ export declare function createVideoCommand(): Command;
13
+ //# sourceMappingURL=video.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../src/commands/video.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKnC,OAAO,EAAE,0BAA0B,EAAsB,gBAAgB,EAAE,KAAK,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAG5I,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,CAAA;AAClE,eAAO,MAAM,qBAAqB,mCAA6B,CAAA;AAC/D,eAAO,MAAM,WAAW,yBAAmB,CAAA;AAE3C,wBAAgB,kBAAkB,IAAI,OAAO,CA2D5C"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * `ph0ny video translate …` — turn a video (file or URL) into another
3
+ * language: captions burned in or as SRT/VTT, an optional per-speaker dub,
4
+ * optional lip sync. The work runs server-side (POST /v1/video/translate);
5
+ * this command gets the video there, follows the job, and saves the outputs.
6
+ */
7
+ import * as fs from 'node:fs';
8
+ import { Command } from 'commander';
9
+ import { createCliClient } from '../lib/client.js';
10
+ import { run } from '../lib/errors.js';
11
+ import { info, printJson, spinner, success, warn } from '../lib/output.js';
12
+ import { buildVideoTranslateRequest, groupTranslateHelp, videoOutputPaths } from './translate-options.js';
13
+ import { submitTranslation, followTranslation, downloadTranslation } from './translate-job.js';
14
+ export const buildTranslateRequest = buildVideoTranslateRequest;
15
+ export const outputPaths = videoOutputPaths;
16
+ export function createVideoCommand() {
17
+ const cmd = new Command('video').description('Translate, caption and dub videos');
18
+ const translate = cmd.command('translate')
19
+ .description('Translate a video into another language with captions, and optionally a dub')
20
+ .argument('<input>', 'Video file, direct media URL, or a page URL yt-dlp can fetch (X, YouTube, ...)')
21
+ .requiredOption('--to <language>', 'Target language (ISO code or name, e.g. en, es, "Japanese")')
22
+ .option('--from <language>', 'Spoken language (default: detected)')
23
+ .option('--captions <mode>', 'burn (into the picture) | srt | vtt (a caption file) | none', 'burn')
24
+ .option('--caption-style <style>', 'plain | viral | karaoke', 'plain')
25
+ .option('--caption-position <position>', 'bottom | top', 'bottom')
26
+ .option('--cover-captions', 'Hide captions already burned into the bottom of the source under a solid band')
27
+ .option('--audio <mode>', 'original | dub', 'original')
28
+ .option('--original-volume <0..1>', 'Original-audio level under a dub (default: 0.15; 0 = dub only)')
29
+ .option('--original-audio <mode>', 'full | background | none under a dub (default: full)')
30
+ .option('--voice <voice>', 'neutral | speakers | clone | a stock voice name | your consented clone id', 'neutral')
31
+ .option('--speaker-voice <speaker=voiceId...>', 'Voice per speaker, e.g. speaker_0=<your consented clone id>')
32
+ .option('--consent <json-file>', 'Consent attestations for --voice speakers, keyed by speaker_0, ...')
33
+ .option('--speaker-consents <json-file>', 'Legacy alias for --consent')
34
+ .option('--lipsync', 'Lip-sync the picture to the dub (needs --audio dub)')
35
+ .option('--speakers <n>', 'auto | number of speakers', 'auto')
36
+ .option('--out <path>', 'Output video path (default: <input>.<lang>.mp4 in the current directory)')
37
+ .option('--timeout <minutes>', 'Give up waiting after this many minutes', '45')
38
+ .option('--json', 'Print the finished job as JSON')
39
+ .action(run(async (input, options) => {
40
+ const request = buildTranslateRequest(options);
41
+ const client = createCliClient();
42
+ const outputs = outputPaths(input, options);
43
+ const progress = spinner('Preparing', !!options.json).start();
44
+ const job = await submitTranslation(client, input, request, 'video', (text) => { progress.text = text; });
45
+ const finished = await followTranslation(client, job.id, Number(options.timeout) * 60_000, (j) => {
46
+ progress.text = `${j.stage ?? j.status}${j.progress ? ` ${j.progress}%` : ''}`;
47
+ });
48
+ progress.stop();
49
+ if (finished.status === 'failed') {
50
+ throw new Error(`${finished.error?.code ?? 'FAILED'}: ${finished.error?.message ?? 'the job failed'}`);
51
+ }
52
+ const translation = finished.result?.translation;
53
+ if (!translation)
54
+ throw new Error(`Job ${finished.id} finished without a translation result.`);
55
+ const written = [];
56
+ if (outputs.captions) {
57
+ fs.writeFileSync(outputs.captions, outputs.captions.endsWith('.vtt') ? translation.captions.vtt : translation.captions.srt);
58
+ written.push(outputs.captions);
59
+ }
60
+ if (translation.has_video) {
61
+ await downloadTranslation(client, finished, 'video', outputs.video);
62
+ written.push(outputs.video);
63
+ }
64
+ if (options.json)
65
+ return printJson({ job: finished, files: written });
66
+ report(translation, written);
67
+ }));
68
+ groupTranslateHelp(translate);
69
+ return cmd;
70
+ }
71
+ function report(translation, files) {
72
+ success(`Translated ${translation.source_language} -> ${translation.target_language} (${Math.round(translation.duration_seconds)} s, ${translation.cues.length} captions)`);
73
+ for (const speaker of translation.speakers) {
74
+ const voice = speaker.voice ? `, voice ${speaker.voice.label} (${speaker.voice.kind})` : '';
75
+ info(`${speaker.id}: ${speaker.role ?? 'speaker'}, ${speaker.gender}${voice}`);
76
+ }
77
+ if (translation.dub_fit && translation.dub_fit.trimmed > 0) {
78
+ warn(`${translation.dub_fit.trimmed} of ${translation.dub_fit.utterances} dub lines were shortened to keep sync (${translation.dub_fit.trimmed_seconds} s).`);
79
+ }
80
+ for (const file of files)
81
+ info(`Wrote ${file}`);
82
+ }
83
+ //# sourceMappingURL=video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video.js","sourceRoot":"","sources":["../../src/commands/video.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,gBAAgB,EAAqC,MAAM,wBAAwB,CAAA;AAC5I,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAA;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAA;AAE3C,MAAM,UAAU,kBAAkB;IAChC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,mCAAmC,CAAC,CAAA;IAEjF,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC;SACvC,WAAW,CAAC,6EAA6E,CAAC;SAC1F,QAAQ,CAAC,SAAS,EAAE,gFAAgF,CAAC;SACrG,cAAc,CAAC,iBAAiB,EAAE,6DAA6D,CAAC;SAChG,MAAM,CAAC,mBAAm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,OAAO,GAAG,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,OAAO,WAAW,CAAC,OAAO,CAAC,UAAU,2CAA2C,WAAW,CAAC,OAAO,CAAC,eAAe,MAAM,CAAC,CAAA;IAC/J,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAA;AACjD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"voices.d.ts","sourceRoot":"","sources":["../../src/commands/voices.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,wBAAgB,mBAAmB,IAAI,OAAO,CA+G7C"}
1
+ {"version":3,"file":"voices.d.ts","sourceRoot":"","sources":["../../src/commands/voices.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,wBAAgB,mBAAmB,IAAI,OAAO,CAwF7C"}
@@ -6,26 +6,36 @@ import { Command } from 'commander';
6
6
  import { createCliClient } from '../lib/client.js';
7
7
  import { run } from '../lib/errors.js';
8
8
  import { printJson, printKeyValue, printTable, success } from '../lib/output.js';
9
- import { parseOptionalFloat, parsePositiveInt } from '../lib/command-utils.js';
9
+ import { parsePositiveInt } from '../lib/command-utils.js';
10
10
  export function createVoicesCommand() {
11
- const cmd = new Command('voices').description('Manage voices and synthesize speech');
11
+ const cmd = new Command('voices').description('List, clone and delete voices (speech: phony synthesize)');
12
12
  cmd
13
13
  .command('list')
14
- .description('List voices')
14
+ .description('List every voice the filters match; '
15
+ + '--json prints {data: [{id, name, provider, ...}], hasMore, nextCursor}, hasMore if --limit cut it')
16
+ .option('--provider <name>', 'Only this provider\'s voices (and the built-in "default"), e.g. cartesia')
15
17
  .option('--include-custom', 'Include custom voices')
16
- .option('--limit <n>', 'Max voices to return')
17
- .option('--cursor <cursor>', 'Pagination cursor')
18
+ .option('--limit <n>', 'Stop after n voices')
19
+ .option('--cursor <cursor>', 'Start after this voice id')
18
20
  .option('--json', 'Output as JSON')
19
21
  .action(run(async (options) => {
22
+ const cap = parsePositiveInt(options.limit, '--limit') ?? Infinity;
20
23
  const client = createCliClient();
21
- const page = await client.voice.tts.listVoices({
22
- includeCustom: Boolean(options.includeCustom),
23
- limit: parsePositiveInt(options.limit, '--limit'),
24
- cursor: options.cursor,
25
- });
24
+ const voices = [];
25
+ const cursors = new Set();
26
+ let page = { data: [], hasMore: true, nextCursor: options.cursor };
27
+ // GET /v1/voices answers one page; follow nextCursor to the end, stopping on a cursor the server already gave.
28
+ while (page.hasMore && voices.length < cap && !cursors.has(page.nextCursor)) {
29
+ cursors.add(page.nextCursor);
30
+ // The SDK's listVoices has no provider filter; GET /v1/voices takes one, and clamps limit to 200 (routes/tts.ts).
31
+ page = await client.request('GET', '/voices', {
32
+ query: { provider: options.provider, includeCustom: options.includeCustom, limit: Math.min(200, cap - voices.length), cursor: page.nextCursor },
33
+ });
34
+ voices.push(...page.data);
35
+ }
26
36
  if (options.json)
27
- return printJson(page);
28
- printTable(['ID', 'Name', 'Custom', 'Preview'], page.data.map(voice => [
37
+ return printJson({ ...page, data: voices });
38
+ printTable(['ID', 'Name', 'Custom', 'Preview'], voices.map(voice => [
29
39
  voice.id,
30
40
  voice.name,
31
41
  voice.isCustom,
@@ -52,51 +62,25 @@ export function createVoicesCommand() {
52
62
  }));
53
63
  cmd
54
64
  .command('clone')
55
- .description('Clone a voice from one or more audio sample files')
65
+ .description('Clone your own voice from one or more audio sample files')
56
66
  .requiredOption('--name <name>', 'Voice name')
57
- .requiredOption('--audio-file <path...>', 'Audio sample file(s)')
67
+ .requiredOption('--audio-file <path...>', 'Audio sample file(s) of your own voice')
68
+ .requiredOption('--consent <statement>', 'Your consent, quoted: e.g. "I consent to ph0ny cloning my voice."')
58
69
  .option('--description <text>', 'Voice description')
59
70
  .option('--json', 'Output as JSON')
60
71
  .action(run(async (options) => {
61
72
  const client = createCliClient();
62
73
  const samples = options.audioFile.map(file => fs.readFileSync(file));
74
+ // ph0ny clones only the requester's own voice; the statement is recorded on the clone.
63
75
  const result = await client.voice.tts.cloneVoice(samples, {
64
76
  name: options.name,
65
77
  description: options.description,
78
+ consent: { subject: 'self', statement: options.consent, speakerName: options.name },
66
79
  });
67
80
  if (options.json)
68
81
  return printJson(result);
69
82
  success(`Cloned voice ${result.voice.id} (${result.voice.name}) quality=${result.quality}`);
70
83
  }));
71
- cmd
72
- .command('synthesize')
73
- .description('Synthesize text with a voice')
74
- .argument('<voiceId>', 'Voice ID')
75
- .requiredOption('--text <text>', 'Text to synthesize')
76
- .option('--format <format>', 'Audio format, e.g. mp3 or wav')
77
- .option('--provider <provider>', 'TTS provider override')
78
- .option('--speed <n>', 'Speech speed')
79
- .option('--pitch <n>', 'Speech pitch')
80
- .option('--json', 'Output as JSON')
81
- .action(run(async (voiceId, options) => {
82
- const client = createCliClient();
83
- const result = await client.voice.tts.synthesize(options.text, {
84
- voiceId,
85
- format: (options.format ?? 'mp3'),
86
- provider: options.provider,
87
- speed: parseOptionalFloat(options.speed, '--speed') ?? 1,
88
- pitch: parseOptionalFloat(options.pitch, '--pitch') ?? 1,
89
- });
90
- if (options.json)
91
- return printJson(result);
92
- printKeyValue({
93
- Provider: result.provider,
94
- Duration: result.duration,
95
- Characters: result.charactersUsed,
96
- Audio: result.audioUrl ?? (result.audio ? '<inline base64>' : undefined),
97
- Format: result.audioFormat,
98
- });
99
- }));
100
84
  cmd
101
85
  .command('delete')
102
86
  .description('Delete a custom voice')