@speechweave/node 1.0.1 → 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.
Files changed (2) hide show
  1. package/README.md +77 -45
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -24,25 +24,93 @@ export SPEECHWEAVE_API_KEY="sk_..."
24
24
  ```ts
25
25
  import { SpeechWeave, waitForJob } from "@speechweave/node";
26
26
 
27
- const client = new SpeechWeave();
27
+ const sw = new SpeechWeave({ api_key: process.env.SPEECHWEAVE_API_KEY! });
28
28
 
29
- const job = await client.transcribeFile(buffer, {
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
- const result = await waitForJob(client, job.id, { timeout_ms: 300_000 });
36
- console.log(result.transcript);
58
+ // Stream from disk or a pipe
59
+ const fromStream = await sw.transcribeFile(createReadStream("./podcast.mp3"), {
60
+ filename: "podcast.mp3",
61
+ model: "core",
62
+ });
63
+
64
+ const done = await waitForJob(sw, fromBuffer.id, { timeout_ms: 300_000 });
65
+ console.log(done.transcript);
66
+ ```
67
+
68
+ ## Webhooks
69
+
70
+ ```ts
71
+ import { verifyWebhook } from "@speechweave/node";
72
+
73
+ const result = verifyWebhook(
74
+ WEBHOOK_SECRET,
75
+ rawBody,
76
+ signatureHeader,
77
+ );
78
+ ```
79
+
80
+ Configure webhooks in the dashboard. Payloads are signed with `SpeechWeave-Signature`.
81
+
82
+ ## Errors
83
+
84
+ ```ts
85
+ import { SpeechWeave, SpeechWeaveError } from "@speechweave/node";
86
+
87
+ try {
88
+ const client = new SpeechWeave({ api_key: "bad_key" });
89
+ await client.getJob("job_123");
90
+ } catch (e) {
91
+ if (e instanceof SpeechWeaveError) {
92
+ console.log(e.status);
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
+ }
99
+ }
100
+ }
37
101
  ```
38
102
 
39
- For `jobs.create`, URL input, cancel, and other job operations, see the [API reference](https://speechweave.com/docs/api).
103
+ ## Configuration
40
104
 
41
- ## When to use SpeechWeave
105
+ - `api_key` or set `SPEECHWEAVE_API_KEY`
106
+ - `base_url` — defaults to `https://api.speechweave.com/v1`
107
+ - `fetch_func` — optional custom `fetch` implementation
42
108
 
43
- Use this SDK when you want the native jobs API, presigned uploads for large files, `waitForJob`, and webhook verification.
109
+ ## Compatibility & Migration
44
110
 
45
- ## Drop-in usage
111
+ If you are building a new application, use the native SDK above for full feature support. If you have an existing OpenAI, Deepgram, or AssemblyAI codebase, use the options below to switch with minimal changes.
112
+
113
+ ### Drop-in usage
46
114
 
47
115
  Convenience helpers if you want OpenAI/Deepgram/AssemblyAI response shapes without adding another package. They use presigned uploads like the native API.
48
116
 
@@ -58,7 +126,7 @@ Pass `wait: false` to return the created job without polling.
58
126
 
59
127
  More examples: [OpenAI](https://speechweave.com/docs/migration/openai) · [Deepgram](https://speechweave.com/docs/migration/deepgram) · [AssemblyAI](https://speechweave.com/docs/migration/assemblyai)
60
128
 
61
- ## Migrating from OpenAI
129
+ ### Migrating from OpenAI
62
130
 
63
131
  You don't need this SDK for a quick swap — use the official `openai` package and point it at SpeechWeave:
64
132
 
@@ -80,39 +148,3 @@ console.log(result.text);
80
148
  ```
81
149
 
82
150
  OpenAI model names like `whisper-1` are aliased to `core` on our backend. See the [OpenAI migration guide](https://speechweave.com/docs/migration/openai).
83
-
84
- ## Configuration
85
-
86
- - `api_key` — or set `SPEECHWEAVE_API_KEY`
87
- - `base_url` — defaults to `https://api.speechweave.com/v1`
88
- - `fetch_func` — optional custom `fetch` implementation
89
-
90
- ## Errors
91
-
92
- ```ts
93
- import { SpeechWeave, SpeechWeaveError } from "@speechweave/node";
94
-
95
- try {
96
- const client = new SpeechWeave({ api_key: "bad_key" });
97
- await client.getJob("job_123");
98
- } catch (e) {
99
- if (e instanceof SpeechWeaveError) {
100
- console.log(e.status);
101
- console.log(e.code);
102
- }
103
- }
104
- ```
105
-
106
- ## Webhooks
107
-
108
- ```ts
109
- import { verifyWebhook } from "@speechweave/node";
110
-
111
- const result = verifyWebhook(
112
- WEBHOOK_SECRET,
113
- rawBody,
114
- signatureHeader,
115
- );
116
- ```
117
-
118
- Configure webhooks in the dashboard. Payloads are signed with `SpeechWeave-Signature`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speechweave/node",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "Official SpeechWeave Node.js SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",