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 )
1313# AssemblyAI JavaScript SDK
1414
1515The 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.
1717It 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
7575The 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
251251You 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
283281You 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 ));
288287rt .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 ));
292289rt .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
313310audioStream .pipeTo (rt .stream ());
0 commit comments