assemblyai 2.0.0-beta → 2.0.1-beta

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 (79) hide show
  1. package/README.md +148 -48
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.esm.js +218 -123
  4. package/dist/index.js +225 -123
  5. package/dist/services/base.d.ts +0 -2
  6. package/dist/services/index.d.ts +7 -9
  7. package/dist/services/lemur/index.d.ts +6 -6
  8. package/dist/services/realtime/factory.d.ts +10 -0
  9. package/dist/services/realtime/index.d.ts +2 -16
  10. package/dist/services/realtime/service.d.ts +22 -0
  11. package/dist/services/transcripts/index.d.ts +37 -20
  12. package/dist/types/asyncapi.generated.d.ts +87 -0
  13. package/dist/types/index.d.ts +3 -4
  14. package/dist/types/openapi.generated.d.ts +685 -0
  15. package/dist/types/realtime/index.d.ts +30 -11
  16. package/dist/types/services/abstractions.d.ts +8 -36
  17. package/dist/types/services/index.d.ts +2 -5
  18. package/dist/types/transcripts/index.d.ts +5 -0
  19. package/dist/utils/axios.d.ts +3 -0
  20. package/dist/utils/errors/realtime.d.ts +1 -4
  21. package/package.json +8 -5
  22. package/src/index.ts +3 -0
  23. package/src/services/base.ts +1 -3
  24. package/src/services/files/index.ts +4 -4
  25. package/src/services/index.ts +18 -35
  26. package/src/services/lemur/index.ts +20 -16
  27. package/src/services/realtime/factory.ts +32 -0
  28. package/src/services/realtime/index.ts +2 -106
  29. package/src/services/realtime/service.ts +184 -0
  30. package/src/services/transcripts/index.ts +85 -63
  31. package/src/types/asyncapi.generated.ts +124 -0
  32. package/src/types/index.ts +3 -4
  33. package/src/types/openapi.generated.ts +834 -0
  34. package/src/types/realtime/index.ts +53 -13
  35. package/src/types/services/abstractions.ts +8 -40
  36. package/src/types/services/index.ts +2 -6
  37. package/src/types/transcripts/index.ts +5 -0
  38. package/src/utils/axios.ts +19 -0
  39. package/src/utils/errors/realtime.ts +5 -18
  40. package/dist/services/transcripts/redactions.d.ts +0 -14
  41. package/dist/services/transcripts/subtitles.d.ts +0 -12
  42. package/dist/types/core/index.d.ts +0 -2
  43. package/dist/types/core/params.d.ts +0 -2
  44. package/dist/types/core/segments.d.ts +0 -28
  45. package/dist/types/core/transcript.d.ts +0 -113
  46. package/dist/types/lemur/index.d.ts +0 -79
  47. package/dist/types/models/auto_chapter.d.ts +0 -8
  48. package/dist/types/models/auto_highlights.d.ts +0 -11
  49. package/dist/types/models/content_safety.d.ts +0 -25
  50. package/dist/types/models/entity_detection.d.ts +0 -7
  51. package/dist/types/models/index.d.ts +0 -8
  52. package/dist/types/models/pii.d.ts +0 -3
  53. package/dist/types/models/sentiment_analysis.d.ts +0 -9
  54. package/dist/types/models/shared.d.ts +0 -3
  55. package/dist/types/models/summarization.d.ts +0 -3
  56. package/dist/types/models/topic_detection.d.ts +0 -17
  57. package/dist/types/shared/index.d.ts +0 -2
  58. package/dist/types/shared/pagination.d.ts +0 -7
  59. package/dist/types/shared/timestamp.d.ts +0 -5
  60. package/src/services/transcripts/redactions.ts +0 -27
  61. package/src/services/transcripts/subtitles.ts +0 -26
  62. package/src/types/core/index.ts +0 -2
  63. package/src/types/core/params.ts +0 -3
  64. package/src/types/core/segments.ts +0 -29
  65. package/src/types/core/transcript.ts +0 -159
  66. package/src/types/lemur/index.ts +0 -97
  67. package/src/types/models/auto_chapter.ts +0 -9
  68. package/src/types/models/auto_highlights.ts +0 -14
  69. package/src/types/models/content_safety.ts +0 -34
  70. package/src/types/models/entity_detection.ts +0 -8
  71. package/src/types/models/index.ts +0 -8
  72. package/src/types/models/pii.ts +0 -32
  73. package/src/types/models/sentiment_analysis.ts +0 -11
  74. package/src/types/models/shared.ts +0 -4
  75. package/src/types/models/summarization.ts +0 -10
  76. package/src/types/models/topic_detection.ts +0 -21
  77. package/src/types/shared/index.ts +0 -2
  78. package/src/types/shared/pagination.ts +0 -8
  79. package/src/types/shared/timestamp.ts +0 -6
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <img src="https://github.com/AssemblyAI/assemblyai-typescript-sdk/blob/master/assemblyai.png?raw=true" width="500"/>
2
+
3
+ ---
4
+
1
5
  # AssemblyAI Node.js SDK
