assemblyai 4.33.2 → 4.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/assemblyai.streaming.umd.js +1279 -3
  2. package/dist/assemblyai.streaming.umd.min.js +1 -1
  3. package/dist/assemblyai.umd.js +789 -3
  4. package/dist/assemblyai.umd.min.js +1 -1
  5. package/dist/browser.mjs +765 -4
  6. package/dist/bun.mjs +765 -4
  7. package/dist/deno.mjs +765 -4
  8. package/dist/exports/streaming.d.ts +7 -0
  9. package/dist/index.cjs +789 -3
  10. package/dist/index.mjs +781 -4
  11. package/dist/node.cjs +773 -3
  12. package/dist/node.mjs +765 -4
  13. package/dist/services/index.d.ts +2 -2
  14. package/dist/services/streaming/browser/dual-channel-capture.d.ts +66 -0
  15. package/dist/services/streaming/browser/worklets/pcm16-encoder.d.ts +19 -0
  16. package/dist/services/streaming/energy-vad.d.ts +35 -0
  17. package/dist/services/streaming/index.d.ts +4 -0
  18. package/dist/services/streaming/label-mapper.d.ts +44 -0
  19. package/dist/services/streaming/resampler.d.ts +22 -0
  20. package/dist/services/streaming/service.d.ts +69 -1
  21. package/dist/streaming.browser.mjs +1235 -4
  22. package/dist/streaming.cjs +1275 -3
  23. package/dist/streaming.mjs +1264 -4
  24. package/dist/types/streaming/dual-channel.d.ts +48 -0
  25. package/dist/types/streaming/index.d.ts +112 -1
  26. package/dist/workerd.mjs +765 -4
  27. package/package.json +1 -1
  28. package/src/exports/streaming.ts +7 -0
  29. package/src/services/index.ts +20 -1
  30. package/src/services/streaming/browser/dual-channel-capture.ts +177 -0
  31. package/src/services/streaming/browser/worklets/pcm16-encoder.ts +70 -0
  32. package/src/services/streaming/energy-vad.ts +75 -0
  33. package/src/services/streaming/index.ts +4 -0
  34. package/src/services/streaming/label-mapper.ts +128 -0
  35. package/src/services/streaming/resampler.ts +69 -0
  36. package/src/services/streaming/service.ts +392 -2
  37. package/src/types/streaming/dual-channel.ts +57 -0
  38. package/src/types/streaming/index.ts +112 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Physical input channel that a word/turn was attributed to.
3
+ * - A channel name declared in `StreamingTranscriberParams.channels` (e.g. `"mic"`, `"system"`).
4
+ * - `"unknown"`: no channel was clearly dominant during the word's time window (silent
5
+ * or all channels evenly active under our threshold).
6
+ *
7
+ * This is independent of AssemblyAI's diarization `speaker_label` / `words[i].speaker`,
8
+ * which identifies voices by acoustic characteristics. A given speaker_label can map
9
+ * to any physical channel; the two dimensions can disagree.
10
+ */
11
+ export type Channel = string | "unknown";
12
+ /**
13
+ * Per-channel, per-frame VAD observation emitted by `StreamingTranscriber` when running
14
+ * in dual-channel mode. `ts` is stream-relative milliseconds, derived from the
15
+ * per-channel sample counter — the same reference frame as `StreamingWord.start` /
16
+ * `.end`, so per-word lookups need no conversion.
17
+ */
18
+ export type VadFrame = {
19
+ ts: number;
20
+ channel: string;
21
+ active: boolean;
22
+ rms: number;
23
+ };
24
+ export type VadDetectorResult = {
25
+ active: boolean;
26
+ energy: number;
27
+ };
28
+ /**
29
+ * Pluggable per-channel voice-activity detector. The default `EnergyVad` is energy-based
30
+ * with an adaptive noise-floor threshold; callers can drop in a DNN-backed detector
31
+ * (e.g. Silero via `@ricky0123/vad-web`) for noisier environments.
32
+ *
33
+ * A separate `VadDetector` instance is held per channel; do not assume cross-channel
34
+ * state. Frames are fixed-size at the transcriber's target sample rate.
35
+ */
36
+ export interface VadDetector {
37
+ process(frame: Float32Array): VadDetectorResult;
38
+ reset(): void;
39
+ }
40
+ /**
41
+ * Thrown when `DualChannelCapture` is constructed in a non-browser environment
42
+ * (no `globalThis.AudioContext`). The helper is intentionally surfaced from the
43
+ * main entrypoint so the import path is uniform across runtimes; the runtime
44
+ * guard moves to construction time.
45
+ */
46
+ export declare class BrowserOnlyError extends Error {
47
+ constructor(message?: string);
48
+ }
@@ -1,4 +1,63 @@
1
1
  import { AudioEncoding } from "..";
