assemblyai 2.0.2 → 3.0.0

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
@@ -40,7 +40,7 @@ bun add assemblyai
40
40
  Import the AssemblyAI package and create an AssemblyAI object with your API key:
41
41
 
42
42
  ```javascript
43
- import AssemblyAI from "assemblyai";
43
+ import { AssemblyAI } from "assemblyai";
44
44
 
45
45
  const client = new AssemblyAI({
46
46
  apiKey: process.env.ASSEMBLYAI_API_KEY,
@@ -94,7 +94,7 @@ const transcript = await client.transcripts.get(transcript.id)
94
94
 
95
95
  ## List transcripts
96
96
 
97
- This will return a paged list of transcripts that you have transcript.
97
+ This will return a page of transcripts that you have transcript.
98
98
 
99
99
  ```javascript
100
100
  const page = await client.transcripts.list()
package/dist/index.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- import { AssemblyAI } from "./services";
2
- export * from "./services";
3
1
  export type * from "./types";
4
- export default AssemblyAI;
2
+ export * from "./services";
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import axios, { isAxiosError } from 'axios';
2
2
  import WebSocket from 'ws';
3
3
  import { Writable } from 'stream';
4
- import { readFile } from 'fs/promises';
4
+ import fs from 'fs';
5
5
 
6
6
  function createAxiosClient(params) {
7
7
  const client = axios.create({
@@ -369,15 +369,23 @@ class TranscriptService extends BaseService {
369
369
  return res.data;
370
370
  });
371
371
  }
372
- // TODO: add options overload to support list querystring parameters
373
372
  /**
374
- * Retrieves a paged list of transcript listings.
375
- * @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
376
- * @returns
373
+ * Retrieves a page of transcript listings.
374
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
377
375
  */
378
- list(nextUrl) {
376
+ list(parameters) {
379
377
  return __awaiter(this, void 0, void 0, function* () {
380
- const { data } = yield this.client.get(nextUrl !== null && nextUrl !== void 0 ? nextUrl : "/v2/transcript");
378
+ let url = "/v2/transcript";
379
+ let query;
380
+ if (typeof parameters === "string") {
381
+ url = parameters;
382
+ }
383
+ else if (parameters) {
384
+ query = parameters;
385
+ }
386
+ const { data } = yield this.client.get(url, {
387
+ params: query,
388
+ });
381
389
  for (const transcriptListItem of data.transcripts) {
382
390
  transcriptListItem.created = new Date(transcriptListItem.created);
383
391
  if (transcriptListItem.completed) {
@@ -478,13 +486,17 @@ function getPath(path) {
478
486
  class FileService extends BaseService {
479
487
  /**
480
488
  * Upload a local file to AssemblyAI.
481
- * @param path The local file to upload.
489
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
482
490
  * @return A promise that resolves to the uploaded file URL.
483
491
  */
484
- upload(path) {
492
+ upload(input) {
485
493
  return __awaiter(this, void 0, void 0, function* () {
486
- const file = yield readFile(path);
487
- const { data } = yield this.client.post("/v2/upload", file, {
494
+ let fileData;
495
+ if (typeof input === "string")
496
+ fileData = fs.createReadStream(input);
497
+ else
498
+ fileData = input;
499
+ const { data } = yield this.client.post("/v2/upload", fileData, {
488
500
  headers: {
489
501
  "Content-Type": "application/octet-stream",
490
502
  },
@@ -509,18 +521,4 @@ class AssemblyAI {
509
521
  }
510
522
  }
511
523
 
512
- var services = /*#__PURE__*/Object.freeze({
513
- __proto__: null,
514
- AssemblyAI: AssemblyAI,
515
- FileService: FileService,
516
- LemurService: LemurService,
517
- RealtimeService: RealtimeService,
518
- RealtimeServiceFactory: RealtimeServiceFactory,
519
- TranscriptService: TranscriptService
520
- });
521
-
522
- class AssemblyAIExports extends AssemblyAI {
523
- }
524
- module.exports = Object.assign(AssemblyAIExports, services);
525
-
526
- export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService, AssemblyAI as default };
524
+ export { AssemblyAI, FileService, LemurService, RealtimeService, RealtimeServiceFactory, TranscriptService };
package/dist/index.js CHANGED
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var axios = require('axios');
6
4
  var WebSocket = require('ws');
7
5
  var stream = require('stream');
8
- var promises = require('fs/promises');
6
+ var fs = require('fs');
9
7
 
10
8
  function createAxiosClient(params) {
11
9
  const client = axios.create({
@@ -373,15 +371,23 @@ class TranscriptService extends BaseService {
373
371
  return res.data;
374
372
  });
375
373
  }
376
- // TODO: add options overload to support list querystring parameters
377
374
  /**
378
- * Retrieves a paged list of transcript listings.
379
- * @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
380
- * @returns
375
+ * Retrieves a page of transcript listings.
376
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
381
377
  */
382
- list(nextUrl) {
378
+ list(parameters) {
383
379
  return __awaiter(this, void 0, void 0, function* () {
384
- const { data } = yield this.client.get(nextUrl !== null && nextUrl !== void 0 ? nextUrl : "/v2/transcript");
380
+ let url = "/v2/transcript";
381
+ let query;
382
+ if (typeof parameters === "string") {
383
+ url = parameters;
384
+ }
385
+ else if (parameters) {
386
+ query = parameters;
387
+ }
388
+ const { data } = yield this.client.get(url, {
389
+ params: query,
390
+ });
385
391
  for (const transcriptListItem of data.transcripts) {
386
392
  transcriptListItem.created = new Date(transcriptListItem.created);
387
393
  if (transcriptListItem.completed) {
@@ -482,13 +488,17 @@ function getPath(path) {
482
488
  class FileService extends BaseService {
483
489
  /**
484
490
  * Upload a local file to AssemblyAI.
485
- * @param path The local file to upload.
491
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
486
492
  * @return A promise that resolves to the uploaded file URL.
487
493
  */
488
- upload(path) {
494
+ upload(input) {
489
495
  return __awaiter(this, void 0, void 0, function* () {
490
- const file = yield promises.readFile(path);
491
- const { data } = yield this.client.post("/v2/upload", file, {
496
+ let fileData;
497
+ if (typeof input === "string")
498
+ fileData = fs.createReadStream(input);
499
+ else
500
+ fileData = input;
501
+ const { data } = yield this.client.post("/v2/upload", fileData, {
492
502
  headers: {
493
503
  "Content-Type": "application/octet-stream",
494
504
  },
@@ -513,24 +523,9 @@ class AssemblyAI {
513
523
  }
514
524
  }
515
525
 
516
- var services = /*#__PURE__*/Object.freeze({
517
- __proto__: null,
518
- AssemblyAI: AssemblyAI,
519
- FileService: FileService,
520
- LemurService: LemurService,
521
- RealtimeService: RealtimeService,
522
- RealtimeServiceFactory: RealtimeServiceFactory,
523
- TranscriptService: TranscriptService
524
- });
525
-
526
- class AssemblyAIExports extends AssemblyAI {
527
- }
528
- module.exports = Object.assign(AssemblyAIExports, services);
529
-
530
526
  exports.AssemblyAI = AssemblyAI;
531
527
  exports.FileService = FileService;
532
528
  exports.LemurService = LemurService;
533
529
  exports.RealtimeService = RealtimeService;
534
530
  exports.RealtimeServiceFactory = RealtimeServiceFactory;
535
531
  exports.TranscriptService = TranscriptService;
536
- exports.default = AssemblyAI;
@@ -1,9 +1,10 @@
1
1
  import { BaseService } from "@/services/base";
2
+ import { FileUploadParameters } from "@/types";
2
3
  export declare class FileService extends BaseService {
3
4
  /**
4
5
  * Upload a local file to AssemblyAI.
5
- * @param path The local file to upload.
6
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
6
7
  * @return A promise that resolves to the uploaded file URL.
7
8
  */
8
- upload(path: string): Promise<string>;
9
+ upload(input: FileUploadParameters): Promise<string>;
9
10
  }
@@ -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, WordSearchResponse } from "@/types";
2
+ import { ParagraphsResponse, SentencesResponse, Transcript, TranscriptList, CreateTranscriptParameters, CreateTranscriptOptions, Createable, Deletable, Listable, Retrieveable, SubtitleFormat, RedactedAudioResponse, TranscriptListParameters, 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> {
@@ -20,11 +20,10 @@ export declare class TranscriptService extends BaseService implements Createable
20
20
  */
21
21
  get(id: string): Promise<Transcript>;
22
22
  /**
23
- * Retrieves a paged list of transcript listings.
24
- * @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
25
- * @returns
23
+ * Retrieves a page of transcript listings.
24
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
26
25
  */
27
- list(nextUrl?: string | null): Promise<TranscriptList>;
26
+ list(parameters?: TranscriptListParameters | string): Promise<TranscriptList>;
28
27
  /**
29
28
  * Delete a transcript
30
29
  * @param id The identifier of the transcript.
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ type FileUploadParameters = string | FileUploadData;
4
+ type FileUploadData = NodeJS.ReadableStream | ReadableStream | Buffer | ArrayBufferView | ArrayBufferLike | Uint8Array;
5
+ export type { FileUploadParameters, FileUploadData };
@@ -1,3 +1,4 @@
1
+ export type * from "./files";
1
2
  export type * from "./transcripts";
2
3
  export type * from "./realtime";
3
4
  export type * from "./services";
@@ -620,6 +620,27 @@ export type TranscriptListItem = {
620
620
  resource_url: string;
621
621
  status: TranscriptStatus;
622
622
  };
623
+ export type TranscriptListParameters = {
624
+ /** @description Get transcripts that were created after this transcript ID */
625
+ after_id?: string;
626
+ /** @description Get transcripts that were created before this transcript ID */
627
+ before_id?: string;
628
+ /**
629
+ * Format: date
630
+ * @description Only get transcripts created on this date
631
+ */
632
+ created_on?: string;
633
+ /**
634
+ * Format: int64
635
+ * @description Maximum amount of transcripts to retrieve
636
+ * @default 10
637
+ */
638
+ limit?: number;
639
+ /** @description Filter by transcript status */
640
+ status?: TranscriptStatus;
641
+ /** @description Only get throttled transcripts, overrides the status filter */
642
+ throttled_only?: boolean;
643
+ };
623
644
  export type TranscriptParagraph = {
624
645
  /** Format: double */
625
646
  confidence: number;
@@ -1,3 +1,3 @@
1
- import { BaseServiceParams } from "../.";
1
+ import { BaseServiceParams } from "@/types";
2
2
  export declare function createAxiosClient(params: BaseServiceParams): import("axios").AxiosInstance;
3
3
  export declare function throwApiError(error: unknown): Promise<never>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assemblyai",
3
- "version": "2.0.2",
3
+ "version": "3.0.0",
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",
package/src/index.ts CHANGED
@@ -1,7 +1,2 @@
1
- import * as services from "./services";
2
- import { AssemblyAI } from "./services";
3
- export * from "./services";
4
1
  export type * from "./types";
5
- export default AssemblyAI;
6
- class AssemblyAIExports extends AssemblyAI {}
7
- module.exports = Object.assign(AssemblyAIExports, services);
2
+ export * from "./services";
@@ -1,21 +1,29 @@
1
- import { readFile } from "fs/promises";
1
+ // import the fs module instead if specific named exports
2
+ // to keep the assemblyai module more compatible. Some fs polyfills don't include `createReadStream`.
3
+ import fs from "fs";
2
4
  import { BaseService } from "@/services/base";
3
- import { UploadedFile } from "@/types";
5
+ import { UploadedFile, FileUploadParameters, FileUploadData } from "@/types";
4
6
 
5
7
  export class FileService extends BaseService {
6
8
  /**
7
9
  * Upload a local file to AssemblyAI.
8
- * @param path The local file to upload.
10
+ * @param input The local file path to upload, or a stream or buffer of the file to upload.
9
11
  * @return A promise that resolves to the uploaded file URL.
10
12
  */
11
- async upload(path: string): Promise<string> {
12
- const file = await readFile(path);
13
+ async upload(input: FileUploadParameters): Promise<string> {
14
+ let fileData: FileUploadData;
15
+ if (typeof input === "string") fileData = fs.createReadStream(input);
16
+ else fileData = input;
13
17
 
14
- const { data } = await this.client.post<UploadedFile>("/v2/upload", file, {
15
- headers: {
16
- "Content-Type": "application/octet-stream",
17
- },
18
- });
18
+ const { data } = await this.client.post<UploadedFile>(
19
+ "/v2/upload",
20
+ fileData,
21
+ {
22
+ headers: {
23
+ "Content-Type": "application/octet-stream",
24
+ },
25
+ }
26
+ );
19
27
 
20
28
  return data.upload_url;
21
29
  }
@@ -12,6 +12,7 @@ import {
12
12
  Retrieveable,
13
13
  SubtitleFormat,
14
14
  RedactedAudioResponse,
15
+ TranscriptListParameters,
15
16
  WordSearchResponse,
16
17
  } from "@/types";
17
18
  import { AxiosInstance } from "axios";
@@ -87,16 +88,23 @@ export class TranscriptService
87
88
  return res.data;
88
89
  }
89
90
 
90
- // TODO: add options overload to support list querystring parameters
91
91
  /**
92
- * Retrieves a paged list of transcript listings.
93
- * @param nextUrl The URL to retrieve the transcript list from. If not provided, the first page will be retrieved.
94
- * @returns
92
+ * Retrieves a page of transcript listings.
93
+ * @param parameters The parameters to filter the transcript list by, or the URL to retrieve the transcript list from.
95
94
  */
96
- async list(nextUrl?: string | null): Promise<TranscriptList> {
97
- const { data } = await this.client.get<TranscriptList>(
98
- nextUrl ?? "/v2/transcript"
99
- );
95
+ async list(
96
+ parameters?: TranscriptListParameters | string
97
+ ): Promise<TranscriptList> {
98
+ let url = "/v2/transcript";
99
+ let query: TranscriptListParameters | undefined;
100
+ if (typeof parameters === "string") {
101
+ url = parameters;
102
+ } else if (parameters) {
103
+ query = parameters;
104
+ }
105
+ const { data } = await this.client.get<TranscriptList>(url, {
106
+ params: query,
107
+ });
100
108
  for (const transcriptListItem of data.transcripts) {
101
109
  transcriptListItem.created = new Date(transcriptListItem.created);
102
110
  if (transcriptListItem.completed) {
@@ -0,0 +1,10 @@
1
+ type FileUploadParameters = string | FileUploadData;
2
+ type FileUploadData =
3
+ | NodeJS.ReadableStream
4
+ | ReadableStream
5
+ | Buffer
6
+ | ArrayBufferView
7
+ | ArrayBufferLike
8
+ | Uint8Array;
9
+
10
+ export type { FileUploadParameters, FileUploadData };
@@ -1,3 +1,4 @@
1
+ export type * from "./files";
1
2
  export type * from "./transcripts";
2
3
  export type * from "./realtime";
3
4
  export type * from "./services";
@@ -762,6 +762,28 @@ export type TranscriptListItem = {
762
762
  status: TranscriptStatus;
763
763
  };
764
764
 
765
+ export type TranscriptListParameters = {
766
+ /** @description Get transcripts that were created after this transcript ID */
767
+ after_id?: string;
768
+ /** @description Get transcripts that were created before this transcript ID */
769
+ before_id?: string;
770
+ /**
771
+ * Format: date
772
+ * @description Only get transcripts created on this date
773
+ */
774
+ created_on?: string;
775
+ /**
776
+ * Format: int64
777
+ * @description Maximum amount of transcripts to retrieve
778
+ * @default 10
779
+ */
780
+ limit?: number;
781
+ /** @description Filter by transcript status */
782
+ status?: TranscriptStatus;
783
+ /** @description Only get throttled transcripts, overrides the status filter */
784
+ throttled_only?: boolean;
785
+ };
786
+
765
787
  export type TranscriptParagraph = {
766
788
  /** Format: double */
767
789
  confidence: number;
@@ -1,5 +1,5 @@
1
1
  import axios, { isAxiosError } from "axios";
2
- import { BaseServiceParams } from "../.";
2
+ import { BaseServiceParams } from "@/types";
3
3
 
4
4
  export function createAxiosClient(params: BaseServiceParams) {
5
5
  const client = axios.create({