Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "assemblyai",
"version": "4.23.1",
"version": "4.24.0",
"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.",
"engines": {
"node": ">=18"
Expand Down
43 changes: 42 additions & 1 deletion src/services/streaming/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
BeginEvent,
StreamingEventMessage,
TurnEvent,
StreamingUpdateConfiguration,
StreamingForceEndpoint,
} from "../..";
import { StreamingError, StreamingErrorMessages } from "../../utils/errors";
import { StreamingErrorTypeCodes } from "../../utils/errors/streaming";
Expand Down Expand Up @@ -83,7 +85,15 @@ export class StreamingTranscriber {
);
}

if (this.params.minEndOfTurnSilenceWhenConfident) {
if (this.params.minTurnSilence) {
searchParams.set(
"min_turn_silence",
this.params.minTurnSilence.toString(),
);
} else if (this.params.minEndOfTurnSilenceWhenConfident) {
console.warn(
"[Deprecation Warning] `minEndOfTurnSilenceWhenConfident` is deprecated and will be removed in a future release. Please use `minTurnSilence` instead.",
);
searchParams.set(
"min_end_of_turn_silence_when_confident",
this.params.minEndOfTurnSilenceWhenConfident.toString(),
Expand Down Expand Up @@ -121,6 +131,10 @@ export class StreamingTranscriber {
searchParams.set("keyterms_prompt", JSON.stringify(this.params.keyterms));
}

if (this.params.prompt) {
searchParams.set("prompt", this.params.prompt);
}

if (this.params.filterProfanity) {
searchParams.set(
"filter_profanity",
Expand All @@ -129,6 +143,11 @@ export class StreamingTranscriber {
}

if (this.params.speechModel) {
if (this.params.speechModel === "u3-pro") {
console.warn(
"[Deprecation Warning] The speech model `u3-pro` is deprecated and will be removed in a future release. Please use `u3-rt-pro` instead.",
);
}
searchParams.set("speech_model", this.params.speechModel.toString());
}

Expand Down Expand Up @@ -240,6 +259,28 @@ Learn more at https://github.com/AssemblyAI/assemblyai-node-sdk/blob/main/docs/c
this.send(audio);
}

/**
* Update the streaming configuration mid-stream.
* @param config - The configuration parameters to update
*/
updateConfiguration(config: Omit<StreamingUpdateConfiguration, "type">) {
const message: StreamingUpdateConfiguration = {
type: "UpdateConfiguration",
...config,
};
this.send(JSON.stringify(message));
}

/**
* Force the current turn to end immediately.
*/
forceEndpoint() {
const message: StreamingForceEndpoint = {
type: "ForceEndpoint",
};
this.send(JSON.stringify(message));
}

private send(data: BufferLike) {
if (!this.socket || this.socket.readyState !== this.socket.OPEN) {
throw new Error("Socket is not open for communication");
Expand Down
16 changes: 15 additions & 1 deletion src/types/streaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ export type StreamingTranscriberParams = {
sampleRate: number;
encoding?: AudioEncoding;
endOfTurnConfidenceThreshold?: number;
/**
* @deprecated Use `minTurnSilence` instead. This parameter will be removed in a future release.
*/
minEndOfTurnSilenceWhenConfident?: number;
minTurnSilence?: number;
maxTurnSilence?: number;
vadThreshold?: number;
formatTurns?: boolean;
filterProfanity?: boolean;
keyterms?: string[];
keytermsPrompt?: string[];
prompt?: string;
speechModel?: StreamingSpeechModel;
languageDetection?: boolean;
inactivityTimeout?: number;
Expand All @@ -30,7 +35,9 @@ export type StreamingListeners = {

export type StreamingSpeechModel =
| "universal-streaming-english"
| "universal-streaming-multilingual";
| "universal-streaming-multilingual"
| "u3-rt-pro"
| "u3-pro";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include the deprecated u3-pro attribute here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly maybe not, I should probably remove that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to keep it temporarily for the python one though b/c a customer is using it


export type StreamingTokenParams = {
expires_in_seconds: number;
Expand Down Expand Up @@ -82,10 +89,17 @@ export type StreamingTerminateSession = {
export type StreamingUpdateConfiguration = {
type: "UpdateConfiguration";
end_of_turn_confidence_threshold?: number;
/**
* @deprecated Use `min_turn_silence` instead. This parameter will be removed in a future release.
*/
min_end_of_turn_silence_when_confident?: number;
min_turn_silence?: number;
max_turn_silence?: number;
vad_threshold?: number;
format_turns?: boolean;
keyterms_prompt?: string[];
prompt?: string;
filter_profanity?: boolean;
};

export type StreamingForceEndpoint = {
Expand Down