assemblyai 2.0.2-beta → 2.0.2

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 CHANGED
@@ -10,7 +10,6 @@
10
10
  [![Discord](https://img.shields.io/discord/875120158014853141?logo=discord&label=Discord&link=https%3A%2F%2Fdiscord.com%2Fchannels%2F875120158014853141&style=social)
11
11
  ](https://discord.gg/5aQNZyq3)
12
12
 
13
-
14
13
  # AssemblyAI Node.js SDK
15
14
 
16
15
  The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API,
@@ -165,13 +164,13 @@ const { response } = await client.lemur.task({
165
164
  Create the real-time service.
166
165
 
167
166
  ```typescript
168
- const service = client.realtime.createService();
167
+ const rt = client.realtime.createService();
169
168
  ```
170
169
 
171
170
  You can also pass in the following options.
172
171
 
173
172
  ```typescript
174
- const service = client.realtime.createService({
173
+ const rt = client.realtime.createService({
175
174
  realtimeUrl: 'wss://localhost/override',
176
175
  apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
177
176
  sampleRate: 16_000,
@@ -209,7 +208,7 @@ After configuring your events, connect to the server.
209
208
  await rt.connect();
210
209
  ```
211
210
 
212
- Send audio data.
211
+ Send audio data via chunks.
213
212
 
214
213
  ```typescript
215
214
  // Pseudo code for getting audio
@@ -217,6 +216,11 @@ getAudio((chunk) => {
217
216
  rt.sendAudio(chunk);
218
217
  });
219
218
  ```
219
+ Or send audio data via a stream by piping to the realtime stream.
220
+
221
+ ```typescript
222
+ audioStream.pipe(rt.stream());
223
+ ```
220
224
 
221
225
  Close the connection when you're finished.
222
226
 
package/dist/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import axios, { isAxiosError } from 'axios';
2
2
  import WebSocket from 'ws';
3
+ import { Writable } from 'stream';
3
4
  import { readFile } from 'fs/promises';
4
5
 
5
6
  function createAxiosClient(params) {
@@ -88,6 +89,16 @@ class LemurService extends BaseService {
88
89
  return data;
89
90
  });
90
91
  }
92
+ /**
93
+ * Delete the data for a previously submitted LeMUR request.
94
+ * @param id ID of the LeMUR request
95
+ */
96
+ purgeRequestData(id) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const { data } = yield this.client.delete(`/lemur/v3/${id}`);
99
+ return data;
100
+ });
101
+ }
91
102
  }
92
103
 
93
104
  var RealtimeErrorType;
@@ -246,6 +257,15 @@ class RealtimeService {
246
257
  };
247
258
  this.socket.send(JSON.stringify(payload));
248
259
  }
260
+ stream() {
261
+ const stream = new Writable({
262
+ write: (chunk, encoding, next) => {
263
+ this.sendAudio(chunk);
264
+ next();
265
+ },
266
+ });
267
+ return stream;
268
+ }
249
269
  close(waitForSessionTermination = true) {
250
270
  return __awaiter(this, void 0, void 0, function* () {
251
271
  if (this.socket) {
@@ -378,6 +398,23 @@ class TranscriptService extends BaseService {
378
398
  return res.data;
379
399
  });
380
400
  }
401
+ /**
402
+ * Search through the transcript for a specific set of keywords.
403
+ * You can search for individual words, numbers, or phrases containing up to five words or numbers.
404
+ * @param id The identifier of the transcript.
405
+ * @param id Keywords to search for.
406
+ * @return A promise that resolves to the sentences.
407
+ */
408
+ wordSearch(id, words) {
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
411
+ params: {
412
+ words: JSON.stringify(words),
413
+ },
414
+ });
415
+ return data;
416
+ });
417
+ }
381
418
  /**
382
419
  * Retrieve all sentences of a transcript.
383
420
  * @param id The identifier of the transcript.
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var axios = require('axios');
6
6
  var WebSocket = require('ws');
7
+ var stream = require('stream');
7
8
  var promises = require('fs/promises');
8
9
 
9
10
  function createAxiosClient(params) {
@@ -92,6 +93,16 @@ class LemurService extends BaseService {
92
93
  return data;
93
94
  });
94
95
  }
96
+ /**
97
+ * Delete the data for a previously submitted LeMUR request.
98
+ * @param id ID of the LeMUR request
99
+ */
100
+ purgeRequestData(id) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const { data } = yield this.client.delete(`/lemur/v3/${id}`);
103
+ return data;
104
+ });
105
+ }
95
106
  }
