From f6827ac29d4614dd7297d4f221614e5b6b2f07e8 Mon Sep 17 00:00:00 2001 From: AssemblyAI Date: Fri, 12 Dec 2025 13:42:21 -0800 Subject: [PATCH] Project import generated by Copybara. GitOrigin-RevId: a0eae159e9cb154d0a58ae4b2934798427d3b086 --- CONTRIBUTING.md | 1 - docs/compat.md | 14 +++++++------- src/types/openapi.generated.ts | 18 ++++++++++++++---- tests/unit/language-detection-options.test.ts | 8 ++++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84a272d..8e491bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,7 +55,6 @@ TEST_TRANSCRIPT_IDS=... ## Generate types from OpenAPI and AsyncAPI spec 1. Configure the location of the OpenAPI and AsyncAPI spec as environment variables: - - `OPENAPI_SPEC`: Path or URL to the AssemblyAI OpenAPI spec - `ASYNCAPI_SPEC`: Path or URL to the AssemblyAI AsyncAPI spec diff --git a/docs/compat.md b/docs/compat.md index 9a4ca0e..7300c0c 100644 --- a/docs/compat.md +++ b/docs/compat.md @@ -13,8 +13,8 @@ If you do use an older version of Node.js like version 16, you'll need to polyfi To make the SDK compatible with the browser, the SDK aims to use web standards as much as possible. However, there are still incompatibilities between Node.js and the browser. -- `RealtimeTranscriber` doesn't support the AssemblyAI API key in the browser. - Instead, you have to generate a temporary auth token using `client.realtime.createTemporaryToken`, and pass in the resulting token to the real-time transcriber. +- `StreamingTranscriber` doesn't support the AssemblyAI API key in the browser. + Instead, you have to generate a temporary auth token using `client.streaming.createTemporaryToken`, and pass in the resulting token to the streaming transcriber. Generate a temporary auth token on the server. @@ -23,7 +23,7 @@ However, there are still incompatibilities between Node.js and the browser. // Ideally, to avoid embedding your API key client side, // you generate this token on the server, and pass it to the client via an API. const client = new AssemblyAI({ apiKey: "YOUR_API_KEY" }); - const token = await client.realtime.createTemporaryToken({ expires_in = 480 }); + const token = await client.streaming.createTemporaryToken({ expires_in_seconds: 60 }); ``` > [!NOTE] @@ -31,16 +31,16 @@ However, there are still incompatibilities between Node.js and the browser. > If you embed the API key on the client, everyone can see it and use it for themselves. Then pass the token via an API to the client. - On the client, create an instance of `RealtimeTranscriber` using the token. + On the client, create an instance of `StreamingTranscriber` using the token. ```js - import { RealtimeTranscriber } from "assemblyai"; + import { StreamingTranscriber } from "assemblyai"; // or the following if you're using UMD - // const { RealtimeTranscriber } = assemblyai; + // const { StreamingTranscriber } = assemblyai; const token = getToken(); // getToken is a function for you to implement - const rt = new RealtimeTranscriber({ + const rt = new StreamingTranscriber({ token: token, }); ``` diff --git a/src/types/openapi.generated.ts b/src/types/openapi.generated.ts index 2fda274..3843230 100644 --- a/src/types/openapi.generated.ts +++ b/src/types/openapi.generated.ts @@ -1670,6 +1670,16 @@ export type CodeSwitchingLanguage = { confidence: number; }; +/** + * Language detection results including code switching languages + */ +export type LanguageDetectionResults = { + /** + * List of detected languages with confidence scores when code switching is enabled + */ + code_switching_languages?: CodeSwitchingLanguage[] | null; +}; + /** * Options for controlling the behavior of Automatic Language Detection */ @@ -2742,10 +2752,6 @@ export type Transcript = { * List of language codes detected in the audio file when language detection is enabled */ language_codes: LiteralUnion[] | null; - /** - * List of detected languages with confidence scores when code switching is enabled - */ - code_switching_languages?: CodeSwitchingLanguage[] | null; /** * The confidence threshold for the automatically detected language. * An error will be returned if the language confidence is below this threshold. @@ -2755,6 +2761,10 @@ export type Transcript = { * Whether {@link https://www.assemblyai.com/docs/models/speech-recognition#automatic-language-detection | Automatic language detection } is enabled, either true or false */ language_detection?: boolean | null; + /** + * Language detection results including code switching languages + */ + language_detection_results?: LanguageDetectionResults | null; /** * @deprecated * The language model that was used for the transcript diff --git a/tests/unit/language-detection-options.test.ts b/tests/unit/language-detection-options.test.ts index 8189679..55e8398 100644 --- a/tests/unit/language-detection-options.test.ts +++ b/tests/unit/language-detection-options.test.ts @@ -167,7 +167,9 @@ describe("language detection options", () => { const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string); expect(requestBody.language_confidence_threshold).toBe(0.8); expect(requestBody.language_detection_options.fallback_language).toBe("en"); - expect(requestBody.language_detection_options.on_low_language_confidence).toBe("fallback"); + expect( + requestBody.language_detection_options.on_low_language_confidence, + ).toBe("fallback"); }); it("should create transcript with on_low_language_confidence set to error", async () => { @@ -193,6 +195,8 @@ describe("language detection options", () => { const requestBody = JSON.parse(fetchMock.mock.calls[0][1]?.body as string); expect(requestBody.language_confidence_threshold).toBe(0.7); expect(requestBody.language_detection_options.fallback_language).toBe("en"); - expect(requestBody.language_detection_options.on_low_language_confidence).toBe("error"); + expect( + requestBody.language_detection_options.on_low_language_confidence, + ).toBe("error"); }); });