@speechweave/node 1.0.3 → 1.0.4
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 +38 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,19 +24,46 @@ export SPEECHWEAVE_API_KEY="sk_..."
|
|
|
24
24
|
```ts
|
|
25
25
|
import { SpeechWeave, waitForJob } from "@speechweave/node";
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const sw = new SpeechWeave({ api_key: process.env.SPEECHWEAVE_API_KEY! });
|
|
28
28
|
|
|
29
|
-
const job = await
|
|
29
|
+
const job = await sw.jobs.create({
|
|
30
|
+
file: "./podcast.mp3",
|
|
31
|
+
model: "core",
|
|
32
|
+
service_mode: "deferred",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const done = await waitForJob(sw, job.id);
|
|
36
|
+
console.log(done.transcript);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`jobs.create` accepts a local path string, `Buffer`, `Blob`, or `ReadStream`. For URL input, cancel, and other job operations, see the [API reference](https://speechweave.com/docs/api).
|
|
40
|
+
|
|
41
|
+
## Handling buffers & streams
|
|
42
|
+
|
|
43
|
+
When audio is already in memory or you are piping a stream, use `transcribeFile` directly:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { createReadStream } from "node:fs";
|
|
47
|
+
import { SpeechWeave, waitForJob } from "@speechweave/node";
|
|
48
|
+
|
|
49
|
+
const sw = new SpeechWeave();
|
|
50
|
+
|
|
51
|
+
// In-memory buffer
|
|
52
|
+
const fromBuffer = await sw.transcribeFile(buffer, {
|
|
30
53
|
filename: "audio.wav",
|
|
31
54
|
model: "core",
|
|
32
55
|
language: "en",
|
|
33
56
|
});
|
|
34
57
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
// Stream from disk or a pipe
|
|
59
|
+
const fromStream = await sw.transcribeFile(createReadStream("./podcast.mp3"), {
|
|
60
|
+
filename: "podcast.mp3",
|
|
61
|
+
model: "core",
|
|
62
|
+
});
|
|
38
63
|
|
|
39
|
-
|
|
64
|
+
const done = await waitForJob(sw, fromBuffer.id, { timeout_ms: 300_000 });
|
|
65
|
+
console.log(done.transcript);
|
|
66
|
+
```
|
|
40
67
|
|
|
41
68
|
## Webhooks
|
|
42
69
|
|
|
@@ -64,6 +91,11 @@ try {
|
|
|
64
91
|
if (e instanceof SpeechWeaveError) {
|
|
65
92
|
console.log(e.status);
|
|
66
93
|
console.log(e.code);
|
|
94
|
+
// Prepaid wallet / spend caps: HTTP 402 with codes like INSUFFICIENT_BALANCE,
|
|
95
|
+
// WALLET_EMPTY, SPEND_CAP_REACHED, CHECKOUT_REQUIRED.
|
|
96
|
+
if (e.status === 402) {
|
|
97
|
+
console.log("Top up the wallet or raise spend caps, then retry.");
|
|
98
|
+
}
|
|
67
99
|
}
|
|
68
100
|
}
|
|
69
101
|
```
|