Skip to content

Commit a26f7da

Browse files
authored
Merge pull request #116 from AssemblyAI/EA17A79D514289B819B9AE7C9AB1132F
Sync from internal repo (2025/11/05)
2 parents 2df9063 + 792fd93 commit a26f7da

File tree

3 files changed

+174
-2
lines changed

3 files changed

+174
-2
lines changed

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.18.5",
3+
"version": "4.19.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/types/openapi.generated.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,20 @@ export type SpeakerOptions = {
16561656
max_speakers_expected?: number | null;
16571657
};
16581658

1659+
/**
1660+
* Code switching language detection result
1661+
*/
1662+
export type CodeSwitchingLanguage = {
1663+
/**
1664+
* The language code detected
1665+
*/
1666+
language_code: string;
1667+
/**
1668+
* The confidence score for this language detection, between 0.0 and 1.0
1669+
*/
1670+
confidence: number;
1671+
};
1672+
16591673
/**
16601674
* Options for controlling the behavior of Automatic Language Detection
16611675
*/
@@ -1668,6 +1682,14 @@ export type LanguageDetectionOptions = {
16681682
* The language to fallback to in case the language detection does not predict any of the expected ones.
16691683
*/
16701684
fallback_language?: string | null;
1685+
/**
1686+
* Should code switching be enabled for this transcription.
1687+
*/
1688+
code_switching?: boolean | null;
1689+
/**
1690+
* The confidence threshold for the automatically detected code switching language.
1691+
*/
1692+
code_switching_confidence_threshold?: number | null;
16711693
};
16721694