96
107
 
97
108
  var RealtimeErrorType;
@@ -250,6 +261,15 @@ class RealtimeService {
250
261
  };
251
262
  this.socket.send(JSON.stringify(payload));
252
263
  }
264
+ stream() {
265
+ const stream$1 = new stream.Writable({
266
+ write: (chunk, encoding, next) => {
267
+ this.sendAudio(chunk);
268
+ next();
269
+ },
270
+ });
271
+ return stream$1;
272
+ }
253
273
  close(waitForSessionTermination = true) {
254
274
  return __awaiter(this, void 0, void 0, function* () {
255
275
  if (this.socket) {
@@ -382,6 +402,23 @@ class TranscriptService extends BaseService {
382
402
  return res.data;
383
403
  });
384
404
  }
405
+ /**
406
+ * Search through the transcript for a specific set of keywords.
407
+ * You can search for individual words, numbers, or phrases containing up to five words or numbers.
408
+ * @param id The identifier of the transcript.
409
+ * @param id Keywords to search for.
410
+ * @return A promise that resolves to the sentences.
411
+ */
412
+ wordSearch(id, words) {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ const { data } = yield this.client.get(`/v2/transcript/${id}/word-search`, {
415
+ params: {
416
+ words: JSON.stringify(words),
417
+ },
418
+ });
419
+ return data;
420
+ });
421
+ }
385
422
  /**
386
423
  * Retrieve all sentences of a transcript.
387
424
  * @param id The identifier of the transcript.
@@ -1,8 +1,13 @@
1
- import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse } from "@/types";
1
+ import { LemurSummaryParameters, LemurActionItemsParameters, LemurQuestionAnswerParameters, LemurTaskParameters, LemurSummaryResponse, LemurQuestionAnswerResponse, LemurActionItemsResponse, LemurTaskResponse, PurgeLemurRequestDataResponse } from "@/types";
2
2
  import { BaseService } from "@/services/base";
3
3
  export declare class LemurService extends BaseService {
4
4
  summary(params: LemurSummaryParameters): Promise<LemurSummaryResponse>;
5
5
  questionAnswer(params: LemurQuestionAnswerParameters): Promise<LemurQuestionAnswerResponse>;
6
6
  actionItems(params: LemurActionItemsParameters): Promise<LemurActionItemsResponse>;
7
7
  task(params: LemurTaskParameters): Promise<LemurTaskResponse>;
8
+ /**
9
+ * Delete the data for a previously submitted LeMUR request.
10
+ * @param id ID of the LeMUR request
11
+ */
12
+ purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse>;
8
13
  }
@@ -1,4 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import { RealtimeServiceParams, RealtimeTranscript, PartialTranscript, FinalTranscript, SessionBeginsEventData } from "@/types";
3
+ import { Writable } from "stream";
2
4
  export declare class RealtimeService {
3
5
  private realtimeUrl;
4
6
  private sampleRate;
@@ -18,5 +20,6 @@ export declare class RealtimeService {
18
20
  on(event: "close", listener: (code: number, reason: string) => void): void;
19
21
  connect(): Promise<SessionBeginsEventData>;
20
22
  sendAudio(audio: ArrayBuffer): void;
23
+ stream(): Writable;
21
24
  close(waitForSessionTermination?: boolean): Promise<void>;
22
25
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseService } from "@/services/base";
2
- import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse } from "@/types";
2
+ import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, WordSearchResponse } from "@/types";
3
3
  import { AxiosInstance } from "axios";
4
4
  import { FileService } from "../files";
