speechrevolutions 0.2.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 +183 -0
- package/dist/cjs/client.js +786 -0
- package/dist/cjs/exceptions.js +77 -0
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/progress.js +130 -0
- package/dist/cjs/sse.js +56 -0
- package/dist/cjs/transcript.js +303 -0
- package/dist/cjs/types.js +31 -0
- package/dist/cjs/upload.js +44 -0
- package/dist/esm/client.d.ts +94 -0
- package/dist/esm/client.js +748 -0
- package/dist/esm/exceptions.d.ts +46 -0
- package/dist/esm/exceptions.js +66 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/progress.d.ts +58 -0
- package/dist/esm/progress.js +125 -0
- package/dist/esm/sse.d.ts +7 -0
- package/dist/esm/sse.js +53 -0
- package/dist/esm/transcript.d.ts +51 -0
- package/dist/esm/transcript.js +267 -0
- package/dist/esm/types.d.ts +73 -0
- package/dist/esm/types.js +26 -0
- package/dist/esm/upload.d.ts +26 -0
- package/dist/esm/upload.js +39 -0
- package/package.json +57 -0
- package/src/client.ts +950 -0
- package/src/exceptions.ts +92 -0
- package/src/index.ts +20 -0
- package/src/progress.ts +147 -0
- package/src/sse.ts +61 -0
- package/src/transcript.ts +334 -0
- package/src/types.ts +114 -0
- package/src/upload.ts +50 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type OutputType = "txt" | "json" | "srt" | "vtt" | "docx" | "pdf";
|
|
2
|
+
export type ProcessingTier = "standard" | "economy";
|
|
3
|
+
export interface TranscribeOptions {
|
|
4
|
+
outputType?: OutputType;
|
|
5
|
+
wordTimestamps?: boolean;
|
|
6
|
+
speakerLabels?: boolean;
|
|
7
|
+
/** Alias for speakerLabels (ElevenLabs / Deepgram). */
|
|
8
|
+
diarize?: boolean;
|
|
9
|
+
nltk?: boolean;
|
|
10
|
+
/** Processing / pricing tier. Default: standard. */
|
|
11
|
+
tier?: ProcessingTier;
|
|
12
|
+
customVocabulary?: string[];
|
|
13
|
+
/** Webhook URL POSTed a signed completion/failure notification. */
|
|
14
|
+
callbackUrl?: string;
|
|
15
|
+
/** Callback fired for every transcription progress event (read `event.percent`). */
|
|
16
|
+
onProgress?: ProgressCallback;
|
|
17
|
+
/** Callback fired for byte-level upload progress (`event.step === "upload"`). */
|
|
18
|
+
onUploadProgress?: ProgressCallback;
|
|
19
|
+
/** Render live `Uploading` + `Transcribing` bars to stderr. Default: false. */
|
|
20
|
+
progress?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface UploadJob {
|
|
23
|
+
jobId: string;
|
|
24
|
+
uploadUrl: string;
|
|
25
|
+
downloadUrl: string;
|
|
26
|
+
contentType: string;
|
|
27
|
+
expiresIn: number;
|
|
28
|
+
}
|
|
29
|
+
export interface JobStatus {
|
|
30
|
+
jobId: string;
|
|
31
|
+
status: "processing" | "completed" | "failed" | string;
|
|
32
|
+
downloadUrl?: string;
|
|
33
|
+
failedStage?: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ProgressEvent {
|
|
37
|
+
completed?: number;
|
|
38
|
+
total?: number;
|
|
39
|
+
step?: string;
|
|
40
|
+
elapsedSeconds?: number;
|
|
41
|
+
raw?: Record<string, unknown>;
|
|
42
|
+
/** Completion as a 0–100 number, or `undefined` when the total is unknown. */
|
|
43
|
+
percent?: number;
|
|
44
|
+
}
|
|
45
|
+
export type ProgressCallback = (event: ProgressEvent) => void;
|
|
46
|
+
/** Completion as a 0–100 number clamped to [0, 100], or `undefined` if unknown. */
|
|
47
|
+
export declare function computePercent(completed?: number, total?: number): number | undefined;
|
|
48
|
+
/** Build a {@link ProgressEvent} with its `percent` derived from completed/total. */
|
|
49
|
+
export declare function makeProgressEvent(event: Omit<ProgressEvent, "percent">): ProgressEvent;
|
|
50
|
+
export interface STTClientOptions {
|
|
51
|
+
/** Defaults to SPEECHREVOLUTIONS_API_KEY or STT_API_KEY. */
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
baseUrl?: string;
|
|
54
|
+
/** Total seconds to wait for a job (default 600). */
|
|
55
|
+
timeout?: number;
|
|
56
|
+
fetch?: typeof fetch;
|
|
57
|
+
/** Retry attempts for transient JSON API failures (429/5xx/network). Default 3. */
|
|
58
|
+
maxRetries?: number;
|
|
59
|
+
/** Base backoff in ms; exponential and capped at 30s. Default 500. */
|
|
60
|
+
retryBackoffMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Extra `fetch` init merged into every request — the idiomatic proxy hook in
|
|
63
|
+
* Node: pass `{ dispatcher: new ProxyAgent(url) }` (from `undici`).
|
|
64
|
+
*/
|
|
65
|
+
requestInit?: RequestInit;
|
|
66
|
+
/**
|
|
67
|
+
* Prefer S3 multipart uploads and fall back to a single presigned PUT if the
|
|
68
|
+
* server has multipart disabled or a multipart upload fails mid-flight.
|
|
69
|
+
* Default true.
|
|
70
|
+
*/
|
|
71
|
+
multipart?: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare function resolveOptions(options?: TranscribeOptions): Required<Pick<TranscribeOptions, "outputType" | "wordTimestamps" | "speakerLabels" | "nltk" | "tier">> & Pick<TranscribeOptions, "customVocabulary" | "callbackUrl">;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Completion as a 0–100 number clamped to [0, 100], or `undefined` if unknown. */
|
|
2
|
+
export function computePercent(completed, total) {
|
|
3
|
+
if (completed === undefined || completed === null || !total)
|
|
4
|
+
return undefined;
|
|
5
|
+
return Math.max(0, Math.min(100, (completed / total) * 100));
|
|
6
|
+
}
|
|
7
|
+
/** Build a {@link ProgressEvent} with its `percent` derived from completed/total. */
|
|
8
|
+
export function makeProgressEvent(event) {
|
|
9
|
+
return { ...event, percent: computePercent(event.completed, event.total) };
|
|
10
|
+
}
|
|
11
|
+
export function resolveOptions(options = {}) {
|
|
12
|
+
const speakerLabels = options.diarize !== undefined
|
|
13
|
+
? options.diarize
|
|
14
|
+
: options.speakerLabels !== undefined
|
|
15
|
+
? options.speakerLabels
|
|
16
|
+
: true;
|
|
17
|
+
return {
|
|
18
|
+
outputType: options.outputType ?? "json",
|
|
19
|
+
wordTimestamps: options.wordTimestamps ?? true,
|
|
20
|
+
speakerLabels,
|
|
21
|
+
nltk: options.nltk ?? true,
|
|
22
|
+
tier: options.tier ?? "standard",
|
|
23
|
+
customVocabulary: options.customVocabulary,
|
|
24
|
+
callbackUrl: options.callbackUrl,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload-body helpers that report byte-level progress.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP client can only observe upload progress if it reads the body through
|
|
5
|
+
* something we control. For a presigned S3 PUT that's a byte-chunk async
|
|
6
|
+
* generator (`iterWithProgress`) paired with an explicit `Content-Length`
|
|
7
|
+
* header, which keeps S3 happy — undici (Node's fetch) would otherwise switch a
|
|
8
|
+
* streamed body to `Transfer-Encoding: chunked`, which presigned PUTs reject.
|
|
9
|
+
*/
|
|
10
|
+
import { type ProgressCallback } from "./types.js";
|
|
11
|
+
/** Callback receives (bytesSent, totalBytes). */
|
|
12
|
+
export type ByteProgressFn = (sent: number, total: number) => void;
|
|
13
|
+
export declare const UPLOAD_CHUNK_SIZE: number;
|
|
14
|
+
/**
|
|
15
|
+
* Adapt a {@link ProgressCallback} to a `(sent, total)` byte callback.
|
|
16
|
+
*
|
|
17
|
+
* Upload events are reported as `ProgressEvent(step="upload")` so they share the
|
|
18
|
+
* same shape (and `.percent`) as transcription progress.
|
|
19
|
+
*/
|
|
20
|
+
export declare function byteProgressAdapter(onProgress?: ProgressCallback): ByteProgressFn | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Yield `data` in chunks, reporting progress after each — used as the streamed
|
|
23
|
+
* PUT body. A fresh generator is created per upload attempt, so a retry simply
|
|
24
|
+
* restarts progress from 0.
|
|
25
|
+
*/
|
|
26
|
+
export declare function iterWithProgress(data: Uint8Array, callback?: ByteProgressFn): AsyncGenerator<Uint8Array>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload-body helpers that report byte-level progress.
|
|
3
|
+
*
|
|
4
|
+
* The HTTP client can only observe upload progress if it reads the body through
|
|
5
|
+
* something we control. For a presigned S3 PUT that's a byte-chunk async
|
|
6
|
+
* generator (`iterWithProgress`) paired with an explicit `Content-Length`
|
|
7
|
+
* header, which keeps S3 happy — undici (Node's fetch) would otherwise switch a
|
|
8
|
+
* streamed body to `Transfer-Encoding: chunked`, which presigned PUTs reject.
|
|
9
|
+
*/
|
|
10
|
+
import { makeProgressEvent } from "./types.js";
|
|
11
|
+
export const UPLOAD_CHUNK_SIZE = 64 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
* Adapt a {@link ProgressCallback} to a `(sent, total)` byte callback.
|
|
14
|
+
*
|
|
15
|
+
* Upload events are reported as `ProgressEvent(step="upload")` so they share the
|
|
16
|
+
* same shape (and `.percent`) as transcription progress.
|
|
17
|
+
*/
|
|
18
|
+
export function byteProgressAdapter(onProgress) {
|
|
19
|
+
if (!onProgress)
|
|
20
|
+
return undefined;
|
|
21
|
+
return (sent, total) => {
|
|
22
|
+
onProgress(makeProgressEvent({ completed: sent, total, step: "upload" }));
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Yield `data` in chunks, reporting progress after each — used as the streamed
|
|
27
|
+
* PUT body. A fresh generator is created per upload attempt, so a retry simply
|
|
28
|
+
* restarts progress from 0.
|
|
29
|
+
*/
|
|
30
|
+
export async function* iterWithProgress(data, callback) {
|
|
31
|
+
const total = data.byteLength;
|
|
32
|
+
let sent = 0;
|
|
33
|
+
for (let start = 0; start < total; start += UPLOAD_CHUNK_SIZE) {
|
|
34
|
+
const chunk = data.subarray(start, Math.min(start + UPLOAD_CHUNK_SIZE, total));
|
|
35
|
+
sent += chunk.byteLength;
|
|
36
|
+
yield chunk;
|
|
37
|
+
callback?.(sent, total);
|
|
38
|
+
}
|
|
39
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "speechrevolutions",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Official JavaScript/TypeScript SDK for the Speech Revolutions speech-to-text API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/cjs/index.js",
|
|
7
|
+
"module": "./dist/esm/index.js",
|
|
8
|
+
"types": "./dist/esm/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/esm/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
13
|
+
"require": "./dist/cjs/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs && node scripts/fixup-dist.mjs",
|
|
23
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
24
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
25
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
26
|
+
"prepare": "npm run build",
|
|
27
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
28
|
+
"test:only": "node --test test/*.test.mjs"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"speech-to-text",
|
|
35
|
+
"stt",
|
|
36
|
+
"transcription",
|
|
37
|
+
"whisper",
|
|
38
|
+
"asr"
|
|
39
|
+
],
|
|
40
|
+
"author": "Speech Revolutions",
|
|
41
|
+
"homepage": "https://speechrevolutions.com",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/SpeechRevolutions/node-sdk.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/SpeechRevolutions/node-sdk/issues"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^20.11.0",
|
|
55
|
+
"typescript": "^5.3.0"
|
|
56
|
+
}
|
|
57
|
+
}
|