Skip to content
Open
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.34.0",
"version": "4.34.3",
"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
12 changes: 11 additions & 1 deletion src/services/streaming/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export class StreamingTranscriber {
searchParams.set("prompt", this.params.prompt);
}

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

if (this.params.filterProfanity) {
searchParams.set(
"filter_profanity",
Expand All @@ -274,7 +278,9 @@ export class StreamingTranscriber {
"[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());
if (this.params.speechModel !== undefined) {
searchParams.set("speech_model", this.params.speechModel.toString());
}

if (this.params.languageDetection !== undefined) {
searchParams.set(
Expand Down Expand Up @@ -389,6 +395,10 @@ export class StreamingTranscriber {
searchParams.set("redact_pii_sub", this.params.redactPiiSub);
}

if (this.params.mode !== undefined) {
searchParams.set("mode", this.params.mode);
}

if (this.params.llmGateway !== undefined) {
searchParams.set("llm_gateway", JSON.stringify(this.params.llmGateway));
}
Expand Down
8 changes: 7 additions & 1 deletion src/types/streaming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export type StreamingTranscriberParams = {
keyterms?: string[];
keytermsPrompt?: string[];
prompt?: string;
speechModel: StreamingSpeechModel;
agentContext?: string;
speechModel?: StreamingSpeechModel;
languageDetection?: boolean;
domain?: StreamingDomain;
inactivityTimeout?: number;
Expand All @@ -107,6 +108,7 @@ export type StreamingTranscriberParams = {
redactPii?: boolean;
redactPiiPolicies?: StreamingPiiPolicy[];
redactPiiSub?: StreamingPiiSubstitution;
mode?: StreamingMode;
llmGateway?: LLMGatewayConfig;
webhookUrl?: string;
webhookAuthHeaderName?: string;
Expand Down Expand Up @@ -165,11 +167,14 @@ export type StreamingSpeechModel =
| "universal-streaming-english"
| "universal-streaming-multilingual"
| "u3-rt-pro"
| "u3-rt-pro-beta-1"
| "whisper-rt"
| "u3-pro";

export type StreamingDomain = "medical-v1";

export type StreamingMode = "max_accuracy" | "min_latency" | "balanced";

export type VoiceFocusModel = "near-field" | "far-field";

export type StreamingPiiSubstitution = "hash" | "entity_name";
Expand Down Expand Up @@ -330,6 +335,7 @@ export type StreamingUpdateConfiguration = {
format_turns?: boolean;
keyterms_prompt?: string[];
prompt?: string;
agent_context?: string;
filter_profanity?: boolean;
interruption_delay?: number;
turn_left_pad_ms?: number;
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/streaming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,37 @@ describe("streaming", () => {
);
});

it("should include agent_context in updateConfiguration message", async () => {
rt.updateConfiguration({ agent_context: "What is your account number?" });
await expect(server).toReceiveMessage(
JSON.stringify({
type: "UpdateConfiguration",
agent_context: "What is your account number?",
}),
);
});

it("should include agent_context in connection URL", async () => {
await cleanup();
WS.clean();

const wsUrl =
`${websocketBaseUrl}?token=123&sample_rate=16000` +
`&agent_context=${encodeURIComponent("What is your account number?")}` +
`&speech_model=u3-rt-pro`;
server = new WS(wsUrl);
rt = new StreamingTranscriber({
websocketBaseUrl,
token: "123",
sampleRate: 16_000,
speechModel: "u3-rt-pro",
agentContext: "What is your account number?",
});
onOpen = jest.fn();
rt.on("open", onOpen);
await connect(rt, server);
});

it("should include turn_left_pad_ms in connection URL", async () => {
await cleanup();
WS.clean();
Expand Down Expand Up @@ -254,6 +285,24 @@ describe("streaming", () => {
await connect(rt, server);
});

it("should include mode in connection URL", async () => {
await cleanup();
WS.clean();

const wsUrl = `${websocketBaseUrl}?token=123&sample_rate=16000&speech_model=u3-rt-pro&mode=max_accuracy`;
server = new WS(wsUrl);
rt = new StreamingTranscriber({
websocketBaseUrl,
token: "123",
sampleRate: 16_000,
speechModel: "u3-rt-pro",
mode: "max_accuracy",
});
onOpen = jest.fn();
rt.on("open", onOpen);
await connect(rt, server);
});

it("should include whisper-rt speech model in connection URL", async () => {
await cleanup();
WS.clean();
Expand Down
Loading