Skip to content

Commit bb6aa31

Browse files
AssemblyAISwimburger
authored andcommitted
Project import generated by Copybara.
GitOrigin-RevId: ac079adb8f337563cbf27b0e6a1dfa0bb1c17de8
1 parent 7f5efee commit bb6aa31

File tree

13 files changed

+117
-63
lines changed

13 files changed

+117
-63
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [4.2.1] - 2024-01-23
4+
5+
### Added
6+
- Add `answer_format` to `LemurActionItemsParams` type
7+
8+
### Changed
9+
- Rename `RealtimeService` to `RealtimeTranscriber`, `RealtimeServiceFactory` to `RealtimeTranscriberFactory`, `RealtimeTranscriberFactory.createService()` to `RealtimeTranscriberFactory.transcriber()`. Deprecated aliases are provided for all old types and functions for backwards compatibility.
10+
- Restrict the type for `redact_pii_audio_quality` from `string` to `RedactPiiAudioQuality` an enum string.
11+
312
## [4.2.0] - 2024-01-11
413

514
### Added

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,18 @@ const { response } = await client.lemur.task({
184184
});
185185
```
186186

187-
## Transcribe in real time
187+
## Transcribe in real-time
188188

189-
Create the real-time service.
189+
Create the real-time transcriber.
190190

191191
```typescript
192-
const rt = client.realtime.createService();
192+
const rt = client.realtime.transcriber();
193193
```
194194

195195
You can also pass in the following options.
196196

197197
```typescript
198-
const rt = client.realtime.createService({
198+
const rt = client.realtime.transcriber({
199199
realtimeUrl: 'wss://localhost/override',
200200
apiKey: process.env.ASSEMBLYAI_API_KEY // The API key passed to `AssemblyAI` will be used by default,
201201
sampleRate: 16_000,
@@ -207,7 +207,7 @@ You can also generate a temporary auth token for real-time.
207207

208208
```typescript
209209
const token = await client.realtime.createTemporaryToken({ expires_in = 60 });
210-
const rt = client.realtime.createService({
210+
const rt = client.realtime.transcriber({
211211
token: token,
212212
});
213213
```

docs/compat.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If you do use an older version of Node.js like version 16, you'll need to polyfi
1313
To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible.
1414
However, there are still incompatibilities between Node.js and the browser.
1515

16-
- `RealtimeService` doesn't support the AssemblyAI API key in the browser.
16+
- `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser.
1717
Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber.
1818

1919
Generate a temporary auth token on the server.
@@ -31,16 +31,16 @@ However, there are still incompatibilities between Node.js and the browser.
3131
> If you embed the API key on the client, everyone can see it and use it for themselves.
3232
3333
Then pass the token via an API to the client.
34-
On the client, create an instance of `RealtimeService` using the token.
34+
On the client, create an instance of `RealtimeTranscriber` using the token.
3535

3636
```js
37-
import { RealtimeService } from "assemblyai";
37+
import { RealtimeTranscriber } from "assemblyai";
3838
// or the following if you're using UMD
39-
// const { RealtimeService } = assemblyai;
39+
// const { RealtimeTranscriber } = assemblyai;
4040

4141
const token = getToken(); // getToken is a function for you to implement
4242

43-
const rt = new RealtimeService({
43+
const rt = new RealtimeTranscriber({
4444
token: token,
4545
});
4646
```

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.2.0",
3+
"version": "4.2.1",
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"

scripts/generate-types.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,8 @@ async function generateTypes(apiSpecPath: string, outputPath: string) {
77
alphabetize: true,
88
exportType: true,
99
transform(schemaObject) {
10-
if (
11-
"x-fern-type" in schemaObject &&
12-
schemaObject["x-fern-type"] === "datetime"
13-
) {
14-
// Use Date as type instead of String, even though it will be a string.
15-
// The service code manually converts the string into a Date.
16-
// Fe see `TranscriptService#list`.
17-
return schemaObject.nullable ? "Date | null" : "Date";
18-
}
19-
},
20-
postTransform(type) {
21-
if (type === `components["schemas"]["LemurModel"] | string`) {
22-
return `LiteralUnion<components["schemas"]["LemurModel"], string>`;
10+
if ("x-ts-type" in schemaObject) {
11+
return schemaObject["x-ts-type"];
2312
}
2413
},
2514
});

scripts/kitchensink.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
LemurBaseResponse,
88
PartialTranscript,
99
RealtimeTranscript,
10-
CreateRealtimeServiceParams,
10+
CreateRealtimeTranscriberParams,
1111
TranscribeParams,
1212
} from "../src";
1313

@@ -17,7 +17,7 @@ const client = new AssemblyAI({
1717

1818
(async function transcribeUsingRealtime() {
1919
const useToken = false;
20-
const serviceParams: CreateRealtimeServiceParams = {
20+
const serviceParams: CreateRealtimeTranscriberParams = {
2121
sampleRate: 16_000,
2222
wordBoost: ["gore", "climate"],
2323
token: useToken
@@ -27,7 +27,7 @@ const client = new AssemblyAI({
2727
: undefined,
2828
encoding: "pcm_s16le",
2929
};
30-
const rt = client.realtime.createService(serviceParams);
30+
const rt = client.realtime.transcriber(serviceParams);
3131

3232
rt.on("open", ({ sessionId, expiresAt }) => {
3333
console.log("Session ID:", sessionId, "Expires At:", expiresAt);

src/services/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { BaseServiceParams } from "..";
22
import { LemurService } from "./lemur";
3-
import { RealtimeService, RealtimeServiceFactory } from "./realtime";
3+
import {
4+
RealtimeTranscriber,
5+
RealtimeTranscriberFactory,
6+
RealtimeService,
7+
RealtimeServiceFactory,
8+
} from "./realtime";
49
import { TranscriptService } from "./transcripts";
510
import { FileService } from "./files";
611

@@ -25,7 +30,7 @@ class AssemblyAI {
2530
/**
2631
* The realtime service.
2732
*/
28-
public realtime: RealtimeServiceFactory;
33+
public realtime: RealtimeTranscriberFactory;
2934

3035
/**
3136
* Create a new AssemblyAI client.
@@ -38,13 +43,15 @@ class AssemblyAI {
3843
this.files = new FileService(params);
3944
this.transcripts = new TranscriptService(params, this.files);
4045
this.lemur = new LemurService(params);
41-
this.realtime = new RealtimeServiceFactory(params);
46+
this.realtime = new RealtimeTranscriberFactory(params);
4247
}
4348
}
4449

4550
export {
4651
AssemblyAI,
4752
LemurService,
53+
RealtimeTranscriberFactory,
54+
RealtimeTranscriber,
4855
RealtimeServiceFactory,
4956
RealtimeService,
5057
TranscriptService,

src/services/realtime/factory.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
import {
22
BaseServiceParams,
33
RealtimeTokenParams,
4-
CreateRealtimeServiceParams,
5-
RealtimeServiceParams,
4+
CreateRealtimeTranscriberParams,
5+
RealtimeTranscriberParams,
66
RealtimeTemporaryTokenResponse,
7+
CreateRealtimeServiceParams,
78
} from "../..";
8-
import { RealtimeService } from "./service";
9+
import { RealtimeService, RealtimeTranscriber } from "./service";
910
import { BaseService } from "../base";
1011

11-
export class RealtimeServiceFactory extends BaseService {
12+
export class RealtimeTranscriberFactory extends BaseService {
1213
private rtFactoryParams: BaseServiceParams;
1314
constructor(params: BaseServiceParams) {
1415
super(params);
1516
this.rtFactoryParams = params;
1617
}
1718

19+
/**
20+
* @deprecated Use transcriber(...) instead
21+
*/
1822
createService(params?: CreateRealtimeServiceParams): RealtimeService {
23+
return this.transcriber(params);
24+
}
25+
26+
transcriber(params?: CreateRealtimeTranscriberParams): RealtimeTranscriber {
1927
const serviceParams = { ...params } as Record<string, unknown>;
2028
if (!serviceParams.token && !serviceParams.apiKey) {
2129
serviceParams.apiKey = this.rtFactoryParams.apiKey;
2230
}
2331

24-
return new RealtimeService(serviceParams as RealtimeServiceParams);
32+
return new RealtimeTranscriber(serviceParams as RealtimeTranscriberParams);
2533
}
2634

2735
async createTemporaryToken(params: RealtimeTokenParams) {
@@ -35,3 +43,8 @@ export class RealtimeServiceFactory extends BaseService {
3543
return data.token;
3644
}
3745
}
46+
47+
/**
48+
* @deprecated Use RealtimeTranscriberFactory instead
49+
*/
50+
export class RealtimeServiceFactory extends RealtimeTranscriberFactory {}

src/services/realtime/service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { ErrorEvent, MessageEvent, CloseEvent } from "ws";
44
import {
55
RealtimeEvents,
66
RealtimeListeners,
7-
RealtimeServiceParams,
7+
RealtimeTranscriberParams,
88
RealtimeMessage,
99
RealtimeTranscript,
1010
PartialTranscript,
1111
FinalTranscript,
1212
SessionBeginsEventData,
1313
AudioEncoding,
14+
AudioData,
1415
} from "../..";
1516
import {
1617
RealtimeError,
@@ -20,7 +21,7 @@ import {
2021

2122
const defaultRealtimeUrl = "wss://api.assemblyai.com/v2/realtime/ws";
2223

23-
export class RealtimeService {
24+
export class RealtimeTranscriber {
2425
private realtimeUrl: string;
2526
private sampleRate: number;
2627
private wordBoost?: string[];
@@ -31,7 +32,7 @@ export class RealtimeService {
3132
private listeners: RealtimeListeners = {};
3233
private sessionTerminatedResolve?: () => void;
3334

34-
constructor(params: RealtimeServiceParams) {
35+
constructor(params: RealtimeTranscriberParams) {
3536
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
3637
this.sampleRate = params.sampleRate ?? 16_000;
3738
this.wordBoost = params.wordBoost;
@@ -157,16 +158,16 @@ export class RealtimeService {
157158
});
158159
}
159160

160-
sendAudio(audio: ArrayBufferLike) {
161+
sendAudio(audio: AudioData) {
161162
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
162163
throw new Error("Socket is not open for communication");
163164
}
164165
this.socket.send(audio);
165166
}
166167

167-
stream(): WritableStream<ArrayBufferLike> {
168-
return new WritableStream<ArrayBufferLike>({
169-
write: (chunk: ArrayBufferLike) => {
168+
stream(): WritableStream<AudioData> {
169+
return new WritableStream<AudioData>({
170+
write: (chunk: AudioData) => {
170171
this.sendAudio(chunk);
171172
},
172173
});
@@ -194,3 +195,8 @@ export class RealtimeService {
194195
this.socket = undefined;
195196
}
196197
}
198+
199+
/**
200+
* @deprecated Use RealtimeTranscriber instead
201+
*/
202+
export class RealtimeService extends RealtimeTranscriber {}

src/types/asyncapi.generated.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ type OneOf<T extends any[]> = T extends [infer Only]
1515
? OneOf<[XOR<A, B>, ...Rest]>
1616
: never;
1717

18-
export type AudioData = {
19-
/** @description Base64 encoded raw audio data */
20-
audio_data: string;
21-
};
18+
/**
19+
* Format: binary
20+
* @description Binary audio data
21+
*/
22+
export type AudioData = ArrayBufferLike;
2223

2324
/**
2425
* @description The encoding of the audio data

0 commit comments

Comments
 (0)