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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Speech Revolutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Speech Revolutions — JavaScript / TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official JS/TS client for the Speech Revolutions STT API. Works in Node 18+
|
|
4
|
+
(native `fetch`). Async-first, like Deepgram / ElevenLabs JS.
|
|
5
|
+
|
|
6
|
+
Written in TypeScript, published as both CommonJS and ESM, so it works from
|
|
7
|
+
plain JavaScript (`require`), ESM (`import`), and TypeScript alike — with full
|
|
8
|
+
type definitions either way.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install speechrevolutions
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// CommonJS
|
|
18
|
+
const { SpeechRevolutions } = require("speechrevolutions");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// ESM / TypeScript
|
|
23
|
+
import { SpeechRevolutions } from "speechrevolutions";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { SpeechRevolutions } from "speechrevolutions";
|
|
30
|
+
|
|
31
|
+
const client = new SpeechRevolutions(); // SPEECHREVOLUTIONS_API_KEY or STT_API_KEY
|
|
32
|
+
const result = await client.transcribe("meeting.mp3", { speakerLabels: true });
|
|
33
|
+
|
|
34
|
+
console.log(result.text);
|
|
35
|
+
for (const u of result.utterances) {
|
|
36
|
+
console.log(`Speaker ${u.speaker}: ${u.text}`);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### From a URL (Deepgram-style)
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const result = await client.transcribeUrl("https://example.com/audio.mp3");
|
|
44
|
+
// or
|
|
45
|
+
const result = await client.transcribe("https://example.com/audio.mp3");
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The platform fetches the URL itself — the audio never passes through your
|
|
49
|
+
process.
|
|
50
|
+
|
|
51
|
+
### Options as an object
|
|
52
|
+
|
|
53
|
+
Pass options as the second argument. `diarize` is an alias for `speakerLabels`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
await client.transcribe("a.mp3", {
|
|
57
|
+
diarize: true, // alias for speakerLabels
|
|
58
|
+
outputType: "json",
|
|
59
|
+
wordTimestamps: true,
|
|
60
|
+
customVocabulary: ["AcmeCorp"],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Option | Type | Default |
|
|
65
|
+
|--------|------|---------|
|
|
66
|
+
| `outputType` | `"txt" \| "json" \| "srt" \| "vtt" \| "docx" \| "pdf"` | `"json"` |
|
|
67
|
+
| `wordTimestamps` | `boolean` | `true` |
|
|
68
|
+
| `speakerLabels` | `boolean` | `true` |
|
|
69
|
+
| `diarize` | `boolean` (alias for `speakerLabels`) | — |
|
|
70
|
+
| `nltk` | `boolean` (punctuation & capitalization) | `true` |
|
|
71
|
+
| `tier` | `"standard" \| "economy"` | `"standard"` |
|
|
72
|
+
| `customVocabulary` | `string[]` | `undefined` |
|
|
73
|
+
| `onProgress` | `(event: ProgressEvent) => void` | `undefined` |
|
|
74
|
+
| `onUploadProgress` | `(event: ProgressEvent) => void` | `undefined` |
|
|
75
|
+
| `progress` | `boolean` (render console bars) | `false` |
|
|
76
|
+
|
|
77
|
+
## Live progress
|
|
78
|
+
|
|
79
|
+
Unlike AssemblyAI/Deepgram (which give no percentage for pre-recorded audio),
|
|
80
|
+
you get real-time progress — for **both** the file upload and the transcription
|
|
81
|
+
— as a console bar, a callback, or both.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// 1. Console bars — an "Uploading" byte bar, then a "Transcribing" bar,
|
|
85
|
+
// rendered to stderr on a single carriage-return-updated line.
|
|
86
|
+
await client.transcribe("meeting.mp3", { progress: true });
|
|
87
|
+
|
|
88
|
+
// 2. Programmatic — read event.percent (0–100) to drive your own UI / API.
|
|
89
|
+
await client.transcribe("meeting.mp3", {
|
|
90
|
+
onProgress(event) {
|
|
91
|
+
// transcription: event.step is e.g. "transcribe", event.percent is 0–100
|
|
92
|
+
console.log(event.percent, event.step);
|
|
93
|
+
},
|
|
94
|
+
onUploadProgress(event) {
|
|
95
|
+
// upload: event.step === "upload", event.completed / event.total are bytes
|
|
96
|
+
console.log("upload", event.percent);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`progress: true` and the callbacks compose — the bars render *and* your
|
|
102
|
+
callbacks still fire for every event. `event.percent` is a `0–100` number,
|
|
103
|
+
`undefined` when the total is not yet known.
|
|
104
|
+
|
|
105
|
+
The upload is streamed in chunks with an explicit `Content-Length` (so presigned
|
|
106
|
+
S3 PUTs never see `Transfer-Encoding: chunked`), and progress is reported after
|
|
107
|
+
each chunk.
|
|
108
|
+
|
|
109
|
+
## Result shape
|
|
110
|
+
|
|
111
|
+
Default `outputType` is `json`. The SDK parses it into a transcript-first object:
|
|
112
|
+
|
|
113
|
+
| Field | Like |
|
|
114
|
+
|-------|------|
|
|
115
|
+
| `result.text` | AssemblyAI / ElevenLabs |
|
|
116
|
+
| `result.transcript` | Deepgram alias |
|
|
117
|
+
| `result.words` | word + start/end/speaker |
|
|
118
|
+
| `result.utterances` | AssemblyAI speaker turns |
|
|
119
|
+
| `result.toDeepgram()` | Deepgram-shaped object |
|
|
120
|
+
| `result.toDict()` | normalized JSON |
|
|
121
|
+
| `result.content` / `result.save()` | raw bytes / file |
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const dg = result.toDeepgram();
|
|
125
|
+
console.log(dg.results.channels[0].alternatives[0].transcript);
|
|
126
|
+
|
|
127
|
+
// Save raw content to disk. Appends the output type if the path has no
|
|
128
|
+
// extension, e.g. "output" -> "output.json". Returns the written path.
|
|
129
|
+
const path = await result.save("output");
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Webhooks & retrieving results later
|
|
133
|
+
|
|
134
|
+
`submit()` uploads and enqueues a job and returns its id **without waiting** —
|
|
135
|
+
ideal for batch/background work. Collect the result later via a webhook
|
|
136
|
+
(`callbackUrl`, a signed POST — verify `X-SR-Signature: sha256=…` against the raw
|
|
137
|
+
bytes) or by polling:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const jobId = await client.submit("meeting.mp3"); // returns immediately, no waiting
|
|
141
|
+
// ...or notify a webhook instead of polling:
|
|
142
|
+
await client.transcribe("meeting.mp3", { callbackUrl: "https://you.example.com/hook" });
|
|
143
|
+
|
|
144
|
+
const status = await client.getJobStatus(jobId); // .status: processing|completed|failed
|
|
145
|
+
if (status.status === "completed") {
|
|
146
|
+
const result = await client.getTranscript(jobId); // downloads + parses
|
|
147
|
+
}
|
|
148
|
+
const page = await client.listJobs({ limit: 50 }); // { jobs, nextBefore }
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Robustness
|
|
152
|
+
|
|
153
|
+
`new SpeechRevolutions({ maxRetries: 3, retryBackoffMs: 500, requestInit: { dispatcher } })`.
|
|
154
|
+
Transient 429/5xx/network errors are retried (honoring `Retry-After`). Errors are
|
|
155
|
+
typed and carry `.statusCode` and `.requestId`.
|
|
156
|
+
|
|
157
|
+
## Timeouts and retries
|
|
158
|
+
|
|
159
|
+
API requests that fail to connect or return 429/500/502/503/504 are retried with
|
|
160
|
+
exponential backoff, honoring `Retry-After`. Uploads and the progress stream
|
|
161
|
+
have their own retry loops.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const client = new STTClient({
|
|
165
|
+
timeout: 600, // whole-job wait in seconds (SSE + polling)
|
|
166
|
+
maxRetries: 3, // extra attempts per API request
|
|
167
|
+
retryBackoffMs: 500,
|
|
168
|
+
requestInit: { signal: controller.signal }, // aborts propagate as AbortError
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Errors carry `statusCode`, `requestId` and `body` where the server supplied
|
|
173
|
+
them; `RateLimitError.retryAfter` holds the server's hint in seconds.
|
|
174
|
+
|
|
175
|
+
## Auth
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
export SPEECHREVOLUTIONS_API_KEY=stt_...
|
|
179
|
+
# or
|
|
180
|
+
export STT_API_KEY=stt_...
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Or `new SpeechRevolutions({ apiKey: "stt_..." })` / `new SpeechRevolutions("stt_...")`.
|