Skip to content

Commit 1372b4b

Browse files
authored
Merge pull request #91 from AssemblyAI/DAF0BAB42D2DA65E0EFFC2912E49A516
Sync from internal repo (2025-06-05)
2 parents f831402 + a13938d commit 1372b4b

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<img src="https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/assemblyai.png?raw=true" width="500"/>
22

3-
---
3+
______________________________________________________________________
44

55
[![npm](https://img.shields.io/npm/v/assemblyai)](https://www.npmjs.com/package/assemblyai)
66
[![Test](https://github.com/AssemblyAI/assemblyai-node-sdk/actions/workflows/test.yml/badge.svg)](https://github.com/AssemblyAI/assemblyai-node-sdk/actions/workflows/test.yml)
@@ -13,7 +13,7 @@
1313
# AssemblyAI JavaScript SDK
1414

1515
The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API,
16-
which supports async and real-time transcription, as well as the latest LeMUR models.
16+
which supports async and streaming transcription, as well as the latest LeMUR models.
1717
It is written primarily for Node.js in TypeScript with all types exported, but also [compatible with other runtimes](./docs/compat.md).
1818

1919
## Documentation
@@ -73,11 +73,11 @@ You can use automatic CDNs like [UNPKG](https://unpkg.com/) to load the library
7373
```
7474

7575
The script creates a global `assemblyai` variable containing all the services.
76-
Here's how you create a `RealtimeTranscriber` object.
76+
Here's how you create a `StreamingTranscriber` object.
7777

7878
```js
79-
const { RealtimeTranscriber } = assemblyai;
80-
const transcriber = new RealtimeTranscriber({
79+
const { StreamingTranscriber } = assemblyai;
80+
const transcriber = new StreamingTranscriber({
8181
token: "[GENERATE TEMPORARY AUTH TOKEN IN YOUR API]",
8282
...
8383
});
@@ -101,7 +101,7 @@ let transcript = await client.transcripts.transcribe({
101101
});
102102
```
103103

104-
> **Note**
104+
> [!NOTE]
105105
> You can also pass a local file path, a stream, or a buffer as the `audio` property.
106106
107107
`transcribe` queues a transcription job and polls it until the `status` is `completed` or `error`.
@@ -242,20 +242,18 @@ const res = await client.transcripts.delete(transcript.id);
242242

243243
### Transcribe in real-time
244244

245-
Create the real-time transcriber.
245+
Create the streaming transcriber.
246246

247247
```typescript
248-
const rt = client.realtime.transcriber();
248+
const rt = client.streaming.transcriber();
249249
```
250250

251251
You can also pass in the following options.
252252

253253
```typescript
254-
const rt = client.realtime.transcriber({
255-
realtimeUrl: 'wss://localhost/override',
254+
const rt = client.streaming.transcriber({
256255
apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
257256
sampleRate: 16_000,
258-
wordBoost: ['foo', 'bar']
259257
});
260258
```
261259

@@ -265,30 +263,29 @@ const rt = client.realtime.transcriber({
265263
> _Server code_:
266264
>
267265
> ```typescript
268-
> const token = await client.realtime.createTemporaryToken({ expires_in = 60 });
266+
> const token = await client.streaming.createTemporaryToken({ expires_in_seconds = 60 });
269267
> // TODO: return token to client
270268
> ```
271269
>
272270
> _Client code_:
273271
>
274272
> ```typescript
275-
> import { RealtimeTranscriber } from "assemblyai"; // or "assemblyai/streaming"
273+
> import { StreamingTranscriber } from "assemblyai";
276274
> // TODO: implement getToken to retrieve token from server
277275
> const token = await getToken();
278-
> const rt = new RealtimeTranscriber({
276+
> const rt = new StreamingTranscriber({
279277
> token,
280278
> });
281279
> ```
282280
283281
You can configure the following events.
284282
285283
<!-- prettier-ignore -->
284+
286285
```typescript
287-
rt.on("open", ({ sessionId, expiresAt }) => console.log('Session ID:', sessionId, 'Expires at:', expiresAt));
286+
rt.on("open", ({ id, expires_at }) => console.log('Session ID:', id, 'Expires at:', expires_at));
288287
rt.on("close", (code: number, reason: string) => console.log('Closed', code, reason));
289-
rt.on("transcript", (transcript: TranscriptMessage) => console.log('Transcript:', transcript));
290-
rt.on("transcript.partial", (transcript: PartialTranscriptMessage) => console.log('Partial transcript:', transcript));
291-
rt.on("transcript.final", (transcript: FinalTranscriptMessage) => console.log('Final transcript:', transcript));
288+
rt.on("turn", ({ transcript }) => console.log('Transcript:', transcript));
292289
rt.on("error", (error: Error) => console.error('Error', error));
293290
```
294291
@@ -307,7 +304,7 @@ getAudio((chunk) => {
307304
});
308305
```
309306

310-
Or send audio data via a stream by piping to the real-time stream.
307+
Or send audio data via a stream:
311308

312309
```typescript
313310
audioStream.pipeTo(rt.stream());

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "assemblyai",
3-
"version": "4.13.1",
3+
"version": "4.13.2",
44
"description": "The AssemblyAI JavaScript SDK provides an easy-to-use interface for interacting with the AssemblyAI API, which supports async and real-time transcription, as well as the latest LeMUR models.",
55
"engines": {
66
"node": ">=18"

src/services/streaming/service.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
factory as polyfillWebSocketFactory,
55
} from "#websocket";
66
import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
7+
import { conditions } from "#conditions";
78
import {
89
StreamingEvents,
910
StreamingListeners,
@@ -69,6 +70,10 @@ export class StreamingTranscriber {
6970

7071
const searchParams = new URLSearchParams();
7172

73+
if (this.token) {
74+
searchParams.set("token", this.token);
75+
}
76+
7277
searchParams.set("sample_rate", this.params.sampleRate.toString());
7378

7479
if (this.params.endOfTurnConfidenceThreshold) {
@@ -118,9 +123,20 @@ export class StreamingTranscriber {
118123

119124
const url = this.connectionUrl();
120125

121-
this.socket = polyfillWebSocketFactory(url.toString(), {
122-
headers: { Authorization: this.token || this.apiKey },
123-
});
126+
if (this.token) {
127+
this.socket = polyfillWebSocketFactory(url.toString());
128+
} else {
129+
if (conditions.browser) {
130+
console.warn(
131+
`API key authentication is not supported for the StreamingTranscriber in browser environment. Use temporary token authentication instead.
132+
Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/compat.md#browser-compatibility.`,
133+
);
134+
}
135+
136+
this.socket = polyfillWebSocketFactory(url.toString(), {
137+
headers: { Authorization: this.apiKey },
138+
});
139+
}
124140

125141
this.socket.binaryType = "arraybuffer";
126142

0 commit comments

Comments
 (0)