Skip to content

Commit 87c2be2

Browse files
authored
Merge pull request #29 from AssemblyAI/5FC74E4F61B92B08B5515C2BF0B00557
Release 4.1.0
2 parents ffa9186 + 777f9b6 commit 87c2be2

File tree

11 files changed

+64
-18
lines changed

11 files changed

+64
-18
lines changed

CHANGELOG.md

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

3+
## [4.1.0] - 2023-12-22
4+
5+
### Added
6+
7+
- Add `"anthropic/claude-2-1"` to `LemurModel` type
8+
- Add `encoding` option to the real-time service and factory. `encoding` can be `"pcm_s16le"` or `"pcm_mulaw"`.
9+
- `"pcm_mulaw"` is a newly supported audio encoding for the real-time service.
10+
11+
### Changed
12+
13+
- Allow any string into `final_model` for LeMUR requests
14+
315
## [4.0.1] - 2023-12-14
416

517
### Added

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.0.1",
3+
"version": "4.1.0",
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ async function generateTypes(apiSpecPath: string, outputPath: string) {
1717
return schemaObject.nullable ? "Date | null" : "Date";
1818
}
1919
},
20+
postTransform(type) {
21+
if (type === `components["schemas"]["LemurModel"] | string`) {
22+
return `LiteralUnion<components["schemas"]["LemurModel"], string>`;
23+
}
24+
},
2025
});
2126
const schemasPosition = output.indexOf("schemas: {") + 10;
2227
output = output
@@ -46,6 +51,8 @@ async function generateTypes(apiSpecPath: string, outputPath: string) {
4651
/* tslint:disable */
4752
/* eslint-disable */
4853
54+
import { LiteralUnion } from "./helpers";
55+
4956
/** OneOf type helpers */
5057
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
5158
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

scripts/kitchensink.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ import {
1212
} from "../src";
1313

1414
const client = new AssemblyAI({
15-
apiKey: process.env.ASSEMBLYAI_API_KEY || "",
15+
apiKey: process.env.ASSEMBLYAI_API_KEY!,
1616
});
1717

1818
(async function transcribeUsingRealtime() {
1919
const useToken = false;
20-
let token: undefined | string = undefined;
21-
if (useToken) {
22-
token = await client.realtime.createTemporaryToken({
23-
expires_in: 480,
24-
});
25-
}
2620
const serviceParams: CreateRealtimeServiceParams = {
2721
sampleRate: 16_000,
2822
wordBoost: ["gore", "climate"],
29-
token: token,
23+
token: useToken
24+
? await client.realtime.createTemporaryToken({
25+
expires_in: 480,
26+
})
27+
: undefined,
28+
encoding: "pcm_s16le",
3029
};
3130
const rt = client.realtime.createService(serviceParams);
3231

@@ -51,7 +50,7 @@ const client = new AssemblyAI({
5150
await rt.connect();
5251

5352
const chunkSize = 8 * 1024;
54-
const audio = createReadStream("./tests/static/gore-short.wav", {
53+
const audio = createReadStream("./tests/static/gore.wav", {
5554
highWaterMark: chunkSize,
5655
});
5756
for await (const chunk of audio) {

src/services/realtime/factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export class RealtimeServiceFactory extends BaseService {
1616
}
1717

1818
createService(params?: CreateRealtimeServiceParams): RealtimeService {
19-
if (!params) params = { apiKey: this.rtFactoryParams.apiKey };
20-
else if (!("token" in params) && !params.apiKey) {
21-
params.apiKey = this.rtFactoryParams.apiKey;
19+
const serviceParams = { ...params } as Record<string, unknown>;
20+
if (!serviceParams.token && !serviceParams.apiKey) {
21+
serviceParams.apiKey = this.rtFactoryParams.apiKey;
2222
}
2323

24-
return new RealtimeService(params as RealtimeServiceParams);
24+
return new RealtimeService(serviceParams as RealtimeServiceParams);
2525
}
2626

2727
async createTemporaryToken(params: RealtimeTokenParams) {

src/services/realtime/service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PartialTranscript,
1111
FinalTranscript,
1212
SessionBeginsEventData,
13+
AudioEncoding,
1314
} from "../..";
1415
import {
1516
RealtimeError,
@@ -23,6 +24,7 @@ export class RealtimeService {
2324
private realtimeUrl: string;
2425
private sampleRate: number;
2526
private wordBoost?: string[];
27+
private encoding?: AudioEncoding;
2628
private apiKey?: string;
2729
private token?: string;
2830
private socket?: WebSocket;
@@ -33,10 +35,11 @@ export class RealtimeService {
3335
this.realtimeUrl = params.realtimeUrl ?? defaultRealtimeUrl;
3436
this.sampleRate = params.sampleRate ?? 16_000;
3537
this.wordBoost = params.wordBoost;
36-
if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
38+
this.encoding = params.encoding;
3739
if ("token" in params && params.token) this.token = params.token;
40+
if ("apiKey" in params && params.apiKey) this.apiKey = params.apiKey;
3841

39-
if (!(this.apiKey || this.token)) {
42+
if (!(this.token || this.apiKey)) {
4043
throw new Error("API key or temporary token is required.");
4144
}
4245
}
@@ -56,6 +59,9 @@ export class RealtimeService {
5659
if (this.wordBoost && this.wordBoost.length > 0) {
5760
searchParams.set("word_boost", JSON.stringify(this.wordBoost));
5861
}
62+
if (this.encoding) {
63+
searchParams.set("encoding", this.encoding);
64+
}
5965
url.search = searchParams.toString();
6066

6167
return url;

src/types/asyncapi.generated.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* tslint:disable */
33
/* eslint-disable */
44

5+
import { LiteralUnion } from "./helpers";
6+
57
/** OneOf type helpers */
68
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
79
type XOR<T, U> = T | U extends object
@@ -18,6 +20,13 @@ export type AudioData = {
1820
audio_data: string;
1921
};
2022

23+
/**
24+
* @description The encoding of the audio data
25+
* @default pcm_s16le
26+
* @enum {string}
27+
*/
28+
export type AudioEncoding = "pcm_s16le" | "pcm_mulaw";
29+
2130
export type FinalTranscript = RealtimeBaseTranscript & {
2231
/**
2332
* @description Describes the type of message

src/types/helpers/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// source: https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
2+
export type LiteralUnion<LiteralType, BaseType> =
3+
| LiteralType
4+
| (BaseType & Record<never, never>);

src/types/openapi.generated.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/* tslint:disable */
33
/* eslint-disable */
44

5+
import { LiteralUnion } from "./helpers";
6+
57
/** OneOf type helpers */
68
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
79
type XOR<T, U> = T | U extends object
@@ -512,7 +514,7 @@ export type LemurBaseParams = {
512514
}
513515
]
514516
>;
515-
final_model?: LemurModel;
517+
final_model?: LiteralUnion<LemurModel, string>;
516518
/**
517519
* @description Custom formatted transcript data. Maximum size is the context limit of the selected model, which defaults to 100000.
518520
* Use either transcript_ids or input_text as input into LeMUR.
@@ -552,7 +554,11 @@ export type LemurBaseResponse = {
552554
*
553555
* @enum {string}
554556
*/
555-
export type LemurModel = "default" | "basic" | "assemblyai/mistral-7b";
557+
export type LemurModel =
558+
| "default"
559+
| "basic"
560+
| "assemblyai/mistral-7b"
561+
| "anthropic/claude-2-1";
556562

557563
/**
558564
* @example {

src/types/realtime/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AudioEncoding,
23
FinalTranscript,
34
PartialTranscript,
45
RealtimeTranscript,
@@ -9,6 +10,7 @@ type CreateRealtimeServiceParams = {
910
realtimeUrl?: string;
1011
sampleRate?: number;
1112
wordBoost?: string[];
13+
encoding?: AudioEncoding;
1214
} & (
1315
| {
1416
apiKey?: string;
@@ -22,6 +24,7 @@ type RealtimeServiceParams = {
2224
realtimeUrl?: string;
2325
sampleRate?: number;
2426
wordBoost?: string[];
27+
encoding?: AudioEncoding;
2528
} & (
2629
| {
2730
apiKey: string;

0 commit comments

Comments
 (0)