ttp-agent-sdk 2.48.12 → 2.48.16
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.
- package/dist/agent-widget.dev.js +212 -29
- package/dist/agent-widget.esm.js +1 -1
- package/dist/agent-widget.js +1 -1
- package/dist/audio-processor.js +41 -3
- package/dist/index.html +1 -1
- package/package.json +1 -1
package/dist/audio-processor.js
CHANGED
|
@@ -19,10 +19,23 @@ class AudioProcessor extends AudioWorkletProcessor {
|
|
|
19
19
|
this.bufferIndex = 0;
|
|
20
20
|
|
|
21
21
|
// VAD (Voice Activity Detection) parameters
|
|
22
|
-
this.silenceThreshold = 0.02; // RMS threshold for voice detection (
|
|
22
|
+
this.silenceThreshold = 0.02; // Base RMS threshold for voice detection (scaled by micSensitivity below)
|
|
23
23
|
this.VOICE_FRAMES_REQUIRED = 2; // Require 2 consecutive frames above threshold before activating
|
|
24
24
|
this.minVoiceDuration = 100; // ms - minimum speech duration
|
|
25
25
|
this.pauseThreshold = 3000; // ms - longer pause before processing
|
|
26
|
+
|
|
27
|
+
// Mic sensitivity: user/agent-adjustable multiplier on the VAD energy gate.
|
|
28
|
+
// 1.0 = default; 2.0 = twice as sensitive (half the RMS floor); 0.5 = half as
|
|
29
|
+
// sensitive (double the floor — only close/loud speech triggers, e.g. TV in the room).
|
|
30
|
+
this.micSensitivity = (typeof this.config.micSensitivity === 'number' && this.config.micSensitivity > 0)
|
|
31
|
+
? this.config.micSensitivity : 1.0;
|
|
32
|
+
// While agent audio plays, the gate rises by this factor (stricter barge-in: background
|
|
33
|
+
// TV/chatter must not interrupt playback). The SDK main thread tracks playback state.
|
|
34
|
+
this.playbackActive = false;
|
|
35
|
+
this.PLAYBACK_GATE_FACTOR = 1.6;
|
|
36
|
+
// Hysteresis: once voice is active the floor drops, so a borderline signal isn't
|
|
37
|
+
// chopped on every frame (quiet speech tails stay under the trigger level).
|
|
38
|
+
this.HYSTERESIS_FACTOR = 0.75;
|
|
26
39
|
|
|
27
40
|
// VAD state
|
|
28
41
|
this.isVoiceActive = false;
|
|
@@ -75,6 +88,18 @@ class AudioProcessor extends AudioWorkletProcessor {
|
|
|
75
88
|
// iOS: bypass client VAD - always send. Desktop: keep VAD (saves bandwidth, reduces noise).
|
|
76
89
|
this.isCurrentlyStreaming = data.enabled && (data.bypassVad === true);
|
|
77
90
|
break;
|
|
91
|
+
|
|
92
|
+
case 'setMicSensitivity': {
|
|
93
|
+
const v = Number(data && data.value);
|
|
94
|
+
if (isFinite(v) && v > 0) {
|
|
95
|
+
this.micSensitivity = Math.max(0.25, Math.min(4.0, v));
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case 'setPlaybackActive':
|
|
101
|
+
this.playbackActive = !!(data && data.active);
|
|
102
|
+
break;
|
|
78
103
|
|
|
79
104
|
case 'flush':
|
|
80
105
|
this.flushBuffer();
|
|
@@ -157,9 +182,22 @@ class AudioProcessor extends AudioWorkletProcessor {
|
|
|
157
182
|
const highFreqRatio = highFreqCount / this.bufferSize;
|
|
158
183
|
|
|
159
184
|
const currentTime = Date.now();
|
|
160
|
-
|
|
185
|
+
|
|
186
|
+
// Effective VAD floor: base threshold scaled by the mic-sensitivity multiplier —
|
|
187
|
+
// QUADRATIC below 1.0 so the strict end actually bites (0.5 → 0.08 floor, not
|
|
188
|
+
// 0.04: a linear ±6dB band is imperceptible, and browser AGC flattens level
|
|
189
|
+
// differences before we see them). Raised during agent playback (stricter
|
|
190
|
+
// barge-in), lowered while voice is already active (hysteresis, so speech
|
|
191
|
+
// tails aren't clipped).
|
|
192
|
+
const sens = this.micSensitivity;
|
|
193
|
+
let effectiveThreshold = sens >= 1
|
|
194
|
+
? this.silenceThreshold / sens
|
|
195
|
+
: this.silenceThreshold / (sens * sens);
|
|
196
|
+
if (this.playbackActive) effectiveThreshold *= this.PLAYBACK_GATE_FACTOR;
|
|
197
|
+
if (this.isVoiceActive) effectiveThreshold *= this.HYSTERESIS_FACTOR;
|
|
198
|
+
|
|
161
199
|
// VAD with reduced sensitivity - require consecutive frames above threshold
|
|
162
|
-
let hasVoice = rms >
|
|
200
|
+
let hasVoice = rms > effectiveThreshold;
|
|
163
201
|
// Calculate time since last voice detection
|
|
164
202
|
const timeSinceLastVoice = currentTime - this.lastVoiceTime;
|
|
165
203
|
|
package/dist/index.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<img src="https://talktopc.com/logo192.png" alt="TTP Logo" style="width: 40px; height: 40px; border-radius: 8px;">
|
|
24
24
|
<div>
|
|
25
25
|
<h1 style="margin: 0; font-size: 1.4rem;">TTP Agent SDK</h1>
|
|
26
|
-
<p class="version" style="margin: 0;">v2.48.
|
|
26
|
+
<p class="version" style="margin: 0;">v2.48.15</p>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
29
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttp-agent-sdk",
|
|
3
|
-
"version": "2.48.
|
|
3
|
+
"version": "2.48.16",
|
|
4
4
|
"description": "Comprehensive Voice Agent SDK with Customizable Widget - Real-time audio, WebSocket communication, React components, and extensive customization options",
|
|
5
5
|
"main": "dist/agent-widget.js",
|
|
6
6
|
"module": "dist/agent-widget.esm.js",
|