2
6
 
3
7
  The AssemblyAI Node.js SDK provides an easy-to-use interface for interacting with the AssemblyAI API,
@@ -5,121 +9,217 @@ which supports async and real-time transcription, as well as the latest LeMUR mo
5
9
 
6
10
  ## Installation
7
11
 
8
- Use [npm](https://www.npmjs.com/) to install AssemblyAI:
12
+ You can install the AssemblyAI SDK by running:
9
13
 
10
14
  ```bash
11
15
  npm install assemblyai
12
16
  ```
13
17
 
18
+ ```bash
19
+ yarn add assemblyai
20
+ ```
21
+
22
+ ```bash
23
+ pnpm add assemblyai
24
+ ```
25
+
26
+ ```bash
27
+ bun add assemblyai
28
+ ```
29
+
14
30
  # Usage
15
31
 
16
- Import the AssemblyAI package and create an AssemblyAI object with your API token:
32
+ Import the AssemblyAI package and create an AssemblyAI object with your API key:
17
33
 
18
34
  ```javascript
19
- import AssemblyAI from 'assemblyai'
35
+ import AssemblyAI from "assemblyai";
20
36
 
21
- const assembly = new AssemblyAI({
22
- token: process.env.ASSEMBLYAI_API_KEY,
37
+ const client = new AssemblyAI({
38
+ apiKey: process.env.ASSEMBLYAI_API_KEY,
23
39
  })
24
40
  ```
25
41
 
26
- You can now use the `assembly` object to interact with the AssemblyAI API.
42
+ You can now use the `client` object to interact with the AssemblyAI API.
27
43
 
28
- ## Create a Transcript
44
+ ## Create a transcript
29
45
 
30
46
  When you create a transcript, you can either pass in a URL to an audio file, or upload a file directly.
31
47
 
32
48
  ```javascript
33
49
  // Using a remote URL
34
- const created = await assembly.transcripts.create({
50
+ const transcript = await client.transcripts.create({
35
51
  audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
36
52
  })
37
53
  ```
38
54
 
39
55
  ```javascript
40
56
  // Uploading a file
41
- const created = await assembly.transcripts.create({
57
+ const transcript = await client.transcripts.create({
42
58
  audio_url: './news.mp4',
43
59
  })
44
60
  ```
45
61
 
46
- ## Retrieve a Transcript
47
-
48
- This will return the transcript object in its current state. If the transcript is still processing, the `status` field will be `queued` or `processing`. Once the transcript is complete, the `status` field will be `completed`.
62
+ By default, when you create a transcript, it'll be polled until the status is `completed` or `error`.
63
+ You can configure whether to poll, the polling interval, and polling timeout using these options:
49
64
 
50
65
  ```javascript
51
- const transcript = await assembly.transcripts.retrieve(created.id)
66
+ const transcript = await client.transcripts.create({
67
+ audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
68
+ },
69
+ {
70
+ // Enable or disable polling. Defaults to true.
71
+ poll: true,
72
+ // How frequently the transcript is polled in ms. Defaults to 3000.
73
+ pollingInterval: 1000,
74
+ // How long to wait in ms until the "Polling timeout" error is thrown. Defaults to 180000.
75
+ pollingTimeout: 5000,
76
+ })
52
77
  ```
53
78
 
54
- ## Poll a Transcript
79
+ ## Get a transcript
55
80
 
56
- This will poll the transcript until it is complete. Once the transcript is complete, the `status` field will be `completed`.
81
+ This will return the transcript object in its current state. If the transcript is still processing, the `status` field will be `queued` or `processing`. Once the transcript is complete, the `status` field will be `completed`.
57
82
 
58
83
  ```javascript
59
- const transcript = await assembly.transcripts.poll({
60
- transcript_id: created.id,
61
- })
84
+ const transcript = await client.transcripts.get(transcript.id)
62
85
  ```
63
86
 
64
- ## List Transcripts
87
+ ## List transcripts
65
88
 
66
- This will return a list of all transcripts that you have created.
89
+ This will return a paged list of transcripts that you have transcript.
67
90
 
68
91
  ```javascript
69
- const page = await assembly.transcripts.list()
92
+ const page = await client.transcripts.list()
93
+ ```
94
+
95
+ You can also paginate over all pages.
96
+
97
+ ```typescript
98
+ let nextPageUrl: string | null = null;
99
+ do {
100
+ const page = await client.transcripts.list(nextPageUrl)
101
+ nextPageUrl = page.page_details.next_url
102
+ } while(nextPageUrl !== null)
70
103
  ```
71
104
 
72
- ## Delete a Transcript
105
+ ## Delete a transcript
73
106
 
74
107
  ```javascript
75
- const res = await assembly.transcripts.delete(transcript.id)
108
+ const res = await client.transcripts.delete(transcript.id)
76
109
  ```
77
110
 
78
- ## LeMUR
111
+ ## Use LeMUR
79
112
 
80
- The SDK supports the latest LeMUR models. You can specify which model you would like to use when creating a transcript.
113
+ Call [LeMUR endpoints](https://www.assemblyai.com/docs/API%20reference/lemur) to summarize, ask questions, generate action items, or run a custom task.
114
+
115
+ Custom Summary:
116
+ ```javascript
117
+ const { response } = await client.lemur.summary({
118
+ transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
119
+ answer_format: 'one sentence',
120
+ context: {
121
+ speakers: ['Alex', 'Bob'],
122
+ }
123
+ })
124
+ ```
81
125
 
126
+ Question & Answer:
82
127
  ```javascript
83
- // Ask a question about the transcript
84
- const { response } = await assembly.lemur.create({
85
- type: 'question',
86
- model: 'basic',
87
- transcript_id: '0d295578-8c75-421a-885a-2c487f188927',
128
+ const { response } = await client.lemur.questionAnswer({
129
+ transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
88
130
  questions: [
89
131
  {
90
132
  question: 'What are they discussing?',
91
133
  answer_format: 'text',
92
- },
93
- ],
134
+ }
135
+ ]
94
136
  })
95
137
  ```
96
138
 
139
+ Action Items:
97
140
  ```javascript
98
- // Summarize the transcript
99
- const { response } = await assembly.lemur.create({
100
- type: 'summary',
101
- model: 'basic',
102
- transcript_id: '0d295578-8c75-421a-885a-2c487f188927',
103
- context: {
104
- speakers: ['Alex', 'Bob'],
105
- },
141
+ const { response } = await client.lemur.actionItems({
142
+ transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
106
143
  })
107
144
  ```
108
145
 
146
+ Custom Task:
109
147
  ```javascript
110
- // AI Coach
111
- const { response } = await assembly.lemur.create({
112
- type: 'coach',
113
- model: 'basic',
114
- transcript_id: '0d295578-8c75-421a-885a-2c487f188927',
148
+ const { response } = await client.lemur.task({
149
+ transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
150
+ prompt: 'Write a haiku about this conversation.',
115
151
  })
116
152
  ```
117
153
 
154
+ ## Transcribe in real time
155
+
156
+ Create the real-time service.
157
+
158
+ ```typescript
159
+ const service = client.realtime.createService();
160
+ ```
161
+
162
+ You can also pass in the following options.
163
+
164
+ ```typescript
165
+ const service = client.realtime.createService({
166
+ realtimeUrl: 'wss://localhost/override',
167
+ apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
168
+ sampleRate: 16_000,
169
+ wordBoost: ['foo', 'bar']
170
+ });
171
+ ```
172
+
173
+ You can also generate a temporary auth token for real-time.
174
+
175
+ ```typescript
176
+ const token = await client.realtime.createTemporaryToken({expires_in = 60});
177
+ const rt = client.realtime.createService({
178
+ token: token
179
+ });
180
+ ```
181
+
182
+ > [!WARNING]
183
+ > Storing your API key in client-facing applications exposes your API key.
184
+ > Generate a temporary auth token on the server and pass it to your client.
185
+
186
+ You can configure the following events.
187
+
188
+ ```typescript
189
+ rt.on("open", ({ sessionId, expiresAt }) => console.log('Session ID:', sessionId, 'Expires at:', expiresAt));
190
+ rt.on("close", (code: number, reason: string) => console.log('Closed', code, reason));
191
+ rt.on("transcript", (transcript: TranscriptMessage) => console.log('Transcript:', transcript));
192
+ rt.on("transcript.partial", (transcript: PartialTranscriptMessage) => console.log('Partial transcript:', transcript));
193
+ rt.on("transcript.final", (transcript: FinalTranscriptMessage) => console.log('Final transcript:', transcript));
194
+ rt.on("error", (error: Error) => console.error('Error', error));
195
+ ```
196
+
197
+ After configuring your events, connect to the server.
198
+
199
+ ```typescript
200
+ await rt.connect();
201
+ ```
202
+
203
+ Send audio data.
204
+
205
+ ```typescript
206
+ // Pseudo code for getting audio
207
+ getAudio((chunk) => {
208
+ rt.sendAudio(chunk);
209
+ });
210
+ ```
211
+
212
+ Close the connection when you're finished.
213
+
214
+ ```typescript
215
+ rt.close();
216
+ ```
217
+
118
218
  # Tests
119
219
 
120
- To run the test suite, first install the dependencies, then run `npm test`:
220
+ To run the test suite, first install the dependencies, then run `pnpm test`:
121
221
 
122
222
  ```bash
123
- npm install
124
- npm test
223
+ pnpm install
224
+ pnpm test
125
225
  ```
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import AssemblyAI from "./services";
2
+ export * from "./services";
3
+ export type * from "./types";
2
4
  export default AssemblyAI;