2
+ import type { Channel, VadDetector, VadFrame } from "./dual-channel";
3
+ export * from "./dual-channel";
4
+ /**
5
+ * Per-channel attribution tuning for dual-channel mode. All fields optional;
6
+ * ignored when `StreamingTranscriberParams.channels` is not set.
7
+ */
8
+ export type ChannelAttributionParams = {
9
+ /** Energy ratio above which a channel is declared dominant for a word. Default 4. */
10
+ dominanceRatio?: number;
11
+ /** Rolling VAD timeline window in ms. Default 30_000. */
12
+ timelineWindowMs?: number;
13
+ /**
14
+ * Factory for the per-channel VAD detector. Called once per declared channel
15
+ * at transcriber construction time. The channel name is passed so factories
16
+ * that wrap higher-level VAD libraries (which manage their own audio source)
17
+ * can map each `VadDetector` instance to its corresponding channel.
18
+ */
19
+ createVad?: (channelName: string) => VadDetector;
20
+ /** Mix flush interval in ms — how often per-channel buffers are summed and sent. Default 50. */
21
+ flushIntervalMs?: number;
22
+ /**
23
+ * Strategy used to fill words whose per-word VAD attribution resolved to
24
+ * `"unknown"`. Confident per-word VAD decisions (`"mic"` / `"system"`) are
25
+ * never modified by any strategy.
26
+ *
27
+ * - `"window"` (default): look at the dominant non-`"unknown"` channel
28
+ * among ±`resolutionWindowWords` neighboring words in the same turn.
29
+ * Ignores `speaker_label`, so it works even when AAI re-uses a label for
30
+ * two physically distinct voices.
31
+ * - `"speaker-history"`: accumulate per-`speaker_label` per-channel active
32
+ * VAD energy across the session, then fill `"unknown"` words with the
33
+ * speaker's dominant channel when it clears
34
+ * `speakerHistoryMinRmsEvidence` and beats runner-up by
35
+ * `speakerHistoryDominanceRatio`. Robust for stable speaker labels but
36
+ * does nothing when a speaker has split evidence.
37
+ * - `"none"`: disable resolution; `"unknown"` words remain `"unknown"` in
38
+ * the output.
39
+ */
40
+ resolveUnknownChannelsMethod?: "none" | "window" | "speaker-history";
41
+ /**
42
+ * Half-window (in words) on each side of an `"unknown"` word for the
43
+ * `"window"` method. Default 2 — so the full window is up to 5 words
44
+ * (2 before + the unknown + 2 after).
45
+ */
46
+ resolutionWindowWords?: number;
47
+ /**
48
+ * Minimum cumulative active-RMS evidence (sum across all the speaker's
49
+ * frames to date) before a speaker can be resolved via the
50
+ * `"speaker-history"` method. Default 0.5 — roughly a few seconds of
51
+ * sustained speech.
52
+ */
53
+ speakerHistoryMinRmsEvidence?: number;
54
+ /**
55
+ * For the `"speaker-history"` method, the top channel's evidence must
56
+ * exceed the runner-up's by at least this factor for the speaker to be
57
+ * considered pinned to that channel. Default 3.
58
+ */
59
+ speakerHistoryDominanceRatio?: number;
60
+ };
2
61
  export type LLMGatewayMessage = {
3
62
  role: string;
4
63
  content: string;
@@ -37,6 +96,7 @@ export type StreamingTranscriberParams = {
37
96
  voiceFocusThreshold?: number;
38
97
  continuousPartials?: boolean;
39
98
  interruptionDelay?: number;
99
+ turnLeftPadMs?: number;
40
100
  customerSupportAudioCapture?: boolean;
41
101
  includePartialTurns?: boolean;
42
102
  redactPii?: boolean;
@@ -46,8 +106,37 @@ export type StreamingTranscriberParams = {
46
106
  webhookUrl?: string;
47
107
  webhookAuthHeaderName?: string;
48
108
  webhookAuthHeaderValue?: string;
109
+ /**
110
+ * Enable dual-channel (or N-channel) mode. Presence of `channels` switches the
111
+ * transcriber into channel-tagged mode: `sendAudio(audio, { channel })` is required,
112
+ * per-channel VAD runs on the raw PCM, the streams are mixed to mono before being
113
+ * sent to the server, and emitted `TurnEvent`s are enriched with `channel` and
114
+ * per-word `channel` attribution.
115
+ *
116
+ * Must contain exactly 2 entries with unique names. The names are echoed back in
117
+ * `TurnEvent.channel` / `words[i].channel`.
118
+ *
119
+ * **Acoustic-leak caveat.** Per-word channel attribution uses energy-based
120
+ * VAD on each channel. If your capture setup lets one channel's audio bleed
121
+ * into another at similar amplitude — typically system audio playing
122
+ * through speakers and being picked up by an open mic — attribution can
123
+ * misfire (mic-tagged words that were actually system). Transcription
124
+ * quality is unaffected; only the `channel` field is. To preserve
125
+ * attribution in speaker-leak setups, apply echo cancellation at capture
126
+ * before feeding audio to the SDK. In browsers, that's
127
+ * `getUserMedia({ audio: { echoCancellation: true } })`. On macOS native,
128
+ * `AVAudioEngine.setVoiceProcessingEnabled(true)` on the input node. If
129
+ * platform-level AEC isn't available, swap in a DNN VAD (e.g. Silero) via
130
+ * `channelAttribution.createVad`. See the dual-channel sample app's
131
+ * README for worked examples.
132
+ */
133
+ channels?: Array<{
134
+ name: string;
135
+ }>;
136
+ /** Tuning for dual-channel attribution. Ignored when `channels` is unset. */
137
+ channelAttribution?: ChannelAttributionParams;
49
138
  };
50
- export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "warning" | "error";
139
+ export type StreamingEvents = "open" | "close" | "turn" | "speechStarted" | "llmGatewayResponse" | "warning" | "vad" | "error";
51
140
  export type StreamingListeners = {
52
141
  open?: (event: BeginEvent) => void;
53
142
  close?: (code: number, reason: string) => void;
@@ -55,6 +144,7 @@ export type StreamingListeners = {
55
144
  speechStarted?: (event: SpeechStartedEvent) => void;
56
145
  llmGatewayResponse?: (event: LLMGatewayResponseEvent) => void;
57
146
  warning?: (event: WarningEvent) => void;
147
+ vad?: (event: VadFrame) => void;
58
148
  error?: (error: Error) => void;
59
149
  };
60
150
  export type StreamingSpeechModel = "universal-streaming-english" | "universal-streaming-multilingual" | "u3-rt-pro" | "whisper-rt" | "u3-pro";
@@ -90,6 +180,12 @@ export type TurnEvent = {
90
180
  language_code?: string;
91
181
  language_confidence?: number;
92
182
  speaker_label?: string;
183
+ /**
184
+ * Duration-weighted majority channel across `words[i].channel`. Populated only
185
+ * when the transcriber is configured with `channels`. Independent from
186
+ * `speaker_label`.
187
+ */
188
+ channel?: Channel;
93
189
  };
94
190
  export type StreamingWord = {
95
191
  start: number;
@@ -98,6 +194,20 @@ export type StreamingWord = {
98
194
  text: string;
99
195
  word_is_final: boolean;
100
196
  speaker?: string;
197
+ /**
198
+ * Physical input channel attributed by client-side VAD during this word's
199
+ * time window. Populated only when the transcriber is configured with
200
+ * `channels`. Independent from `speaker`.
201
+ */
202
+ channel?: Channel;
203
+ /**
204
+ * True if `channel` was filled in by `channelAttribution.resolveUnknownChannelsMethod`
205
+ * rather than by the per-word VAD. Only set on words whose per-word VAD
206
+ * attribution was `"unknown"` and whose resolution method produced a
207
+ * confident channel. Useful for debugging or rendering an indicator that a
208
+ * word's channel came from context, not direct VAD evidence.
209
+ */
210
+ channelResolved?: boolean;
101
211
  };
102
212
  export type TerminationEvent = {
103
213
  type: "Termination";
@@ -122,6 +232,7 @@ export type StreamingUpdateConfiguration = {
122
232
  prompt?: string;
123
233
  filter_profanity?: boolean;
124
234
  interruption_delay?: number;
235
+ turn_left_pad_ms?: number;
125
236
  };
126
237
  export type StreamingForceEndpoint = {
127
238
  type: "ForceEndpoint";