-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathinterruption_cache_entry.ts
More file actions
47 lines (43 loc) · 1.39 KB
/
interruption_cache_entry.ts
File metadata and controls
47 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { estimateProbability } from './utils.js';
/**
* Typed cache entry for interruption inference results.
* Mutable to support setOrUpdate pattern from Python's _BoundedCache.
*/
export class InterruptionCacheEntry {
createdAt: number;
totalDurationInS: number;
predictionDurationInS: number;
detectionDelayInS: number;
speechInput?: Int16Array;
probabilities?: number[];
isInterruption?: boolean;
constructor(params: {
createdAt: number;
speechInput?: Int16Array;
totalDurationInS?: number;
predictionDurationInS?: number;
detectionDelayInS?: number;
probabilities?: number[];
isInterruption?: boolean;
}) {
this.createdAt = params.createdAt;
this.totalDurationInS = params.totalDurationInS ?? 0;
this.predictionDurationInS = params.predictionDurationInS ?? 0;
this.detectionDelayInS = params.detectionDelayInS ?? 0;
this.speechInput = params.speechInput;
this.probabilities = params.probabilities;
this.isInterruption = params.isInterruption;
}
/**
* The conservative estimated probability of the interruption event.
*/
get probability(): number {
return this.probabilities ? estimateProbability(this.probabilities) : 0;
}
static default(): InterruptionCacheEntry {
return new InterruptionCacheEntry({ createdAt: 0 });
}
}