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
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions docs/compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -23,24 +23,24 @@ 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]
> We recommend generating the token on the server, so you don't embed your AssemblyAI API key in your client app.
> 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,
});
```
Expand Down
18 changes: 14 additions & 4 deletions src/types/openapi.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -2742,10 +2752,6 @@ export type Transcript = {
* List of language codes detected in the audio file when language detection is enabled
*/
language_codes: LiteralUnion<TranscriptLanguageCode, string>[] | 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.
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/language-detection-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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");
});
});
Loading