Skip to content

Commit 7f5efee

Browse files
authored
Merge pull request #30 from AssemblyAI/E07417BDFEA3614F5967B1520F8B2F61
Release 4.2.0
2 parents 87c2be2 + dcbead1 commit 7f5efee

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

CHANGELOG.md

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

3+
## [4.2.0] - 2024-01-11
4+
5+
### Added
6+
7+
- Add `content_safety_confidence` to `TranscriptParams` & `TranscriptOptionalParams`.
8+
9+
### Changed
10+
11+
- The `RealtimeService` now sends audio as binary instead of a base64-encoded JSON object.
12+
313
## [4.1.0] - 2023-12-22
414

515
### 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.1.0",
3+
"version": "4.2.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"

src/services/realtime/service.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class RealtimeService {
102102
headers: { Authorization: this.apiKey },
103103
});
104104
}
105+
this.socket.binaryType = "arraybuffer";
105106

106107
this.socket.onclose = ({ code, reason }: CloseEvent) => {
107108
if (!reason) {
@@ -160,23 +161,7 @@ export class RealtimeService {
160161
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
161162
throw new Error("Socket is not open for communication");
162163
}
163-
let audioData;
164-
if (typeof Buffer !== "undefined") {
165-
audioData = Buffer.from(audio).toString("base64");
166-
} else {
167-
// Buffer is not available in the browser by default
168-
// https://stackoverflow.com/a/42334410/2919731
169-
audioData = btoa(
170-
new Uint8Array(audio).reduce(
171-
(data, byte) => data + String.fromCharCode(byte),
172-
""
173-
)
174-
);
175-
}
176-
const payload = {
177-
audio_data: audioData,
178-
};
179-
this.socket.send(JSON.stringify(payload));
164+
this.socket.send(audio);
180165
}
181166

182167
stream(): WritableStream<ArrayBufferLike> {

src/types/openapi.generated.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ export type LemurBaseParams = {
514514
}
515515
]
516516
>;
517+
/**
518+
* @description The model that is used for the final prompt after compression is performed.
519+
* Defaults to "default".
520+
*
521+
* @default default
522+
*/
517523
final_model?: LiteralUnion<LemurModel, string>;
518524
/**
519525
* @description Custom formatted transcript data. Maximum size is the context limit of the selected model, which defaults to 100000.
@@ -2305,6 +2311,8 @@ export type TranscriptOptionalParams = {
23052311
boost_param?: TranscriptBoostParam;
23062312
/** @description Enable [Content Moderation](https://www.assemblyai.com/docs/models/content-moderation), can be true or false */
23072313
content_safety?: boolean;
2314+
/** @description The confidence threshold for content moderation. Values must be between 25 and 100. */
2315+
content_safety_confidence?: number;
23082316
/** @description Customize how words are spelled and formatted using to and from values */
23092317
custom_spelling?: TranscriptCustomSpelling[];
23102318
/** @description Whether custom topics is enabled, either true or false */

tests/realtime.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,17 @@ describe("realtime", () => {
136136
it("can send audio", async () => {
137137
const data = new ArrayBuffer(8);
138138
rt.sendAudio(data);
139-
await expect(server).toReceiveMessage(
140-
JSON.stringify({ audio_data: Buffer.from(data).toString("base64") })
141-
);
139+
await expect(server).toReceiveMessage(data);
142140
});
143141

144142
it("can send audio using stream", async () => {
145143
const stream = new TransformStream<Buffer, Buffer>();
146144
const writer = stream.writable.getWriter();
147145
stream.readable.pipeTo(rt.stream());
148146
await writer.ready;
149-
writer.write(Buffer.alloc(5_000));
150-
await expect(server).toReceiveMessage(
151-
JSON.stringify({ audio_data: Buffer.alloc(5_000).toString("base64") })
152-
);
147+
const data = Buffer.alloc(5_000);
148+
writer.write(data);
149+
await expect(server).toReceiveMessage(data);
153150
});
154151

155152
it("can receive transcript", () => {

0 commit comments

Comments
 (0)