16731695
/**
@@ -2716,6 +2738,10 @@ export type Transcript = {
27162738
* List of language codes detected in the audio file when language detection is enabled
27172739
*/
27182740
language_codes: LiteralUnion<TranscriptLanguageCode, string>[] | null;
2741+
/**
2742+
* List of detected languages with confidence scores when code switching is enabled
2743+
*/
2744+
code_switching_languages?: CodeSwitchingLanguage[] | null;
27192745
/**
27202746
* The confidence threshold for the automatically detected language.
27212747
* An error will be returned if the language confidence is below this threshold.
@@ -3270,7 +3296,7 @@ export type TranscriptOptionalParams = {
32703296
/**
32713297
* Options for controlling the behavior of Automatic Language Detection
32723298
*/
3273-
language_detection_options?: LanguageDetectionOptions;
3299+
language_detection_options?: LanguageDetectionOptions | null;
32743300
/**
32753301
* Enable {@link https://www.assemblyai.com/docs/models/speech-recognition#multichannel-transcription | Multichannel } transcription, can be true or false.
32763302
* @defaultValue false
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import fetchMock from "jest-fetch-mock";
2+
import { LanguageDetectionOptions } from "../../src";
3+
import { createClient, requestMatches } from "./utils";
4+
5+
fetchMock.enableMocks();
6+
7+
const assembly = createClient();
8+
const transcriptId = "transcript_123";
9+
const remoteAudioURL = "https://assembly.ai/espn.m4a";
10+
11+
beforeEach(() => {
12+
jest.clearAllMocks();
13+
fetchMock.resetMocks();
14+
fetchMock.doMock();
15+
});
16+
17+
describe("language detection options", () => {
18+
it("should create transcript with all language_detection_options", async () => {
19+
const languageDetectionOptions: LanguageDetectionOptions = {
20+
expected_languages: ["en", "es"],
21+
fallback_language: "en",
22+
code_switching: true,
23+
code_switching_confidence_threshold: 0.8,
24+
};
25+
26+
fetchMock.doMockOnceIf(
27+
requestMatches({ url: "/v2/transcript", method: "POST" }),
28+
JSON.stringify({ id: transcriptId, status: "queued" }),
29+
);
30+
31+
const transcript = await assembly.transcripts.submit({
32+
audio_url: remoteAudioURL,
33+
language_detection: true,
34+
language_detection_options: languageDetectionOptions,
35+
});
36+
37+
expect(transcript.id).toBe(transcriptId);
38+
expect(transcript.status).toBe("queued");
39+
40+
// Verify the request body included language_detection_options
41+
const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string);
42+
expect(requestBody.language_detection).toBe(true);
43+
expect(requestBody.language_detection_options).toEqual(
44+
languageDetectionOptions,
45+
);
46+
});
47+
48+
it("should create transcript with only code_switching enabled", async () => {
49+
const languageDetectionOptions: LanguageDetectionOptions = {
50+
code_switching: true,
51+
};
52+
53+
fetchMock.doMockOnceIf(
54+
requestMatches({ url: "/v2/transcript", method: "POST" }),
55+
JSON.stringify({ id: transcriptId, status: "queued" }),
56+
);
57+
58+
const transcript = await assembly.transcripts.submit({
59+
audio_url: remoteAudioURL,
60+
language_detection: true,
61+
language_detection_options: languageDetectionOptions,
62+
});
63+
64+
expect(transcript.id).toBe(transcriptId);
65+
66+
const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string);
67+
expect(requestBody.language_detection_options.code_switching).toBe(true);
68+
expect(
69+
requestBody.language_detection_options
70+
.code_switching_confidence_threshold,
71+
).toBeUndefined();
72+
});
73+
74+
it("should create transcript with code_switching and confidence threshold", async () => {
75+
const languageDetectionOptions: LanguageDetectionOptions = {
76+
code_switching: true,
77+
code_switching_confidence_threshold: 0.75,
78+
};
79+
80+
fetchMock.doMockOnceIf(
81+
requestMatches({ url: "/v2/transcript", method: "POST" }),
82+
JSON.stringify({ id: transcriptId, status: "queued" }),
83+
);
84+
85+
const transcript = await assembly.transcripts.submit({
86+
audio_url: remoteAudioURL,
87+
language_detection: true,
88+
language_detection_options: languageDetectionOptions,
89+
});
90+
91+
expect(transcript.id).toBe(transcriptId);
92+
93+
const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string);
94+
expect(requestBody.language_detection_options.code_switching).toBe(true);
95+
expect(
96+
requestBody.language_detection_options
97+
.code_switching_confidence_threshold,
98+
).toBe(0.75);
99+
});
100+
101+
it("should create transcript with only confidence threshold", async () => {
102+
const languageDetectionOptions: LanguageDetectionOptions = {
103+
code_switching_confidence_threshold: 0.9,
104+
};
105+
106+
fetchMock.doMockOnceIf(
107+
requestMatches({ url: "/v2/transcript", method: "POST" }),
108+
JSON.stringify({ id: transcriptId, status: "queued" }),
109+
);
110+
111+
const transcript = await assembly.transcripts.submit({
112+
audio_url: remoteAudioURL,
113+
language_detection: true,
114+
language_detection_options: languageDetectionOptions,
115+
});
116+
117+
expect(transcript.id).toBe(transcriptId);
118+
119+
const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string);
120+
expect(
121+
requestBody.language_detection_options.code_switching,
122+
).toBeUndefined();
123+
expect(
124+
requestBody.language_detection_options
125+
.code_switching_confidence_threshold,
126+
).toBe(0.9);
127+
});
128+
129+
it("should handle null language_detection_options", async () => {
130+
fetchMock.doMockOnceIf(
131+
requestMatches({ url: "/v2/transcript", method: "POST" }),
132+
JSON.stringify({ id: transcriptId, status: "queued" }),
133+
);
134+
135+
const transcript = await assembly.transcripts.submit({
136+
audio_url: remoteAudioURL,
137+
language_detection: true,
138+
language_detection_options: null,
139+
});
140+
141+
expect(transcript.id).toBe(transcriptId);
142+
143+
const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string);
144+
expect(requestBody.language_detection_options).toBe(null);
145+
});
146+
});

0 commit comments

Comments
 (0)