5
5
  export declare class TranscriptService extends BaseService implements Createable<Transcript, CreateTranscriptParameters, CreateTranscriptOptions>, Retrieveable<Transcript>, Deletable<Transcript>, Listable<TranscriptList> {
@@ -31,6 +31,14 @@ export declare class TranscriptService extends BaseService implements Createable
31
31
  * @returns A promise that resolves to the transcript.
32
32
  */
33
33
  delete(id: string): Promise<Transcript>;
34
+ /**
35
+ * Search through the transcript for a specific set of keywords.
36
+ * You can search for individual words, numbers, or phrases containing up to five words or numbers.
37
+ * @param id The identifier of the transcript.
38
+ * @param id Keywords to search for.
39
+ * @return A promise that resolves to the sentences.
40
+ */
41
+ wordSearch(id: string, words: string[]): Promise<WordSearchResponse>;
34
42
  /**
35
43
  * Retrieve all sentences of a transcript.
36
44
  * @param id The identifier of the transcript.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "2.0.2-beta",
3
+ "version": "2.0.2",
4
4
  "description": "The AssemblyAI Node.js 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.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -11,7 +11,7 @@
11
11
  "url": "git+https://github.com/AssemblyAI/assemblyai-node-sdk.git"
12
12
  },
13
13
  "publishConfig": {
14
- "tag": "beta",
14
+ "tag": "latest",
15
15
  "access": "public",
16
16
  "registry": "https://registry.npmjs.org/"
17
17
  },
@@ -7,6 +7,7 @@ import {
7
7
  LemurQuestionAnswerResponse,
8
8
  LemurActionItemsResponse,
9
9
  LemurTaskResponse,
10
+ PurgeLemurRequestDataResponse,
10
11
  } from "@/types";
11
12
  import { BaseService } from "@/services/base";
12
13
 
@@ -46,4 +47,15 @@ export class LemurService extends BaseService {
46
47
  );
47
48
  return data;
48
49
  }
50
+
51
+ /**
52
+ * Delete the data for a previously submitted LeMUR request.
53
+ * @param id ID of the LeMUR request
54
+ */
55
+ async purgeRequestData(id: string): Promise<PurgeLemurRequestDataResponse> {
56
+ const { data } = await this.client.delete<PurgeLemurRequestDataResponse>(
57
+ `/lemur/v3/${id}`
58
+ );
59
+ return data;
60
+ }
49
61
  }
@@ -14,6 +14,7 @@ import {
14
14
  RealtimeErrorMessages,
15
15
  RealtimeErrorType,
16
16
  } from "@/utils/errors";
17
+ import { Writable } from "stream";
17
18
 
18
19
  const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
19
20
 
@@ -161,6 +162,16 @@ export class RealtimeService {
161
162
  this.socket.send(JSON.stringify(payload));
162
163
  }
163
164
 
165
+ stream(): Writable {
166
+ const stream = new Writable({
167
+ write: (chunk: Buffer, encoding, next) => {
168
+ this.sendAudio(chunk);
169
+ next();
170
+ },
171
+ });
172
+ return stream;
173
+ }
174
+
164
175
  async close(waitForSessionTermination = true) {
165
176
  if (this.socket) {
166
177
  if (this.socket.readyState === WebSocket.OPEN) {
@@ -12,6 +12,7 @@ import {
12
12
  Retrieveable,
13
13
  SubtitleFormat,
14
14
  RedactedAudioResponse,
15
+ WordSearchResponse,
15
16
  } from "@/types";
16
17
  import { AxiosInstance } from "axios";
17
18
  import { FileService } from "../files";
@@ -116,6 +117,25 @@ export class TranscriptService
116
117
  return res.data;
117
118
  }
118
119
 
120
+ /**
121
+ * Search through the transcript for a specific set of keywords.
122
+ * You can search for individual words, numbers, or phrases containing up to five words or numbers.
123
+ * @param id The identifier of the transcript.
124
+ * @param id Keywords to search for.
125
+ * @return A promise that resolves to the sentences.
126
+ */
127
+ async wordSearch(id: string, words: string[]): Promise<WordSearchResponse> {
128
+ const { data } = await this.client.get<WordSearchResponse>(
129
+ `/v2/transcript/${id}/word-search`,
130
+ {
131
+ params: {
132
+ words: JSON.stringify(words),
133
+ },
134
+ }
135
+ );
136
+ return data;
137
+ }
138
+
119
139
  /**
120
140
  * Retrieve all sentences of a transcript.
121
141
  * @param id The identifier of the transcript.