@transcribe-api/sdk 0.1.0 → 0.1.2
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/README.md +71 -9
- package/index.js +1806 -6
- package/package.json +21 -16
- package/worker.js +1358 -0
package/README.md
CHANGED
|
@@ -1,13 +1,75 @@
|
|
|
1
|
-
# Transcribe API JavaScript SDK
|
|
1
|
+
# Transcribe API JavaScript SDK
|
|
2
|
+
|
|
3
|
+
Official JavaScript SDK for Transcribe API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @transcribe-api/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { TranscribeAPI } from "@transcribe-api/sdk";
|
|
15
|
+
|
|
16
|
+
const client = new TranscribeAPI({
|
|
17
|
+
apiKey: "YOUR_API_KEY",
|
|
18
|
+
showLogs: true,
|
|
19
|
+
polling: {
|
|
20
|
+
interval: 10,
|
|
21
|
+
timeout: 15 * 60,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const transcript = await client.transcribe({
|
|
26
|
+
file: "audio.mp3",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const asyncJob = await client.transcribe({
|
|
30
|
+
file: "long-audio.mp3",
|
|
31
|
+
multipartConcurrency: 8,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const batchJob = await client.batch.transcribe({
|
|
35
|
+
files: [
|
|
36
|
+
{ reference_id: "episode_1", file: "a.mp3" },
|
|
37
|
+
{ reference_id: "episode_2", file: "b.wav" },
|
|
38
|
+
],
|
|
39
|
+
});
|
|
2
40
|
|
|
3
|
-
|
|
41
|
+
const remoteJob = await client.transcribe({
|
|
42
|
+
file: { url: "https://signed-get-url-from-s3-or-r2" },
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const remoteBatchJob = await client.batch.transcribe({
|
|
46
|
+
files: [
|
|
47
|
+
{ reference_id: "episode_1", url: "https://signed-get-url-1" },
|
|
48
|
+
{ reference_id: "episode_2", url: "https://signed-get-url-2" },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const mixedBatchJob = await client.batch.transcribe({
|
|
53
|
+
files: [
|
|
54
|
+
{ reference_id: "episode_1", file: "local.mp3" },
|
|
55
|
+
{ reference_id: "episode_2", url: "https://signed-get-url-2" },
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
4
59
|
|
|
5
|
-
|
|
60
|
+
For Cloudflare Workers and other web-style runtimes, use the Worker entrypoint:
|
|
6
61
|
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
62
|
+
```js
|
|
63
|
+
import { TranscribeAPI } from "@transcribe-api/sdk/worker";
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Async uploads use signed R2 URLs returned by the API. Multipart upload is used automatically when the backend returns a multipart flow.
|
|
67
|
+
Async job creation now goes through `POST /v1/transcribe` for single-file and batch jobs. For batch calls, each item must be `{ reference_id, file }` or `{ reference_id, url }`, and local plus remote entries can be mixed in the same batch. The SDK adds `size_bytes` automatically for large local files when the backend needs multipart upload.
|
|
68
|
+
Set `polling.interval` and optional `polling.timeout` in seconds on the client to make async jobs wait for completion automatically. The SDK enforces a minimum polling interval of `10` seconds and stops on `completed`, `failed`, or `insufficient_funds`.
|
|
69
|
+
If polling is not configured, use `GET /v1/transcribe/{job_id}` manually. The response always includes the core job fields and adds `result_url` when `job_status` is `completed`.
|
|
70
|
+
The SDK defaults `multipartConcurrency` to `8` for reliability. You can increase it up to `32` when your network path is stable.
|
|
71
|
+
For Node path uploads, multipart progress is persisted to a sidecar resume file and the SDK will resume the existing big-file job on the next run instead of starting over.
|
|
72
|
+
Multipart uploads also adaptively reduce concurrency on retryable transport errors instead of failing the whole upload immediately.
|
|
73
|
+
Set `showLogs: true` on the client or per async call to let the SDK print upload URL receipt, upload progress, and the final `/upload-completed` response automatically. Pass a custom `logger` object if you want those messages redirected somewhere other than `console`.
|
|
10
74
|
|
|
11
|
-
|
|
12
|
-
apiKey: "YOUR_API_KEY"
|
|
13
|
-
});
|
|
75
|
+
Use `@transcribe-api/sdk/worker` when you need a runtime-safe build for Cloudflare Workers. The Worker entrypoint supports remote URLs, `Blob`, `File`, and byte inputs, but does not support local file path strings or Node.js filesystem resume state.
|