transcribe-so 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/SKILL.md +168 -0
- package/dist/index.js +919 -0
- package/dist/index.js.map +1 -0
- package/examples/batch-transcribe.sh +46 -0
- package/examples/heartbeat-openclaw.json +14 -0
- package/examples/upload-flow.md +42 -0
- package/examples/youtube.json +6 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_yargs = __toESM(require("yargs"));
|
|
28
|
+
var import_helpers = require("yargs/helpers");
|
|
29
|
+
|
|
30
|
+
// src/version.ts
|
|
31
|
+
var CLI_VERSION = true ? "0.1.0" : "0.0.0-dev";
|
|
32
|
+
|
|
33
|
+
// src/commands/core.ts
|
|
34
|
+
var import_crypto = require("crypto");
|
|
35
|
+
|
|
36
|
+
// src/config.ts
|
|
37
|
+
var DEFAULT_API_URL = "https://transcribe.so";
|
|
38
|
+
var EXIT = {
|
|
39
|
+
OK: 0,
|
|
40
|
+
ERROR: 1,
|
|
41
|
+
USAGE: 2,
|
|
42
|
+
AUTH: 3,
|
|
43
|
+
PAYMENT: 4,
|
|
44
|
+
TRANSIENT: 5,
|
|
45
|
+
BUDGET: 6
|
|
46
|
+
};
|
|
47
|
+
function printJson(value) {
|
|
48
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
49
|
+
}
|
|
50
|
+
function failLocal(exitCode, code, message) {
|
|
51
|
+
printJson({ error: { code, message } });
|
|
52
|
+
process.stderr.write(`Error: ${message}
|
|
53
|
+
`);
|
|
54
|
+
process.exit(exitCode);
|
|
55
|
+
}
|
|
56
|
+
function getConfig(argv) {
|
|
57
|
+
const rawUrl = (process.env.TRANSCRIBE_API_URL || DEFAULT_API_URL).replace(
|
|
58
|
+
/\/+$/,
|
|
59
|
+
""
|
|
60
|
+
);
|
|
61
|
+
if (rawUrl !== DEFAULT_API_URL) {
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = new URL(rawUrl);
|
|
65
|
+
} catch {
|
|
66
|
+
failLocal(
|
|
67
|
+
EXIT.USAGE,
|
|
68
|
+
"invalid_api_url",
|
|
69
|
+
`TRANSCRIBE_API_URL is not a valid URL: ${rawUrl}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const isDefaultHost = parsed.protocol === "https:" && parsed.hostname === "transcribe.so";
|
|
73
|
+
if (!isDefaultHost && !argv.allowCustomHost) {
|
|
74
|
+
failLocal(
|
|
75
|
+
EXIT.USAGE,
|
|
76
|
+
"custom_host_refused",
|
|
77
|
+
`Refusing to send your API key to ${rawUrl} (non-default or non-https host). If this is intentional, pass --allow-custom-host.`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const apiKey = process.env.TRANSCRIBE_API_KEY;
|
|
82
|
+
if (!apiKey) {
|
|
83
|
+
failLocal(
|
|
84
|
+
EXIT.AUTH,
|
|
85
|
+
"missing_api_key",
|
|
86
|
+
"TRANSCRIBE_API_KEY is not set. Create a key at https://transcribe.so/settings/api-keys and export TRANSCRIBE_API_KEY=tsk_live_..."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return { apiKey, apiUrl: rawUrl };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/api.ts
|
|
93
|
+
var ApiError = class extends Error {
|
|
94
|
+
constructor(status, rawText, retryAfterSeconds) {
|
|
95
|
+
let envelope = null;
|
|
96
|
+
try {
|
|
97
|
+
envelope = JSON.parse(rawText);
|
|
98
|
+
} catch {
|
|
99
|
+
envelope = null;
|
|
100
|
+
}
|
|
101
|
+
const code = envelope?.error?.code ?? "unknown_error";
|
|
102
|
+
const message = envelope?.error?.message ?? rawText.slice(0, 500);
|
|
103
|
+
super(`API error ${status} ${code}: ${message}`);
|
|
104
|
+
this.status = status;
|
|
105
|
+
this.rawText = rawText;
|
|
106
|
+
this.envelope = envelope;
|
|
107
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
108
|
+
}
|
|
109
|
+
get code() {
|
|
110
|
+
return this.envelope?.error?.code ?? "unknown_error";
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
function exitCodeFor(err) {
|
|
114
|
+
switch (err.code) {
|
|
115
|
+
case "unauthenticated":
|
|
116
|
+
case "invalid_api_key":
|
|
117
|
+
case "scope_forbidden":
|
|
118
|
+
return EXIT.AUTH;
|
|
119
|
+
case "insufficient_funds":
|
|
120
|
+
case "spend_cap_exceeded":
|
|
121
|
+
return EXIT.PAYMENT;
|
|
122
|
+
case "rate_limited":
|
|
123
|
+
case "internal_error":
|
|
124
|
+
return EXIT.TRANSIENT;
|
|
125
|
+
// Not transient on a CLI timescale: the daily Q&A allowance frees up in
|
|
126
|
+
// hours, not seconds. Plain error so agents stop asking, not retry.
|
|
127
|
+
case "qna_quota_exceeded":
|
|
128
|
+
return EXIT.ERROR;
|
|
129
|
+
}
|
|
130
|
+
if (err.status === 401) return EXIT.AUTH;
|
|
131
|
+
if (err.status === 402) return EXIT.PAYMENT;
|
|
132
|
+
if (err.status === 429 || err.status >= 500) return EXIT.TRANSIENT;
|
|
133
|
+
return EXIT.ERROR;
|
|
134
|
+
}
|
|
135
|
+
function handleFailure(err) {
|
|
136
|
+
if (err instanceof ApiError) {
|
|
137
|
+
if (err.envelope !== null) {
|
|
138
|
+
process.stdout.write(err.rawText.endsWith("\n") ? err.rawText : err.rawText + "\n");
|
|
139
|
+
} else {
|
|
140
|
+
process.stdout.write(
|
|
141
|
+
JSON.stringify({
|
|
142
|
+
error: {
|
|
143
|
+
code: "upstream_error",
|
|
144
|
+
message: err.rawText.slice(0, 300),
|
|
145
|
+
http_status: err.status
|
|
146
|
+
}
|
|
147
|
+
}) + "\n"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
process.stderr.write(`${err.message}
|
|
151
|
+
`);
|
|
152
|
+
if (err.code === "not_ready") {
|
|
153
|
+
process.stderr.write(
|
|
154
|
+
"Hint: transcription not completed yet; run `transcribe-so wait <id>` first.\n"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
process.exit(exitCodeFor(err));
|
|
158
|
+
}
|
|
159
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
160
|
+
process.stdout.write(
|
|
161
|
+
JSON.stringify({ error: { code: "cli_error", message } }) + "\n"
|
|
162
|
+
);
|
|
163
|
+
process.stderr.write(`Error: ${message}
|
|
164
|
+
`);
|
|
165
|
+
process.exit(EXIT.ERROR);
|
|
166
|
+
}
|
|
167
|
+
function sleep(ms) {
|
|
168
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
169
|
+
}
|
|
170
|
+
var TranscribeAPI = class {
|
|
171
|
+
constructor(config) {
|
|
172
|
+
this.apiKey = config.apiKey;
|
|
173
|
+
this.apiUrl = config.apiUrl;
|
|
174
|
+
}
|
|
175
|
+
buildUrl(path, query) {
|
|
176
|
+
const url = new URL(`${this.apiUrl}/api/v1${path}`);
|
|
177
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
178
|
+
if (value !== void 0) url.searchParams.set(key, String(value));
|
|
179
|
+
}
|
|
180
|
+
return url.toString();
|
|
181
|
+
}
|
|
182
|
+
// Retry policy: decided on error.code, never on a bare 429 status.
|
|
183
|
+
// Only per-minute `rate_limited` responses with a short, finite
|
|
184
|
+
// Retry-After header are retried; fair-use / daily-allowance exhaustion
|
|
185
|
+
// shares the code but carries no short Retry-After window. Job-creating
|
|
186
|
+
// POSTs (create/retry) are never auto-retried at all — resubmitting a
|
|
187
|
+
// charge is the caller's call, idempotency key or not.
|
|
188
|
+
async request(path, options = {}) {
|
|
189
|
+
const method = options.method ?? "GET";
|
|
190
|
+
const url = this.buildUrl(path, options.query);
|
|
191
|
+
const maxAttempts = 3;
|
|
192
|
+
const isJobCreatingPost = method === "POST" && (path === "/transcriptions" || /\/retry$/.test(path));
|
|
193
|
+
for (let attempt = 1; ; attempt++) {
|
|
194
|
+
const headers = {
|
|
195
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
196
|
+
"User-Agent": `transcribe-so-cli/${CLI_VERSION}`,
|
|
197
|
+
Accept: "application/json"
|
|
198
|
+
};
|
|
199
|
+
if (options.body !== void 0) headers["Content-Type"] = "application/json";
|
|
200
|
+
if (options.idempotencyKey) headers["Idempotency-Key"] = options.idempotencyKey;
|
|
201
|
+
const response = await fetch(url, {
|
|
202
|
+
method,
|
|
203
|
+
headers,
|
|
204
|
+
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0
|
|
205
|
+
});
|
|
206
|
+
const rawText = await response.text();
|
|
207
|
+
if (response.ok) {
|
|
208
|
+
let json = null;
|
|
209
|
+
try {
|
|
210
|
+
json = JSON.parse(rawText);
|
|
211
|
+
} catch {
|
|
212
|
+
json = null;
|
|
213
|
+
}
|
|
214
|
+
return { status: response.status, headers: response.headers, rawText, json };
|
|
215
|
+
}
|
|
216
|
+
const retryAfterHeader = response.headers.get("retry-after");
|
|
217
|
+
const retryAfterSeconds = retryAfterHeader ? Number(retryAfterHeader) : null;
|
|
218
|
+
const err = new ApiError(response.status, rawText, retryAfterSeconds);
|
|
219
|
+
const retryable = err.code === "rate_limited" && !isJobCreatingPost && retryAfterSeconds !== null && Number.isFinite(retryAfterSeconds) && retryAfterSeconds <= 90;
|
|
220
|
+
if (retryable && attempt < maxAttempts) {
|
|
221
|
+
const waitSec = Math.max(1, retryAfterSeconds);
|
|
222
|
+
process.stderr.write(
|
|
223
|
+
`rate limited; retrying in ${waitSec}s (attempt ${attempt}/${maxAttempts - 1})
|
|
224
|
+
`
|
|
225
|
+
);
|
|
226
|
+
await sleep(waitSec * 1e3);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
throw err;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// GET that returns the RAW body (subtitles). Errors keep the envelope.
|
|
233
|
+
async requestRaw(path, query) {
|
|
234
|
+
const url = this.buildUrl(path, query);
|
|
235
|
+
const response = await fetch(url, {
|
|
236
|
+
headers: {
|
|
237
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
238
|
+
"User-Agent": `transcribe-so-cli/${CLI_VERSION}`
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const rawText = await response.text();
|
|
242
|
+
if (!response.ok) {
|
|
243
|
+
const retryAfterHeader = response.headers.get("retry-after");
|
|
244
|
+
throw new ApiError(
|
|
245
|
+
response.status,
|
|
246
|
+
rawText,
|
|
247
|
+
retryAfterHeader ? Number(retryAfterHeader) : null
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return rawText;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// src/commands/core.ts
|
|
255
|
+
var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
256
|
+
function apiFor(argv) {
|
|
257
|
+
return new TranscribeAPI(getConfig({ allowCustomHost: argv.allowCustomHost }));
|
|
258
|
+
}
|
|
259
|
+
function printRaw(rawText) {
|
|
260
|
+
process.stdout.write(rawText.endsWith("\n") ? rawText : rawText + "\n");
|
|
261
|
+
}
|
|
262
|
+
function buildCreateBody(argv) {
|
|
263
|
+
const body = { source: argv.source };
|
|
264
|
+
if (argv.url !== void 0) body.url = argv.url;
|
|
265
|
+
if (argv.uploadId !== void 0) body.upload_id = argv.uploadId;
|
|
266
|
+
if (argv.duration !== void 0) body.duration_seconds = argv.duration;
|
|
267
|
+
if (argv.language !== void 0) body.language = argv.language;
|
|
268
|
+
if (argv.callbackUrl !== void 0) body.callback_url = argv.callbackUrl;
|
|
269
|
+
return body;
|
|
270
|
+
}
|
|
271
|
+
async function authStatus(argv) {
|
|
272
|
+
const config = getConfig({ allowCustomHost: argv.allowCustomHost });
|
|
273
|
+
const api = new TranscribeAPI(config);
|
|
274
|
+
try {
|
|
275
|
+
const res = await api.request("/me");
|
|
276
|
+
printJson({
|
|
277
|
+
authenticated: true,
|
|
278
|
+
api_url: config.apiUrl,
|
|
279
|
+
email: res.json?.email ?? null,
|
|
280
|
+
subscription_tier: res.json?.subscription_tier ?? null,
|
|
281
|
+
wallet_balance_usd: res.json?.wallet_balance_usd ?? null,
|
|
282
|
+
api_key: res.json?.api_key ?? null
|
|
283
|
+
});
|
|
284
|
+
} catch (err) {
|
|
285
|
+
handleFailure(err);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function me(argv) {
|
|
289
|
+
try {
|
|
290
|
+
const res = await apiFor(argv).request("/me");
|
|
291
|
+
printRaw(res.rawText);
|
|
292
|
+
} catch (err) {
|
|
293
|
+
handleFailure(err);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async function pipelines(argv) {
|
|
297
|
+
try {
|
|
298
|
+
const res = await apiFor(argv).request("/pipelines");
|
|
299
|
+
printRaw(res.rawText);
|
|
300
|
+
} catch (err) {
|
|
301
|
+
handleFailure(err);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function quote(argv) {
|
|
305
|
+
try {
|
|
306
|
+
const res = await apiFor(argv).request("/quotes", {
|
|
307
|
+
method: "POST",
|
|
308
|
+
body: buildCreateBody(argv),
|
|
309
|
+
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
310
|
+
});
|
|
311
|
+
printRaw(res.rawText);
|
|
312
|
+
} catch (err) {
|
|
313
|
+
handleFailure(err);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async function create(argv) {
|
|
317
|
+
try {
|
|
318
|
+
const res = await apiFor(argv).request("/transcriptions", {
|
|
319
|
+
method: "POST",
|
|
320
|
+
body: buildCreateBody(argv),
|
|
321
|
+
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
322
|
+
});
|
|
323
|
+
printRaw(res.rawText);
|
|
324
|
+
} catch (err) {
|
|
325
|
+
handleFailure(err);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async function waitLoop(api, id, opts) {
|
|
329
|
+
const deadline = Date.now() + opts.timeoutSec * 1e3;
|
|
330
|
+
let last = null;
|
|
331
|
+
let quotedPolls = 0;
|
|
332
|
+
for (; ; ) {
|
|
333
|
+
const remaining = Math.ceil((deadline - Date.now()) / 1e3);
|
|
334
|
+
if (remaining <= 0) {
|
|
335
|
+
return { body: last?.body ?? null, rawText: last?.rawText ?? "null", timedOut: true };
|
|
336
|
+
}
|
|
337
|
+
const window = Math.min(45, Math.max(1, remaining));
|
|
338
|
+
const res = await api.request(`/transcriptions/${id}/wait`, {
|
|
339
|
+
query: { timeout: window, include: opts.include }
|
|
340
|
+
});
|
|
341
|
+
last = { body: res.json, rawText: res.rawText };
|
|
342
|
+
const status = res.json?.status;
|
|
343
|
+
if (TERMINAL_STATUSES.has(status)) {
|
|
344
|
+
return { body: res.json, rawText: res.rawText, timedOut: false };
|
|
345
|
+
}
|
|
346
|
+
if (status === "quoted") {
|
|
347
|
+
quotedPolls++;
|
|
348
|
+
process.stderr.write(
|
|
349
|
+
"this id looks like a quote, not a job; only the create 202 id is pollable\n"
|
|
350
|
+
);
|
|
351
|
+
if (quotedPolls >= 2) {
|
|
352
|
+
return { body: res.json, rawText: res.rawText, timedOut: false, notAJob: true };
|
|
353
|
+
}
|
|
354
|
+
} else if (status === "queued") {
|
|
355
|
+
process.stderr.write("waiting for a concurrency slot\n");
|
|
356
|
+
} else {
|
|
357
|
+
const stage = res.json?.stage ?? "?";
|
|
358
|
+
const progress = res.json?.progress ?? 0;
|
|
359
|
+
process.stderr.write(`status=${status} stage=${stage} progress=${progress}%
|
|
360
|
+
`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async function wait(argv) {
|
|
365
|
+
const api = apiFor(argv);
|
|
366
|
+
try {
|
|
367
|
+
const result2 = await waitLoop(api, argv.id, {
|
|
368
|
+
timeoutSec: argv.timeout,
|
|
369
|
+
include: argv.include
|
|
370
|
+
});
|
|
371
|
+
printRaw(result2.rawText);
|
|
372
|
+
if (result2.notAJob) {
|
|
373
|
+
process.stderr.write(
|
|
374
|
+
`id ${argv.id} is a quote row (status=quoted), not a started job; pass the id from the create 202 response
|
|
375
|
+
`
|
|
376
|
+
);
|
|
377
|
+
process.exit(EXIT.ERROR);
|
|
378
|
+
}
|
|
379
|
+
if (result2.timedOut) {
|
|
380
|
+
process.stderr.write(`wait timed out after ${argv.timeout}s (job still running)
|
|
381
|
+
`);
|
|
382
|
+
process.exit(EXIT.TRANSIENT);
|
|
383
|
+
}
|
|
384
|
+
if (result2.body?.status !== "completed") {
|
|
385
|
+
process.stderr.write(`transcription ended with status=${result2.body?.status}
|
|
386
|
+
`);
|
|
387
|
+
process.exit(EXIT.ERROR);
|
|
388
|
+
}
|
|
389
|
+
} catch (err) {
|
|
390
|
+
handleFailure(err);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async function result(argv) {
|
|
394
|
+
try {
|
|
395
|
+
const res = await apiFor(argv).request(`/transcriptions/${argv.id}/result`, {
|
|
396
|
+
query: { include: argv.include }
|
|
397
|
+
});
|
|
398
|
+
printRaw(res.rawText);
|
|
399
|
+
} catch (err) {
|
|
400
|
+
handleFailure(err);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async function run(argv) {
|
|
404
|
+
const api = apiFor(argv);
|
|
405
|
+
try {
|
|
406
|
+
const body = buildCreateBody(argv);
|
|
407
|
+
const quoteRes = await api.request("/quotes", {
|
|
408
|
+
method: "POST",
|
|
409
|
+
body,
|
|
410
|
+
idempotencyKey: (0, import_crypto.randomUUID)()
|
|
411
|
+
});
|
|
412
|
+
const retailUsd = Number(quoteRes.json?.retail_usd);
|
|
413
|
+
const billedMinutes = quoteRes.json?.billed_minutes;
|
|
414
|
+
process.stderr.write(`quote: $${retailUsd.toFixed(2)} for ${billedMinutes} billed minute(s)
|
|
415
|
+
`);
|
|
416
|
+
if (!Number.isFinite(argv.maxUsd) || !Number.isFinite(retailUsd) || retailUsd > argv.maxUsd) {
|
|
417
|
+
printJson({
|
|
418
|
+
error: {
|
|
419
|
+
code: "max_usd_exceeded",
|
|
420
|
+
message: `Quoted price $${retailUsd} exceeds --max-usd ${argv.maxUsd}. Re-run with a higher --max-usd to proceed (this is a local budget refusal, not a balance problem; do not top up).`,
|
|
421
|
+
quote: quoteRes.json
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
process.stderr.write(
|
|
425
|
+
`Refusing to create: quoted $${retailUsd} > --max-usd ${argv.maxUsd}
|
|
426
|
+
`
|
|
427
|
+
);
|
|
428
|
+
process.exit(EXIT.BUDGET);
|
|
429
|
+
}
|
|
430
|
+
const createRes = await api.request("/transcriptions", {
|
|
431
|
+
method: "POST",
|
|
432
|
+
body,
|
|
433
|
+
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
434
|
+
});
|
|
435
|
+
const id = createRes.json?.id;
|
|
436
|
+
process.stderr.write(
|
|
437
|
+
`created transcription ${id} (held $${createRes.json?.retail_usd})
|
|
438
|
+
`
|
|
439
|
+
);
|
|
440
|
+
const waited = await waitLoop(api, id, { timeoutSec: argv.timeout });
|
|
441
|
+
if (waited.notAJob) {
|
|
442
|
+
printRaw(waited.rawText);
|
|
443
|
+
process.stderr.write(`transcription ${id} unexpectedly reports status=quoted
|
|
444
|
+
`);
|
|
445
|
+
process.exit(EXIT.ERROR);
|
|
446
|
+
}
|
|
447
|
+
if (waited.timedOut) {
|
|
448
|
+
printRaw(waited.rawText);
|
|
449
|
+
process.stderr.write(
|
|
450
|
+
`wait timed out after ${argv.timeout}s; resume with: transcribe-so wait ${id}
|
|
451
|
+
`
|
|
452
|
+
);
|
|
453
|
+
process.exit(EXIT.TRANSIENT);
|
|
454
|
+
}
|
|
455
|
+
if (waited.body?.status !== "completed") {
|
|
456
|
+
printRaw(waited.rawText);
|
|
457
|
+
process.stderr.write(`transcription ${id} ended with status=${waited.body?.status}
|
|
458
|
+
`);
|
|
459
|
+
process.exit(EXIT.ERROR);
|
|
460
|
+
}
|
|
461
|
+
const resultRes = await api.request(`/transcriptions/${id}/result`, {
|
|
462
|
+
query: { include: argv.include }
|
|
463
|
+
});
|
|
464
|
+
printRaw(resultRes.rawText);
|
|
465
|
+
} catch (err) {
|
|
466
|
+
handleFailure(err);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async function list(argv) {
|
|
470
|
+
try {
|
|
471
|
+
const res = await apiFor(argv).request("/transcriptions", {
|
|
472
|
+
query: {
|
|
473
|
+
limit: argv.limit,
|
|
474
|
+
cursor: argv.cursor,
|
|
475
|
+
api_only: argv.apiOnly ? true : void 0
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
printRaw(res.rawText);
|
|
479
|
+
} catch (err) {
|
|
480
|
+
handleFailure(err);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
async function get(argv) {
|
|
484
|
+
try {
|
|
485
|
+
const res = await apiFor(argv).request(`/transcriptions/${argv.id}`);
|
|
486
|
+
printRaw(res.rawText);
|
|
487
|
+
} catch (err) {
|
|
488
|
+
handleFailure(err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async function deleteTranscription(argv) {
|
|
492
|
+
try {
|
|
493
|
+
const res = await apiFor(argv).request(`/transcriptions/${argv.id}`, {
|
|
494
|
+
method: "DELETE"
|
|
495
|
+
});
|
|
496
|
+
printRaw(res.rawText);
|
|
497
|
+
} catch (err) {
|
|
498
|
+
handleFailure(err);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
async function retry(argv) {
|
|
502
|
+
try {
|
|
503
|
+
const res = await apiFor(argv).request(`/transcriptions/${argv.id}/retry`, {
|
|
504
|
+
method: "POST",
|
|
505
|
+
idempotencyKey: argv.idempotencyKey ?? (0, import_crypto.randomUUID)()
|
|
506
|
+
});
|
|
507
|
+
printRaw(res.rawText);
|
|
508
|
+
} catch (err) {
|
|
509
|
+
handleFailure(err);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/commands/artifacts.ts
|
|
514
|
+
function apiFor2(argv) {
|
|
515
|
+
return new TranscribeAPI(getConfig({ allowCustomHost: argv.allowCustomHost }));
|
|
516
|
+
}
|
|
517
|
+
async function subtitles(argv) {
|
|
518
|
+
try {
|
|
519
|
+
const raw = await apiFor2(argv).requestRaw(
|
|
520
|
+
`/transcriptions/${argv.id}/subtitles`,
|
|
521
|
+
{
|
|
522
|
+
format: argv.format,
|
|
523
|
+
preset: argv.preset,
|
|
524
|
+
speaker_labels: argv.speakerLabels ? true : void 0,
|
|
525
|
+
mode: argv.mode,
|
|
526
|
+
source: argv.source
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
process.stdout.write(raw.endsWith("\n") ? raw : raw + "\n");
|
|
530
|
+
} catch (err) {
|
|
531
|
+
handleFailure(err);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
async function ask(argv) {
|
|
535
|
+
try {
|
|
536
|
+
const body = { question: argv.question };
|
|
537
|
+
if (argv.topK !== void 0) body.top_k = argv.topK;
|
|
538
|
+
const res = await apiFor2(argv).request(`/transcriptions/${argv.id}/ask`, {
|
|
539
|
+
method: "POST",
|
|
540
|
+
body
|
|
541
|
+
});
|
|
542
|
+
process.stdout.write(res.rawText.endsWith("\n") ? res.rawText : res.rawText + "\n");
|
|
543
|
+
} catch (err) {
|
|
544
|
+
handleFailure(err);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// src/commands/upload.ts
|
|
549
|
+
var import_child_process = require("child_process");
|
|
550
|
+
var import_fs = require("fs");
|
|
551
|
+
var import_path = require("path");
|
|
552
|
+
var CONTENT_TYPE_ALLOWLIST = [
|
|
553
|
+
"audio/mpeg",
|
|
554
|
+
"audio/mp3",
|
|
555
|
+
"audio/wav",
|
|
556
|
+
"audio/m4a",
|
|
557
|
+
"audio/mp4",
|
|
558
|
+
"audio/x-m4a",
|
|
559
|
+
"audio/aac",
|
|
560
|
+
"audio/ogg",
|
|
561
|
+
"audio/webm",
|
|
562
|
+
"audio/flac",
|
|
563
|
+
"video/mp4",
|
|
564
|
+
"video/webm",
|
|
565
|
+
"video/quicktime",
|
|
566
|
+
"video/x-msvideo"
|
|
567
|
+
];
|
|
568
|
+
var EXTENSION_MAP = {
|
|
569
|
+
".mp3": "audio/mpeg",
|
|
570
|
+
".mpga": "audio/mpeg",
|
|
571
|
+
".wav": "audio/wav",
|
|
572
|
+
".m4a": "audio/m4a",
|
|
573
|
+
".aac": "audio/aac",
|
|
574
|
+
".ogg": "audio/ogg",
|
|
575
|
+
".oga": "audio/ogg",
|
|
576
|
+
".flac": "audio/flac",
|
|
577
|
+
".webm": "video/webm",
|
|
578
|
+
".mp4": "video/mp4",
|
|
579
|
+
".mov": "video/quicktime",
|
|
580
|
+
".avi": "video/x-msvideo"
|
|
581
|
+
};
|
|
582
|
+
var WARN_BYTES = 50 * 1024 * 1024;
|
|
583
|
+
var HARD_LIMIT_BYTES = 500 * 1024 * 1024;
|
|
584
|
+
function resolveContentType(file, override) {
|
|
585
|
+
if (override) {
|
|
586
|
+
if (!CONTENT_TYPE_ALLOWLIST.includes(override)) {
|
|
587
|
+
failLocal(
|
|
588
|
+
EXIT.USAGE,
|
|
589
|
+
"unsupported_content_type",
|
|
590
|
+
`--content-type ${override} is not accepted by the API. Allowed: ${CONTENT_TYPE_ALLOWLIST.join(", ")}`
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
return override;
|
|
594
|
+
}
|
|
595
|
+
const ext = (0, import_path.extname)(file).toLowerCase();
|
|
596
|
+
const type = EXTENSION_MAP[ext];
|
|
597
|
+
if (!type) {
|
|
598
|
+
failLocal(
|
|
599
|
+
EXIT.USAGE,
|
|
600
|
+
"unsupported_content_type",
|
|
601
|
+
`Cannot map extension "${ext}" to an accepted content type. Pass --content-type with one of: ${CONTENT_TYPE_ALLOWLIST.join(", ")}`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
return type;
|
|
605
|
+
}
|
|
606
|
+
function probeDurationSeconds(file) {
|
|
607
|
+
const probe = (0, import_child_process.spawnSync)(
|
|
608
|
+
"ffprobe",
|
|
609
|
+
[
|
|
610
|
+
"-v",
|
|
611
|
+
"error",
|
|
612
|
+
"-show_entries",
|
|
613
|
+
"format=duration",
|
|
614
|
+
"-of",
|
|
615
|
+
"default=noprint_wrappers=1:nokey=1",
|
|
616
|
+
file
|
|
617
|
+
],
|
|
618
|
+
{ encoding: "utf8" }
|
|
619
|
+
);
|
|
620
|
+
if (probe.error || probe.status !== 0) return null;
|
|
621
|
+
const seconds = parseFloat(probe.stdout.trim());
|
|
622
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds : null;
|
|
623
|
+
}
|
|
624
|
+
async function upload(argv) {
|
|
625
|
+
const file = argv.file;
|
|
626
|
+
let size;
|
|
627
|
+
try {
|
|
628
|
+
size = (0, import_fs.statSync)(file).size;
|
|
629
|
+
} catch {
|
|
630
|
+
failLocal(EXIT.USAGE, "file_not_found", `File not found: ${file}`);
|
|
631
|
+
}
|
|
632
|
+
if (size > HARD_LIMIT_BYTES) {
|
|
633
|
+
failLocal(
|
|
634
|
+
EXIT.ERROR,
|
|
635
|
+
"file_too_large_for_presigned",
|
|
636
|
+
`${file} is ${(size / (1024 * 1024)).toFixed(0)} MB; the CLI's single-shot presigned upload is capped at 500 MB. Use a resumable tus upload (POST /api/v1/uploads/tus with any tus 1.0 client) or upload via https://transcribe.so instead.`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
if (size > WARN_BYTES) {
|
|
640
|
+
process.stderr.write(
|
|
641
|
+
`warning: ${(size / (1024 * 1024)).toFixed(0)} MB single-shot upload; the presigned URL expires in 900s. For flaky networks prefer the resumable tus flow (POST /api/v1/uploads/tus) or the web app.
|
|
642
|
+
`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
const contentType = resolveContentType(file, argv.contentType);
|
|
646
|
+
let durationSeconds = argv.duration;
|
|
647
|
+
if (durationSeconds === void 0) {
|
|
648
|
+
const probed = probeDurationSeconds(file);
|
|
649
|
+
if (probed === null) {
|
|
650
|
+
failLocal(
|
|
651
|
+
EXIT.USAGE,
|
|
652
|
+
"duration_required",
|
|
653
|
+
"Duration is required for uploads and ffprobe is not available (or could not read this file). Either pass --duration <seconds> or install ffmpeg so ffprobe is on PATH."
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
durationSeconds = probed;
|
|
657
|
+
process.stderr.write(`ffprobe duration: ${durationSeconds.toFixed(1)}s
|
|
658
|
+
`);
|
|
659
|
+
}
|
|
660
|
+
const api = new TranscribeAPI(getConfig({ allowCustomHost: argv.allowCustomHost }));
|
|
661
|
+
try {
|
|
662
|
+
const res = await api.request("/uploads", {
|
|
663
|
+
method: "POST",
|
|
664
|
+
body: {
|
|
665
|
+
filename: (0, import_path.basename)(file),
|
|
666
|
+
content_type: contentType,
|
|
667
|
+
file_size: size
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
const uploadUrl = res.json.upload_url;
|
|
671
|
+
process.stderr.write(`uploading ${(0, import_path.basename)(file)} (${size} bytes)...
|
|
672
|
+
`);
|
|
673
|
+
const putResponse = await fetch(uploadUrl, {
|
|
674
|
+
method: "PUT",
|
|
675
|
+
headers: { "Content-Type": contentType },
|
|
676
|
+
body: (0, import_fs.readFileSync)(file)
|
|
677
|
+
});
|
|
678
|
+
if (!putResponse.ok) {
|
|
679
|
+
const text = await putResponse.text();
|
|
680
|
+
printJson({
|
|
681
|
+
error: {
|
|
682
|
+
code: "upload_put_failed",
|
|
683
|
+
message: `PUT to presigned URL failed with ${putResponse.status}: ${text.slice(0, 300)}`
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
process.stderr.write(`upload PUT failed (${putResponse.status})
|
|
687
|
+
`);
|
|
688
|
+
process.exit(EXIT.TRANSIENT);
|
|
689
|
+
}
|
|
690
|
+
printJson({
|
|
691
|
+
upload_id: res.json.upload_id,
|
|
692
|
+
duration_seconds: durationSeconds,
|
|
693
|
+
filename: (0, import_path.basename)(file),
|
|
694
|
+
file_size: size,
|
|
695
|
+
content_type: contentType,
|
|
696
|
+
next: `transcribe-so create --source upload --upload-id ${res.json.upload_id} --duration ${durationSeconds}`
|
|
697
|
+
});
|
|
698
|
+
} catch (err) {
|
|
699
|
+
handleFailure(err);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// src/index.ts
|
|
704
|
+
var INCLUDE_DESCRIBE = "Comma-separated result sections: chapters, acts, sections, qna, segments, posting_chapters, or all. Default chapters,sections,qna";
|
|
705
|
+
function sourceOptions(y) {
|
|
706
|
+
return y.option("source", {
|
|
707
|
+
describe: "Input source",
|
|
708
|
+
type: "string",
|
|
709
|
+
choices: ["youtube", "external_url", "platform_url", "upload"],
|
|
710
|
+
demandOption: true
|
|
711
|
+
}).option("url", {
|
|
712
|
+
describe: "Media URL (required for youtube / platform_url / external_url)",
|
|
713
|
+
type: "string"
|
|
714
|
+
}).option("upload-id", {
|
|
715
|
+
describe: "upload_id from `transcribe-so upload` (required for source=upload)",
|
|
716
|
+
type: "string"
|
|
717
|
+
}).option("duration", {
|
|
718
|
+
describe: "Media duration in seconds (required for upload; speeds up URL sources)",
|
|
719
|
+
type: "number"
|
|
720
|
+
}).option("language", {
|
|
721
|
+
describe: "BCP-47 language code (en, ja, ko, ...) or auto (default)",
|
|
722
|
+
type: "string"
|
|
723
|
+
}).option("callback-url", {
|
|
724
|
+
describe: "Public https URL that receives this job's signed completed/failed webhook",
|
|
725
|
+
type: "string"
|
|
726
|
+
}).option("idempotency-key", {
|
|
727
|
+
describe: "Override the auto-generated Idempotency-Key (max 128 chars)",
|
|
728
|
+
type: "string"
|
|
729
|
+
}).check((argv) => {
|
|
730
|
+
if (argv.source === "upload") {
|
|
731
|
+
if (!argv.uploadId) throw new Error("source=upload requires --upload-id");
|
|
732
|
+
if (argv.duration === void 0)
|
|
733
|
+
throw new Error("source=upload requires --duration <seconds>");
|
|
734
|
+
} else if (!argv.url) {
|
|
735
|
+
throw new Error(`source=${argv.source} requires --url`);
|
|
736
|
+
}
|
|
737
|
+
if (argv.duration !== void 0 && (!Number.isFinite(argv.duration) || argv.duration <= 0)) {
|
|
738
|
+
throw new Error("--duration must be a positive number of seconds");
|
|
739
|
+
}
|
|
740
|
+
return true;
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
var parser = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).scriptName("transcribe-so").usage("$0 <command> [options]\n\nPure-JSON stdout (subtitles excepted); progress goes to stderr.").option("allow-custom-host", {
|
|
744
|
+
describe: "Allow sending the API key to a non-default TRANSCRIBE_API_URL host (refused otherwise)",
|
|
745
|
+
type: "boolean",
|
|
746
|
+
default: false,
|
|
747
|
+
global: true
|
|
748
|
+
}).command(
|
|
749
|
+
"auth:status",
|
|
750
|
+
"Check whether TRANSCRIBE_API_KEY authenticates against the API",
|
|
751
|
+
{},
|
|
752
|
+
authStatus
|
|
753
|
+
).command(
|
|
754
|
+
"me",
|
|
755
|
+
"Account, wallet balance, plan limits, API-key scopes and spend",
|
|
756
|
+
(y) => y.example("$0 me | jq .wallet_balance_usd", "Check the wallet balance"),
|
|
757
|
+
me
|
|
758
|
+
).command(
|
|
759
|
+
"pipelines",
|
|
760
|
+
"Capability catalog: pricing per minute and supported languages",
|
|
761
|
+
(y) => y.example("$0 pipelines | jq '.pipelines[0].retail_usd_per_min'", "Current per-minute rate"),
|
|
762
|
+
pipelines
|
|
763
|
+
).command(
|
|
764
|
+
"quote",
|
|
765
|
+
"Preview the exact cost of a transcription (free, does not queue the job)",
|
|
766
|
+
(y) => sourceOptions(y).example(
|
|
767
|
+
'$0 quote --source youtube --url "https://www.youtube.com/watch?v=jNQXAC9IVRw"',
|
|
768
|
+
"Price a YouTube video"
|
|
769
|
+
).example(
|
|
770
|
+
"$0 quote --source upload --upload-id up_abc --duration 1800",
|
|
771
|
+
"Price an uploaded file (30 min)"
|
|
772
|
+
),
|
|
773
|
+
quote
|
|
774
|
+
).command(
|
|
775
|
+
"create",
|
|
776
|
+
"Submit a transcription (charges the wallet; prints the 202 body)",
|
|
777
|
+
(y) => sourceOptions(y).example(
|
|
778
|
+
'$0 create --source youtube --url "https://youtu.be/jNQXAC9IVRw"',
|
|
779
|
+
"Transcribe a YouTube video"
|
|
780
|
+
).example(
|
|
781
|
+
"$0 create --source upload --upload-id up_abc --duration 1800",
|
|
782
|
+
"Transcribe an uploaded file"
|
|
783
|
+
),
|
|
784
|
+
create
|
|
785
|
+
).command(
|
|
786
|
+
"wait <id>",
|
|
787
|
+
"Long-poll until the transcription completes or fails (server-side windows)",
|
|
788
|
+
(y) => y.positional("id", { describe: "Transcription id from the create 202", type: "number" }).option("timeout", {
|
|
789
|
+
describe: "Overall seconds to keep waiting",
|
|
790
|
+
type: "number",
|
|
791
|
+
default: 1800
|
|
792
|
+
}).option("include", { describe: INCLUDE_DESCRIBE, type: "string" }).example("$0 wait 4821", "Wait for job 4821").example("$0 wait 4821 --include all", "Wait and inline the full result on completion"),
|
|
793
|
+
wait
|
|
794
|
+
).command(
|
|
795
|
+
"result <id>",
|
|
796
|
+
"Fetch the result of a completed transcription",
|
|
797
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("include", { describe: INCLUDE_DESCRIBE, type: "string" }).example("$0 result 4821", "Chapters, sections and Q&A").example("$0 result 4821 --include segments | jq -r '.segments[].text'", "Full verbatim text"),
|
|
798
|
+
result
|
|
799
|
+
).command(
|
|
800
|
+
"run",
|
|
801
|
+
"quote, then create, wait, and fetch the result in one command (requires --max-usd)",
|
|
802
|
+
(y) => sourceOptions(y).option("max-usd", {
|
|
803
|
+
describe: "Hard budget: refuse (exit 6) if the quote exceeds this many USD. Required; there is no default.",
|
|
804
|
+
type: "number",
|
|
805
|
+
demandOption: true
|
|
806
|
+
}).option("timeout", {
|
|
807
|
+
describe: "Overall seconds to wait for completion",
|
|
808
|
+
type: "number",
|
|
809
|
+
default: 1800
|
|
810
|
+
}).option("include", { describe: INCLUDE_DESCRIBE, type: "string" }).check((argv) => {
|
|
811
|
+
if (!Number.isFinite(argv.maxUsd) || argv.maxUsd < 0) {
|
|
812
|
+
throw new Error("--max-usd must be a finite number >= 0 (e.g. --max-usd 2)");
|
|
813
|
+
}
|
|
814
|
+
return true;
|
|
815
|
+
}).example(
|
|
816
|
+
'$0 run --source youtube --url "https://youtu.be/jNQXAC9IVRw" --max-usd 2',
|
|
817
|
+
"Transcribe end to end, refusing if it would cost more than $2"
|
|
818
|
+
),
|
|
819
|
+
run
|
|
820
|
+
).command(
|
|
821
|
+
"list",
|
|
822
|
+
"List transcriptions (newest first, cursor-paginated)",
|
|
823
|
+
(y) => y.option("limit", { describe: "1-200, default 50", type: "number" }).option("cursor", { describe: "next_cursor from the previous page", type: "string" }).option("api-only", { describe: "Only jobs created via API", type: "boolean" }).example("$0 list --limit 5 | jq '.data[] | {id, status, title}'", "Latest five jobs"),
|
|
824
|
+
list
|
|
825
|
+
).command(
|
|
826
|
+
"get <id>",
|
|
827
|
+
"Get one transcription (status, stage, progress, charge)",
|
|
828
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).example("$0 get 4821 | jq .status", "Check status"),
|
|
829
|
+
get
|
|
830
|
+
).command(
|
|
831
|
+
"delete <id>",
|
|
832
|
+
"Permanently delete a transcription and all derived data (irreversible)",
|
|
833
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("yes", {
|
|
834
|
+
describe: "Required confirmation flag; deletion is irreversible",
|
|
835
|
+
type: "boolean",
|
|
836
|
+
default: false
|
|
837
|
+
}).check((argv) => {
|
|
838
|
+
if (!argv.yes) throw new Error("delete is irreversible; re-run with --yes to confirm");
|
|
839
|
+
return true;
|
|
840
|
+
}).example("$0 delete 4821 --yes", "Delete transcription 4821"),
|
|
841
|
+
deleteTranscription
|
|
842
|
+
).command(
|
|
843
|
+
"retry <id>",
|
|
844
|
+
"Retry a failed transcription (charges again from scratch)",
|
|
845
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("yes", {
|
|
846
|
+
describe: "Required confirmation flag; retry re-charges the wallet from scratch",
|
|
847
|
+
type: "boolean",
|
|
848
|
+
default: false
|
|
849
|
+
}).option("idempotency-key", {
|
|
850
|
+
describe: "Override the auto-generated Idempotency-Key",
|
|
851
|
+
type: "string"
|
|
852
|
+
}).check((argv) => {
|
|
853
|
+
if (!argv.yes) throw new Error("retry re-charges from scratch; re-run with --yes to confirm");
|
|
854
|
+
return true;
|
|
855
|
+
}).example("$0 retry 4821 --yes", "Re-run failed job 4821"),
|
|
856
|
+
retry
|
|
857
|
+
).command(
|
|
858
|
+
"upload <file>",
|
|
859
|
+
"Upload a local media file; prints the upload_id to pass to create/run",
|
|
860
|
+
(y) => y.positional("file", { describe: "Path to the audio/video file", type: "string" }).option("duration", {
|
|
861
|
+
describe: "Duration in seconds (otherwise probed with ffprobe if installed)",
|
|
862
|
+
type: "number"
|
|
863
|
+
}).option("content-type", {
|
|
864
|
+
describe: "Override the MIME type (must be on the API allowlist)",
|
|
865
|
+
type: "string"
|
|
866
|
+
}).check((argv) => {
|
|
867
|
+
if (argv.duration !== void 0 && (!Number.isFinite(argv.duration) || argv.duration <= 0)) {
|
|
868
|
+
throw new Error("--duration must be a positive number of seconds");
|
|
869
|
+
}
|
|
870
|
+
return true;
|
|
871
|
+
}).example("$0 upload ./interview.mp3", "Upload an MP3 (duration via ffprobe)").example("$0 upload ./talk.mp4 --duration 1922", "Upload with explicit duration"),
|
|
872
|
+
upload
|
|
873
|
+
).command(
|
|
874
|
+
"subtitles <id>",
|
|
875
|
+
"Print the raw subtitle file (SRT/VTT/JSON) to stdout - the one non-JSON command",
|
|
876
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("format", {
|
|
877
|
+
describe: "Subtitle format",
|
|
878
|
+
type: "string",
|
|
879
|
+
choices: ["srt", "vtt", "vtt-karaoke", "json"]
|
|
880
|
+
}).option("preset", {
|
|
881
|
+
describe: "Platform line rules",
|
|
882
|
+
type: "string",
|
|
883
|
+
choices: ["youtube", "tiktok-shorts", "instagram-reels", "netflix", "podcast", "broadcast"]
|
|
884
|
+
}).option("speaker-labels", { describe: "Prefix cues with [Speaker]", type: "boolean" }).option("mode", {
|
|
885
|
+
describe: "Cue timing",
|
|
886
|
+
type: "string",
|
|
887
|
+
choices: ["auto", "word", "sentence"]
|
|
888
|
+
}).option("source", {
|
|
889
|
+
describe: "Which cues to serve",
|
|
890
|
+
type: "string",
|
|
891
|
+
choices: ["auto", "generated", "materialized"]
|
|
892
|
+
}).example("$0 subtitles 4821 > talk.srt", "Save the SRT").example("$0 subtitles 4821 --format vtt --preset tiktok-shorts > talk.vtt", "Vertical-video VTT"),
|
|
893
|
+
subtitles
|
|
894
|
+
).command(
|
|
895
|
+
"ask <id>",
|
|
896
|
+
"Ask a question about one completed transcription (cited answer; daily Q&A allowance)",
|
|
897
|
+
(y) => y.positional("id", { describe: "Transcription id", type: "number" }).option("question", {
|
|
898
|
+
alias: "q",
|
|
899
|
+
describe: "The question (1-500 chars)",
|
|
900
|
+
type: "string",
|
|
901
|
+
demandOption: true
|
|
902
|
+
}).option("top-k", { describe: "Retrieval candidates before rerank (10-100)", type: "number" }).example('$0 ask 4821 -q "What did the guest say about pricing?"', "Cited Q&A"),
|
|
903
|
+
ask
|
|
904
|
+
).demandCommand(1, "You need at least one command").strict().help().alias("h", "help").version(CLI_VERSION).alias("v", "version").wrap(Math.min(100, process.stdout.columns || 100)).epilogue(
|
|
905
|
+
"Authentication: export TRANSCRIBE_API_KEY=tsk_live_... (create one at https://transcribe.so/settings/api-keys)\nDocs: https://transcribe.so/developers/docs | OpenAPI: https://transcribe.so/openapi.json"
|
|
906
|
+
).fail((msg, err, instance) => {
|
|
907
|
+
if (err) {
|
|
908
|
+
process.stderr.write(`${err.message}
|
|
909
|
+
`);
|
|
910
|
+
process.exit(2);
|
|
911
|
+
}
|
|
912
|
+
instance.showHelp("error");
|
|
913
|
+
process.stderr.write(`
|
|
914
|
+
${msg}
|
|
915
|
+
`);
|
|
916
|
+
process.exit(2);
|
|
917
|
+
});
|
|
918
|
+
parser.parse();
|
|
919
|
+
//# sourceMappingURL=index.js.map
|