@telnyx/ai-agent-widget 0.30.0 → 0.31.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.
- package/README.md +77 -0
- package/dist/bundle.min.js +22 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,6 +23,83 @@ You can customize the call options by adding attributes to the `<telnyx-ai-agent
|
|
|
23
23
|
- [`call-custom-headers`](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#customheaders)
|
|
24
24
|
- [`call-audio`](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#audio)
|
|
25
25
|
|
|
26
|
+
### VAD (Voice Activity Detection) Options
|
|
27
|
+
|
|
28
|
+
Configure Voice Activity Detection for speech detection and latency measurement by passing a JSON object to the `vad` attribute:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<telnyx-ai-agent
|
|
32
|
+
agent-id="assistant-xxx"
|
|
33
|
+
vad='{"volumeThreshold": 10, "silenceDurationMs": 500, "minSpeechDurationMs": 100}'
|
|
34
|
+
></telnyx-ai-agent>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Available VAD options:**
|
|
38
|
+
|
|
39
|
+
| Option | Type | Default | Description |
|
|
40
|
+
| --------------------- | -------- | ----------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `volumeThreshold` | `number` | `10` | Volume threshold (0-255) for detecting speech. Audio levels above this value are considered speech. |
|
|
42
|
+
| `silenceDurationMs` | `number` | `1000` | Duration of silence (ms) before triggering "thinking" state. Lower values = faster response but may cut off natural pauses. |
|
|
43
|
+
| `minSpeechDurationMs` | `number` | `100` | Minimum speech duration (ms) to count as real user speech. Filters out brief noise spikes. |
|
|
44
|
+
| `maxLatencyMs` | `number` | `undefined` | Maximum latency (ms) to report. Values above this are considered stale and won't be reported. |
|
|
45
|
+
|
|
46
|
+
**Example configurations:**
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<!-- Fast-paced conversation (aggressive turn detection) -->
|
|
50
|
+
<telnyx-ai-agent
|
|
51
|
+
agent-id="assistant-xxx"
|
|
52
|
+
vad='{"silenceDurationMs": 500, "minSpeechDurationMs": 80}'
|
|
53
|
+
></telnyx-ai-agent>
|
|
54
|
+
|
|
55
|
+
<!-- Thoughtful conversation (tolerant of pauses) -->
|
|
56
|
+
<telnyx-ai-agent
|
|
57
|
+
agent-id="assistant-xxx"
|
|
58
|
+
vad='{"silenceDurationMs": 1500, "minSpeechDurationMs": 150}'
|
|
59
|
+
></telnyx-ai-agent>
|
|
60
|
+
|
|
61
|
+
<!-- Noisy environment -->
|
|
62
|
+
<telnyx-ai-agent
|
|
63
|
+
agent-id="assistant-xxx"
|
|
64
|
+
vad='{"volumeThreshold": 20, "minSpeechDurationMs": 200}'
|
|
65
|
+
></telnyx-ai-agent>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Latency Display Options
|
|
69
|
+
|
|
70
|
+
Control whether latency measurements are included in transcript messages. Both options default to `false`.
|
|
71
|
+
|
|
72
|
+
| Attribute | Type | Default | Description |
|
|
73
|
+
| ----------------------------- | --------- | ------- | ------------------------------------------------------------------------------------------------------ |
|
|
74
|
+
| `show-user-perceived-latency` | `boolean` | `false` | Include `userPerceivedLatencyMs` in transcript items (time from user stop speaking to agent response). |
|
|
75
|
+
| `show-greeting-latency` | `boolean` | `false` | Include `greetingLatencyMs` in transcript items (time for initial agent greeting). |
|
|
76
|
+
|
|
77
|
+
```html
|
|
78
|
+
<!-- Enable latency tracking in transcript messages -->
|
|
79
|
+
<telnyx-ai-agent
|
|
80
|
+
agent-id="assistant-xxx"
|
|
81
|
+
show-user-perceived-latency
|
|
82
|
+
show-greeting-latency
|
|
83
|
+
></telnyx-ai-agent>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
When enabled, latency values are attached to assistant transcript items and can be accessed via the `transcript.item` event:
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
widget.addEventListener('transcript.item', function (event) {
|
|
90
|
+
const { role, content, userPerceivedLatencyMs, greetingLatencyMs } =
|
|
91
|
+
event.detail;
|
|
92
|
+
if (role === 'assistant') {
|
|
93
|
+
if (userPerceivedLatencyMs !== undefined) {
|
|
94
|
+
console.log('Response latency:', userPerceivedLatencyMs, 'ms');
|
|
95
|
+
}
|
|
96
|
+
if (greetingLatencyMs !== undefined) {
|
|
97
|
+
console.log('Greeting latency:', greetingLatencyMs, 'ms');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
26
103
|
## Events and Callbacks
|
|
27
104
|
|
|
28
105
|
The widget emits DOM CustomEvents that you can listen to for tracking analytics, updating UI, or integrating with your application logic. Event names match `@telnyx/ai-agent-lib` for consistency.
|