orb-ui 0.6.0 → 0.7.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 +29 -20
- package/dist/adapters/audio-level.d.ts +5 -0
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/livekit/browser.d.ts +5 -0
- package/dist/adapters/livekit/index.d.ts +9 -2
- package/dist/adapters/pipecat/index.d.ts +16 -0
- package/dist/adapters.cjs +1 -1
- package/dist/adapters.js +260 -241
- package/dist/components/Orb/Orb.types.d.ts +8 -4
- package/dist/components/Orb/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/livekit-CukEeYFK.js +316 -0
- package/dist/livekit-Dt-QZ6Gs.cjs +1 -0
- package/dist/livekit-adapter.cjs +1 -1
- package/dist/livekit-adapter.js +4 -2
- package/dist/orb-ui.cjs +93 -1
- package/dist/orb-ui.js +251 -28
- package/dist/themes/index.d.ts +1 -0
- package/dist/themes/radial/RadialTheme.d.ts +13 -0
- package/dist/themes/radial/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/livekit-Dasur3lv.js +0 -240
- package/dist/livekit-Ro6A52eb.cjs +0 -1
package/dist/adapters.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as e, n as t, r as n, t as r } from "./livekit-CukEeYFK.js";
|
|
2
2
|
//#region src/adapters/vapi/index.ts
|
|
3
|
-
var
|
|
4
|
-
function
|
|
3
|
+
var i = .12;
|
|
4
|
+
function a(e) {
|
|
5
5
|
let t = "idle", n = null;
|
|
6
6
|
function r(r) {
|
|
7
7
|
if (n &&= (clearTimeout(n), null), t === "speaking" && r === "listening") {
|
|
@@ -20,42 +20,42 @@ function n(e) {
|
|
|
20
20
|
clearTimer: i
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
let
|
|
23
|
+
function o(e, t) {
|
|
24
|
+
let n = /* @__PURE__ */ new Set(), r = null;
|
|
25
25
|
function o() {
|
|
26
|
-
|
|
26
|
+
r || (r = e.start.bind(e), e.start = async (...e) => (n.forEach((e) => e()), r(...e)));
|
|
27
27
|
}
|
|
28
28
|
function s() {
|
|
29
|
-
|
|
29
|
+
n.size > 0 || !r || (e.start = r, r = null);
|
|
30
30
|
}
|
|
31
31
|
return {
|
|
32
32
|
async start() {
|
|
33
|
-
await e.start(
|
|
33
|
+
await e.start(t?.assistantId);
|
|
34
34
|
},
|
|
35
35
|
stop() {
|
|
36
36
|
e.stop();
|
|
37
37
|
},
|
|
38
|
-
subscribe(
|
|
39
|
-
let
|
|
38
|
+
subscribe(t) {
|
|
39
|
+
let r = {
|
|
40
40
|
state: "idle",
|
|
41
41
|
volume: 0,
|
|
42
42
|
outputVolume: 0
|
|
43
43
|
}, c = 0;
|
|
44
44
|
function l(e) {
|
|
45
|
-
let
|
|
46
|
-
return c += (
|
|
45
|
+
let t = e < i ? 0 : (e - i) / (1 - i), n = t > c ? .8 : .5;
|
|
46
|
+
return c += (t - c) * n, c;
|
|
47
47
|
}
|
|
48
48
|
function u(e) {
|
|
49
|
-
|
|
49
|
+
r = e, t(e);
|
|
50
50
|
}
|
|
51
51
|
function d(e) {
|
|
52
52
|
u({
|
|
53
|
-
...
|
|
53
|
+
...r,
|
|
54
54
|
...e,
|
|
55
|
-
state: e.state ??
|
|
55
|
+
state: e.state ?? r.state
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
let { emitState: f, clearTimer: p } =
|
|
58
|
+
let { emitState: f, clearTimer: p } = a((e) => d({ state: e })), m = () => f("connecting"), h = "idle", g = !1, _ = () => {
|
|
59
59
|
g = !0, h = "listening", f("listening"), d({
|
|
60
60
|
volume: 0,
|
|
61
61
|
outputVolume: 0
|
|
@@ -97,15 +97,15 @@ function r(e, r) {
|
|
|
97
97
|
error: e
|
|
98
98
|
}), c = 0;
|
|
99
99
|
};
|
|
100
|
-
return e.on("call-start", _), e.on("call-end", v), e.on("speech-start", y), e.on("speech-end", b), e.on("volume-level", D), e.on("message", O), e.on("error", k),
|
|
101
|
-
p(), E(), c = 0, e.removeListener("call-start", _), e.removeListener("call-end", v), e.removeListener("speech-start", y), e.removeListener("speech-end", b), e.removeListener("volume-level", D), e.removeListener("message", O), e.removeListener("error", k),
|
|
100
|
+
return e.on("call-start", _), e.on("call-end", v), e.on("speech-start", y), e.on("speech-end", b), e.on("volume-level", D), e.on("message", O), e.on("error", k), n.add(m), o(), () => {
|
|
101
|
+
p(), E(), c = 0, e.removeListener("call-start", _), e.removeListener("call-end", v), e.removeListener("speech-start", y), e.removeListener("speech-end", b), e.removeListener("volume-level", D), e.removeListener("message", O), e.removeListener("error", k), n.delete(m), s();
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region src/adapters/elevenlabs/index.ts
|
|
108
|
-
function
|
|
108
|
+
function s(e, t) {
|
|
109
109
|
let n = null, r = 0, i = null, a = null, o = {
|
|
110
110
|
state: "idle",
|
|
111
111
|
volume: 0,
|
|
@@ -245,7 +245,7 @@ function i(e, t) {
|
|
|
245
245
|
}
|
|
246
246
|
//#endregion
|
|
247
247
|
//#region src/adapters/pipecat/index.ts
|
|
248
|
-
var
|
|
248
|
+
var c = {
|
|
249
249
|
connected: "connected",
|
|
250
250
|
disconnected: "disconnected",
|
|
251
251
|
transportStateChanged: "transportStateChanged",
|
|
@@ -262,8 +262,19 @@ var a = {
|
|
|
262
262
|
userStoppedSpeaking: "userStoppedSpeaking",
|
|
263
263
|
botLlmStarted: "botLlmStarted",
|
|
264
264
|
botTtsStarted: "botTtsStarted"
|
|
265
|
-
},
|
|
266
|
-
|
|
265
|
+
}, l = .002, u = 4, d = .8, f = .6, p = .2, m = {
|
|
266
|
+
noiseFloor: .002,
|
|
267
|
+
gain: 5.1,
|
|
268
|
+
exponent: .8,
|
|
269
|
+
attack: .5,
|
|
270
|
+
release: .22
|
|
271
|
+
};
|
|
272
|
+
function h() {
|
|
273
|
+
if (typeof window > "u") return;
|
|
274
|
+
let e = window.AudioContext;
|
|
275
|
+
return e ? new e() : void 0;
|
|
276
|
+
}
|
|
277
|
+
function g(e) {
|
|
267
278
|
switch (e) {
|
|
268
279
|
case "initializing":
|
|
269
280
|
case "initialized":
|
|
@@ -278,30 +289,37 @@ function d(e) {
|
|
|
278
289
|
default: return;
|
|
279
290
|
}
|
|
280
291
|
}
|
|
281
|
-
function
|
|
282
|
-
if (typeof e != "number" || !Number.isFinite(e) || e <=
|
|
283
|
-
let t = Math.min(1, Math.max(0, e -
|
|
284
|
-
return Math.min(1, t *
|
|
292
|
+
function _(e) {
|
|
293
|
+
if (typeof e != "number" || !Number.isFinite(e) || e <= l) return 0;
|
|
294
|
+
let t = Math.min(1, Math.max(0, e - l));
|
|
295
|
+
return Math.min(1, t * u) ** +d;
|
|
285
296
|
}
|
|
286
|
-
function
|
|
287
|
-
let n =
|
|
297
|
+
function v(e, t) {
|
|
298
|
+
let n = _(e), r = n > t ? f : p;
|
|
288
299
|
return t + (n - t) * r;
|
|
289
300
|
}
|
|
290
|
-
function
|
|
301
|
+
function y(e) {
|
|
291
302
|
return typeof e == "object" && !!e && "kind" in e && typeof e.kind == "string";
|
|
292
303
|
}
|
|
293
|
-
function
|
|
294
|
-
let
|
|
295
|
-
state:
|
|
304
|
+
function b(t, r = {}) {
|
|
305
|
+
let i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = {
|
|
306
|
+
state: g(t.state ?? "") ?? "idle",
|
|
296
307
|
volume: 0,
|
|
297
308
|
inputVolume: 0,
|
|
298
309
|
outputVolume: 0
|
|
299
|
-
},
|
|
300
|
-
function
|
|
301
|
-
|
|
310
|
+
}, s = !1, l = 0, u = 0, d = null, f = null, p, _;
|
|
311
|
+
function b() {
|
|
312
|
+
let e = typeof r.outputVolumeCalibration == "function" ? r.outputVolumeCalibration() : r.outputVolumeCalibration;
|
|
313
|
+
return {
|
|
314
|
+
...m,
|
|
315
|
+
...e
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function x(e) {
|
|
319
|
+
o = e, i.forEach((t) => t(e));
|
|
302
320
|
}
|
|
303
|
-
function
|
|
304
|
-
|
|
321
|
+
function S(e, t) {
|
|
322
|
+
l = 0, u = 0, x({
|
|
305
323
|
state: e,
|
|
306
324
|
volume: 0,
|
|
307
325
|
inputVolume: 0,
|
|
@@ -309,143 +327,144 @@ function h(e, t = {}) {
|
|
|
309
327
|
...t === void 0 ? {} : { error: t }
|
|
310
328
|
});
|
|
311
329
|
}
|
|
312
|
-
function
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
let t =
|
|
316
|
-
|
|
317
|
-
...
|
|
330
|
+
function C(e) {
|
|
331
|
+
if (o.state !== "listening") return;
|
|
332
|
+
l = v(e, l);
|
|
333
|
+
let t = l;
|
|
334
|
+
x({
|
|
335
|
+
...o,
|
|
318
336
|
volume: t,
|
|
319
337
|
inputVolume: t,
|
|
320
338
|
outputVolume: 0
|
|
321
339
|
});
|
|
322
340
|
}
|
|
323
|
-
function
|
|
324
|
-
if (
|
|
325
|
-
if (
|
|
326
|
-
let e =
|
|
327
|
-
if (e.local ||
|
|
341
|
+
function w(e, t) {
|
|
342
|
+
if (o.state !== "speaking") return;
|
|
343
|
+
if (t && typeof t == "object") {
|
|
344
|
+
let e = t;
|
|
345
|
+
if (e.local || r.isBotParticipant && !r.isBotParticipant(e)) return;
|
|
328
346
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
347
|
+
let i = n(typeof e == "number" ? e : 0, u, b);
|
|
348
|
+
u = i.normalized, r.onOutputVolumeSample?.(i);
|
|
349
|
+
let a = i.normalized;
|
|
350
|
+
x({
|
|
351
|
+
...o,
|
|
352
|
+
volume: a,
|
|
334
353
|
inputVolume: 0,
|
|
335
|
-
outputVolume:
|
|
354
|
+
outputVolume: a
|
|
336
355
|
});
|
|
337
356
|
}
|
|
338
|
-
function
|
|
357
|
+
function T() {
|
|
358
|
+
d = null, p?.stop(), p = void 0;
|
|
359
|
+
}
|
|
360
|
+
function E() {
|
|
361
|
+
f = null, _?.stop(), _ = void 0;
|
|
362
|
+
}
|
|
363
|
+
function D() {
|
|
364
|
+
T(), E();
|
|
365
|
+
}
|
|
366
|
+
function O(t) {
|
|
367
|
+
d === t && p || (T(), d = t, p = e(t, r.createAudioContext ?? h, C), p || (d = null));
|
|
368
|
+
}
|
|
369
|
+
function k(t) {
|
|
370
|
+
f === t && _ || (E(), f = t, _ = e(t, r.createAudioContext ?? h, w), _ || (f = null));
|
|
371
|
+
}
|
|
372
|
+
function A() {
|
|
373
|
+
let e = t.tracks?.();
|
|
374
|
+
e?.local?.audio && O(e.local.audio), e?.bot?.audio && k(e.bot.audio);
|
|
375
|
+
}
|
|
376
|
+
function j(e) {
|
|
339
377
|
if (!e || typeof e != "object") return !0;
|
|
340
|
-
let
|
|
341
|
-
return
|
|
378
|
+
let t = e;
|
|
379
|
+
return t.local ? !1 : r.isBotParticipant?.(t) ?? !0;
|
|
342
380
|
}
|
|
343
|
-
function
|
|
344
|
-
if (
|
|
345
|
-
let
|
|
346
|
-
|
|
381
|
+
function M(e, t) {
|
|
382
|
+
if (r.playRemoteAudio === !1 || !y(e) || e.kind !== "audio" || !j(t)) return;
|
|
383
|
+
let n = r.createAudioElement?.() ?? new Audio();
|
|
384
|
+
n.autoplay = !0, n.srcObject = new MediaStream([e]), a.set(e, n), n.play().catch(() => void 0);
|
|
347
385
|
}
|
|
348
|
-
function
|
|
349
|
-
if (!
|
|
350
|
-
let t =
|
|
351
|
-
t && (t.pause(), t.srcObject = null, t.remove(),
|
|
386
|
+
function N(e) {
|
|
387
|
+
if (!y(e)) return;
|
|
388
|
+
let t = a.get(e);
|
|
389
|
+
t && (t.pause(), t.srcObject = null, t.remove(), a.delete(e));
|
|
352
390
|
}
|
|
353
|
-
function
|
|
354
|
-
|
|
391
|
+
function P(e, n) {
|
|
392
|
+
if (!y(e) || e.kind !== "audio") return;
|
|
393
|
+
let r = t.tracks?.().local?.audio;
|
|
394
|
+
n?.local === !0 || e === r ? O(e) : j(n) && k(e), M(e, n);
|
|
395
|
+
}
|
|
396
|
+
function F(e) {
|
|
397
|
+
e === d && T(), e === f && E(), N(e);
|
|
398
|
+
}
|
|
399
|
+
function I() {
|
|
400
|
+
a.forEach((e) => {
|
|
355
401
|
e.pause(), e.srcObject = null, e.remove();
|
|
356
|
-
}),
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
402
|
+
}), a.clear();
|
|
403
|
+
}
|
|
404
|
+
function L() {
|
|
405
|
+
D(), S("idle");
|
|
406
|
+
}
|
|
407
|
+
function R() {
|
|
408
|
+
S("listening"), A();
|
|
409
|
+
}
|
|
410
|
+
let z = [
|
|
411
|
+
[c.connected, () => S("connecting")],
|
|
412
|
+
[c.botReady, R],
|
|
413
|
+
[c.disconnected, L],
|
|
414
|
+
[c.botDisconnected, L],
|
|
415
|
+
[c.transportStateChanged, (e) => {
|
|
364
416
|
if (typeof e != "string") return;
|
|
365
|
-
let t =
|
|
366
|
-
t &&
|
|
417
|
+
let t = g(e);
|
|
418
|
+
t && S(t);
|
|
367
419
|
}],
|
|
368
|
-
[
|
|
369
|
-
[
|
|
370
|
-
|
|
420
|
+
[c.userStartedSpeaking, () => S("listening")],
|
|
421
|
+
[c.userStoppedSpeaking, () => {
|
|
422
|
+
o.state === "listening" && S("thinking");
|
|
371
423
|
}],
|
|
372
|
-
[
|
|
373
|
-
[
|
|
374
|
-
[
|
|
375
|
-
[
|
|
376
|
-
[
|
|
377
|
-
[
|
|
378
|
-
["trackStarted",
|
|
379
|
-
["trackStopped",
|
|
380
|
-
[
|
|
381
|
-
[
|
|
382
|
-
[
|
|
424
|
+
[c.botLlmStarted, () => S("thinking")],
|
|
425
|
+
[c.botTtsStarted, () => S("thinking")],
|
|
426
|
+
[c.botStartedSpeaking, () => S("speaking")],
|
|
427
|
+
[c.botStoppedSpeaking, () => S("listening")],
|
|
428
|
+
[c.localAudioLevel, (e) => !p && C(e)],
|
|
429
|
+
[c.remoteAudioLevel, (e, t) => !_ && w(e, t)],
|
|
430
|
+
["trackStarted", P],
|
|
431
|
+
["trackStopped", F],
|
|
432
|
+
[c.error, (e) => S("error", e)],
|
|
433
|
+
[c.messageError, (e) => S("error", e)],
|
|
434
|
+
[c.deviceError, (e) => S("error", e)]
|
|
383
435
|
];
|
|
384
|
-
function
|
|
385
|
-
|
|
436
|
+
function B() {
|
|
437
|
+
s || (s = !0, z.forEach(([e, n]) => t.on(e, n)));
|
|
386
438
|
}
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}),
|
|
439
|
+
function V() {
|
|
440
|
+
s && (s = !1, z.forEach(([e, n]) => {
|
|
441
|
+
t.off ? t.off(e, n) : t.removeListener?.(e, n);
|
|
442
|
+
}), D(), I());
|
|
391
443
|
}
|
|
392
444
|
return {
|
|
393
445
|
subscribe(e) {
|
|
394
|
-
return
|
|
395
|
-
|
|
446
|
+
return i.add(e), B(), e(o), () => {
|
|
447
|
+
i.delete(e), i.size === 0 && V();
|
|
396
448
|
};
|
|
397
449
|
},
|
|
398
450
|
async start() {
|
|
399
|
-
|
|
451
|
+
S("connecting");
|
|
400
452
|
try {
|
|
401
|
-
await (
|
|
453
|
+
await (r.connect ? r.connect() : t.connect());
|
|
402
454
|
} catch (e) {
|
|
403
|
-
throw
|
|
455
|
+
throw S("error", e), e;
|
|
404
456
|
}
|
|
405
457
|
},
|
|
406
458
|
async stop() {
|
|
407
459
|
try {
|
|
408
|
-
await (
|
|
460
|
+
await (r.disconnect ? r.disconnect() : t.disconnect());
|
|
409
461
|
} finally {
|
|
410
|
-
|
|
462
|
+
D(), I(), S("idle");
|
|
411
463
|
}
|
|
412
464
|
}
|
|
413
465
|
};
|
|
414
466
|
}
|
|
415
467
|
//#endregion
|
|
416
|
-
//#region src/adapters/audio-level.ts
|
|
417
|
-
var g = {
|
|
418
|
-
noiseFloor: 0,
|
|
419
|
-
gain: 4,
|
|
420
|
-
exponent: .8,
|
|
421
|
-
attack: 1,
|
|
422
|
-
release: 1
|
|
423
|
-
};
|
|
424
|
-
function _(e, t, n) {
|
|
425
|
-
return Math.min(n, Math.max(t, e));
|
|
426
|
-
}
|
|
427
|
-
function v(e, t) {
|
|
428
|
-
return typeof e == "number" && Number.isFinite(e) ? e : t;
|
|
429
|
-
}
|
|
430
|
-
function y(e) {
|
|
431
|
-
let t = typeof e == "function" ? e() : e;
|
|
432
|
-
return {
|
|
433
|
-
noiseFloor: _(v(t?.noiseFloor, g.noiseFloor), 0, 1),
|
|
434
|
-
gain: Math.max(0, v(t?.gain, g.gain)),
|
|
435
|
-
exponent: Math.max(.01, v(t?.exponent, g.exponent)),
|
|
436
|
-
attack: _(v(t?.attack, g.attack), 0, 1),
|
|
437
|
-
release: _(v(t?.release, g.release), 0, 1)
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function b(e, t, n) {
|
|
441
|
-
let r = Number.isFinite(e) ? _(e, 0, 1) : 0, i = y(n), a = _((r <= i.noiseFloor ? 0 : r - i.noiseFloor) * i.gain, 0, 1) ** +i.exponent, o = a > t ? i.attack : i.release;
|
|
442
|
-
return {
|
|
443
|
-
raw: r,
|
|
444
|
-
shaped: a,
|
|
445
|
-
normalized: _(t + (a - t) * o, 0, 1)
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
//#endregion
|
|
449
468
|
//#region src/adapters/openai-realtime/index.ts
|
|
450
469
|
var x = "https://api.openai.com/v1/realtime/calls", S = .015, C = 8, w = {
|
|
451
470
|
noiseFloor: .003,
|
|
@@ -486,24 +505,24 @@ function O(e) {
|
|
|
486
505
|
return t;
|
|
487
506
|
}
|
|
488
507
|
function k(e) {
|
|
489
|
-
let t = /* @__PURE__ */ new Set(),
|
|
508
|
+
let t = /* @__PURE__ */ new Set(), r = {
|
|
490
509
|
state: "idle",
|
|
491
510
|
volume: 0,
|
|
492
511
|
inputVolume: 0,
|
|
493
512
|
outputVolume: 0
|
|
494
|
-
},
|
|
495
|
-
function
|
|
513
|
+
}, i = null, a = null, o = null, s = null, c, l, u = 0, d = 0, f = !1;
|
|
514
|
+
function p() {
|
|
496
515
|
let t = typeof e.outputVolumeCalibration == "function" ? e.outputVolumeCalibration() : e.outputVolumeCalibration;
|
|
497
516
|
return {
|
|
498
517
|
...w,
|
|
499
518
|
...t
|
|
500
519
|
};
|
|
501
520
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
521
|
+
function m(e) {
|
|
522
|
+
r = e, t.forEach((t) => t(e));
|
|
504
523
|
}
|
|
505
|
-
function
|
|
506
|
-
|
|
524
|
+
function h(e, t) {
|
|
525
|
+
r.state === e && t === void 0 || (e !== "speaking" && (d = 0), m({
|
|
507
526
|
state: e,
|
|
508
527
|
volume: 0,
|
|
509
528
|
inputVolume: 0,
|
|
@@ -511,92 +530,92 @@ function k(e) {
|
|
|
511
530
|
...t === void 0 ? {} : { error: t }
|
|
512
531
|
}));
|
|
513
532
|
}
|
|
514
|
-
function
|
|
515
|
-
if (
|
|
533
|
+
function g(e) {
|
|
534
|
+
if (r.state !== "listening") return;
|
|
516
535
|
let t = E(e);
|
|
517
|
-
|
|
518
|
-
...
|
|
536
|
+
m({
|
|
537
|
+
...r,
|
|
519
538
|
volume: t,
|
|
520
539
|
inputVolume: t,
|
|
521
540
|
outputVolume: 0
|
|
522
541
|
});
|
|
523
542
|
}
|
|
524
|
-
function
|
|
525
|
-
let
|
|
526
|
-
|
|
527
|
-
let
|
|
528
|
-
if (
|
|
529
|
-
else if (
|
|
530
|
-
|
|
543
|
+
function _(t) {
|
|
544
|
+
let i = n(t, d, p);
|
|
545
|
+
d = i.normalized, e.onOutputVolumeSample?.(i);
|
|
546
|
+
let a = i.normalized;
|
|
547
|
+
if (a > S) u = 0, r.state !== "speaking" && h("speaking");
|
|
548
|
+
else if (r.state === "speaking" && (u += 1, u >= C)) {
|
|
549
|
+
u = 0, h("listening");
|
|
531
550
|
return;
|
|
532
551
|
}
|
|
533
|
-
|
|
534
|
-
...
|
|
535
|
-
volume:
|
|
552
|
+
r.state === "speaking" && m({
|
|
553
|
+
...r,
|
|
554
|
+
volume: a,
|
|
536
555
|
inputVolume: 0,
|
|
537
|
-
outputVolume:
|
|
556
|
+
outputVolume: a
|
|
538
557
|
});
|
|
539
558
|
}
|
|
540
|
-
function
|
|
559
|
+
function v(e) {
|
|
541
560
|
switch (e.type) {
|
|
542
561
|
case "session.created":
|
|
543
562
|
case "session.updated":
|
|
544
|
-
|
|
563
|
+
h("listening");
|
|
545
564
|
break;
|
|
546
565
|
case "input_audio_buffer.speech_started":
|
|
547
|
-
|
|
566
|
+
h("listening");
|
|
548
567
|
break;
|
|
549
568
|
case "input_audio_buffer.speech_stopped":
|
|
550
569
|
case "response.created":
|
|
551
|
-
|
|
570
|
+
h("thinking");
|
|
552
571
|
break;
|
|
553
572
|
case "response.output_audio.delta":
|
|
554
573
|
case "output_audio_buffer.started":
|
|
555
|
-
|
|
574
|
+
h("speaking");
|
|
556
575
|
break;
|
|
557
576
|
case "output_audio_buffer.stopped":
|
|
558
|
-
|
|
577
|
+
h("listening");
|
|
559
578
|
break;
|
|
560
579
|
case "response.done":
|
|
561
580
|
case "response.cancelled":
|
|
562
|
-
|
|
581
|
+
r.state !== "speaking" && h("listening");
|
|
563
582
|
break;
|
|
564
583
|
case "error":
|
|
565
|
-
|
|
584
|
+
h("error", e.error ?? e);
|
|
566
585
|
break;
|
|
567
586
|
}
|
|
568
587
|
}
|
|
569
|
-
async function
|
|
570
|
-
|
|
588
|
+
async function y(e) {
|
|
589
|
+
f = !0, a?.close(), a = null, i?.close(), i = null, o?.getTracks().forEach((e) => e.stop()), o = null, s?.pause(), s && (s.srcObject = null), s?.remove(), s = null, await Promise.all([c?.stop(), l?.stop()]), c = void 0, l = void 0, u = 0, d = 0, e && h("idle"), f = !1;
|
|
571
590
|
}
|
|
572
591
|
return {
|
|
573
592
|
subscribe(e) {
|
|
574
|
-
return t.add(e), e(
|
|
593
|
+
return t.add(e), e(r), () => t.delete(e);
|
|
575
594
|
},
|
|
576
595
|
async start() {
|
|
577
|
-
if (!
|
|
578
|
-
|
|
596
|
+
if (!i) {
|
|
597
|
+
h("connecting"), f = !1;
|
|
579
598
|
try {
|
|
580
|
-
let t = e.getUserMedia ?? ((e) => navigator.mediaDevices.getUserMedia(e)), n = e.createPeerConnection ?? (() => new RTCPeerConnection()),
|
|
581
|
-
|
|
582
|
-
let
|
|
583
|
-
|
|
599
|
+
let t = e.getUserMedia ?? ((e) => navigator.mediaDevices.getUserMedia(e)), n = e.createPeerConnection ?? (() => new RTCPeerConnection()), r = e.fetch ?? fetch, u = e.createAudioElement ?? (() => new Audio()), d = e.createAudioContext ?? T, p = O(await e.getClientSecret());
|
|
600
|
+
o = await t(e.mediaStreamConstraints ?? { audio: !0 }), c = D(o, d, g);
|
|
601
|
+
let m = n();
|
|
602
|
+
i = m, o.getAudioTracks().forEach((e) => m.addTrack(e, o)), s = u(), s.autoplay = !0, m.ontrack = (e) => {
|
|
584
603
|
let t = e.streams[0] ?? new MediaStream([e.track]);
|
|
585
|
-
|
|
586
|
-
},
|
|
587
|
-
|
|
604
|
+
s && (s.srcObject = t), s?.play().catch(() => void 0), l?.stop(), l = D(t, d, _);
|
|
605
|
+
}, m.onconnectionstatechange = () => {
|
|
606
|
+
f || (m.connectionState === "failed" ? h("error", /* @__PURE__ */ Error("[orb-ui/openai-realtime] WebRTC connection failed.")) : (m.connectionState === "disconnected" || m.connectionState === "closed") && h("idle"));
|
|
588
607
|
};
|
|
589
|
-
let y =
|
|
590
|
-
|
|
608
|
+
let y = m.createDataChannel("oai-events");
|
|
609
|
+
a = y, y.onopen = () => h("listening"), y.onmessage = (e) => {
|
|
591
610
|
try {
|
|
592
|
-
|
|
611
|
+
v(JSON.parse(String(e.data)));
|
|
593
612
|
} catch {}
|
|
594
|
-
}, y.onerror = (e) =>
|
|
595
|
-
|
|
613
|
+
}, y.onerror = (e) => h("error", e), y.onclose = () => {
|
|
614
|
+
f || h("idle");
|
|
596
615
|
};
|
|
597
|
-
let b = await
|
|
598
|
-
await
|
|
599
|
-
let S = await
|
|
616
|
+
let b = await m.createOffer();
|
|
617
|
+
await m.setLocalDescription(b);
|
|
618
|
+
let S = await r(e.callsUrl ?? x, {
|
|
600
619
|
method: "POST",
|
|
601
620
|
body: b.sdp,
|
|
602
621
|
headers: {
|
|
@@ -608,17 +627,17 @@ function k(e) {
|
|
|
608
627
|
let e = await S.text();
|
|
609
628
|
throw Error(`[orb-ui/openai-realtime] Session negotiation failed (${S.status}): ${e}`);
|
|
610
629
|
}
|
|
611
|
-
await
|
|
630
|
+
await m.setRemoteDescription({
|
|
612
631
|
type: "answer",
|
|
613
632
|
sdp: await S.text()
|
|
614
633
|
});
|
|
615
634
|
} catch (e) {
|
|
616
|
-
throw await
|
|
635
|
+
throw await y(!1), h("error", e), e;
|
|
617
636
|
}
|
|
618
637
|
}
|
|
619
638
|
},
|
|
620
639
|
async stop() {
|
|
621
|
-
await
|
|
640
|
+
await y(!0);
|
|
622
641
|
}
|
|
623
642
|
};
|
|
624
643
|
}
|
|
@@ -671,16 +690,16 @@ function L(e) {
|
|
|
671
690
|
return t ? Number(t[1]) : 24e3;
|
|
672
691
|
}
|
|
673
692
|
function R(e) {
|
|
674
|
-
let t = /* @__PURE__ */ new Set(),
|
|
693
|
+
let t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = {
|
|
675
694
|
state: "idle",
|
|
676
695
|
volume: 0,
|
|
677
696
|
inputVolume: 0,
|
|
678
697
|
outputVolume: 0
|
|
679
|
-
},
|
|
680
|
-
function
|
|
698
|
+
}, a = null, o = null, s = null, c = null, l = null, u = null, d = null, f = null, p = null, m = !1, h = 0, g = 0, _ = !1, v = !1;
|
|
699
|
+
function y() {
|
|
681
700
|
return e.activityDetection !== "server";
|
|
682
701
|
}
|
|
683
|
-
function
|
|
702
|
+
function b() {
|
|
684
703
|
let t = typeof e.outputVolumeCalibration == "function" ? e.outputVolumeCalibration() : e.outputVolumeCalibration;
|
|
685
704
|
return {
|
|
686
705
|
...j,
|
|
@@ -688,10 +707,10 @@ function R(e) {
|
|
|
688
707
|
};
|
|
689
708
|
}
|
|
690
709
|
function x(e) {
|
|
691
|
-
|
|
710
|
+
i = e, t.forEach((t) => t(e));
|
|
692
711
|
}
|
|
693
712
|
function S(e, t) {
|
|
694
|
-
|
|
713
|
+
i.state === e && t === void 0 || (e !== "speaking" && (g = 0), x({
|
|
695
714
|
state: e,
|
|
696
715
|
volume: 0,
|
|
697
716
|
inputVolume: 0,
|
|
@@ -700,113 +719,113 @@ function R(e) {
|
|
|
700
719
|
}));
|
|
701
720
|
}
|
|
702
721
|
function C() {
|
|
703
|
-
|
|
722
|
+
p &&= (clearTimeout(p), null);
|
|
704
723
|
}
|
|
705
724
|
function w(t) {
|
|
706
|
-
t > (e.speechThreshold ?? .04) ? (!
|
|
707
|
-
|
|
708
|
-
}, e.speechEndDelayMs ?? 500)),
|
|
709
|
-
...
|
|
725
|
+
t > (e.speechThreshold ?? .04) ? (!m && y() && a?.sendRealtimeInput({ activityStart: {} }), m = !0, C(), i.state !== "listening" && S("listening")) : m && !p && (p = setTimeout(() => {
|
|
726
|
+
p = null, m = !1, y() && a?.sendRealtimeInput({ activityEnd: {} }), i.state === "listening" && S("thinking");
|
|
727
|
+
}, e.speechEndDelayMs ?? 500)), i.state === "listening" && x({
|
|
728
|
+
...i,
|
|
710
729
|
volume: t,
|
|
711
730
|
inputVolume: t,
|
|
712
731
|
outputVolume: 0
|
|
713
732
|
});
|
|
714
733
|
}
|
|
715
734
|
function T() {
|
|
716
|
-
|
|
735
|
+
r.forEach((e) => {
|
|
717
736
|
try {
|
|
718
737
|
e.stop();
|
|
719
738
|
} catch {}
|
|
720
739
|
e.disconnect();
|
|
721
|
-
}),
|
|
740
|
+
}), r.clear(), h = s?.currentTime ?? 0;
|
|
722
741
|
}
|
|
723
742
|
function E() {
|
|
724
|
-
|
|
743
|
+
_ && r.size === 0 && (_ = !1, S("listening"));
|
|
725
744
|
}
|
|
726
745
|
function D(e) {
|
|
727
|
-
if (!
|
|
728
|
-
let t = I(e.data),
|
|
729
|
-
|
|
730
|
-
let a =
|
|
731
|
-
a.buffer =
|
|
732
|
-
let
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}, a.start(
|
|
746
|
+
if (!s || !d || !e.data) return;
|
|
747
|
+
let t = I(e.data), n = s.createBuffer(1, t.length, L(e.mimeType));
|
|
748
|
+
n.getChannelData(0).set(t);
|
|
749
|
+
let a = s.createBufferSource();
|
|
750
|
+
a.buffer = n, a.connect(d);
|
|
751
|
+
let o = Math.max(s.currentTime, h);
|
|
752
|
+
h = o + n.duration, r.add(a), a.onended = () => {
|
|
753
|
+
r.delete(a), a.disconnect(), E();
|
|
754
|
+
}, a.start(o), i.state !== "speaking" && S("speaking");
|
|
736
755
|
}
|
|
737
756
|
function O(e) {
|
|
738
757
|
e.setupComplete && S("listening");
|
|
739
758
|
let t = e.serverContent;
|
|
740
759
|
if (!t) return;
|
|
741
760
|
if (t.interrupted) {
|
|
742
|
-
T(),
|
|
761
|
+
T(), _ = !1, S("listening");
|
|
743
762
|
return;
|
|
744
763
|
}
|
|
745
764
|
let n = t.modelTurn?.parts?.filter((e) => e.inlineData?.data) ?? [];
|
|
746
|
-
t.modelTurn && n.length === 0 &&
|
|
765
|
+
t.modelTurn && n.length === 0 && i.state !== "speaking" && S("thinking"), n.forEach((e) => D(e.inlineData)), t.waitingForInput && (T(), S("listening")), (t.turnComplete || t.generationComplete) && (_ = !0, E());
|
|
747
766
|
}
|
|
748
767
|
function k() {
|
|
749
|
-
if (!
|
|
750
|
-
let t = new Float32Array(
|
|
751
|
-
|
|
752
|
-
if (!
|
|
753
|
-
|
|
754
|
-
let
|
|
755
|
-
|
|
756
|
-
let
|
|
768
|
+
if (!d) return;
|
|
769
|
+
let t = new Float32Array(d.fftSize);
|
|
770
|
+
f = setInterval(() => {
|
|
771
|
+
if (!d || i.state !== "speaking") return;
|
|
772
|
+
d.getFloatTimeDomainData(t);
|
|
773
|
+
let r = n(M(t), g, b);
|
|
774
|
+
g = r.normalized, e.onOutputVolumeSample?.(r);
|
|
775
|
+
let a = r.normalized;
|
|
757
776
|
x({
|
|
758
|
-
...
|
|
759
|
-
volume:
|
|
777
|
+
...i,
|
|
778
|
+
volume: a,
|
|
760
779
|
inputVolume: 0,
|
|
761
|
-
outputVolume:
|
|
780
|
+
outputVolume: a
|
|
762
781
|
});
|
|
763
782
|
}, 33);
|
|
764
783
|
}
|
|
765
784
|
function R() {
|
|
766
|
-
!
|
|
767
|
-
if (!
|
|
785
|
+
!s || !o || !a || (c = s.createMediaStreamSource(o), l = s.createScriptProcessor(4096, 1, 1), u = s.createGain(), u.gain.value = 0, c.connect(l), l.connect(u), u.connect(s.destination), l.onaudioprocess = (t) => {
|
|
786
|
+
if (!a || v) return;
|
|
768
787
|
let n = t.inputBuffer.getChannelData(0);
|
|
769
788
|
w(N(n));
|
|
770
|
-
let r = P(n,
|
|
771
|
-
|
|
789
|
+
let r = P(n, s?.sampleRate ?? A, e.inputSampleRate ?? A);
|
|
790
|
+
a.sendRealtimeInput({ audio: {
|
|
772
791
|
data: F(r),
|
|
773
792
|
mimeType: `audio/pcm;rate=${e.inputSampleRate ?? A}`
|
|
774
793
|
} });
|
|
775
794
|
});
|
|
776
795
|
}
|
|
777
796
|
async function z(e) {
|
|
778
|
-
|
|
797
|
+
v = !0, C(), f && clearInterval(f), f = null, T(), l?.disconnect(), c?.disconnect(), u?.disconnect(), d?.disconnect(), l = null, c = null, u = null, d = null, o?.getTracks().forEach((e) => e.stop()), o = null, s && s.state !== "closed" && await s.close(), s = null, a = null, m = !1, _ = !1, g = 0, e && S("idle"), v = !1;
|
|
779
798
|
}
|
|
780
799
|
return {
|
|
781
800
|
subscribe(e) {
|
|
782
|
-
return t.add(e), e(
|
|
801
|
+
return t.add(e), e(i), () => t.delete(e);
|
|
783
802
|
},
|
|
784
803
|
async start() {
|
|
785
|
-
if (!
|
|
786
|
-
S("connecting"),
|
|
804
|
+
if (!a) {
|
|
805
|
+
S("connecting"), v = !1;
|
|
787
806
|
try {
|
|
788
807
|
let t = e.getUserMedia ?? ((e) => navigator.mediaDevices.getUserMedia(e)), n = e.createAudioContext ?? (() => new window.AudioContext());
|
|
789
|
-
|
|
808
|
+
o = await t(e.mediaStreamConstraints ?? { audio: !0 }), s = n(), s.state === "suspended" && await s.resume(), d = s.createAnalyser(), d.fftSize = 512, d.smoothingTimeConstant = .25, d.connect(s.destination), k(), a = await e.connect({
|
|
790
809
|
onopen: () => S("listening"),
|
|
791
810
|
onmessage: O,
|
|
792
811
|
onerror: (e) => S("error", e),
|
|
793
812
|
onclose: () => {
|
|
794
|
-
|
|
813
|
+
v || S("idle");
|
|
795
814
|
}
|
|
796
815
|
}), R(), S("listening");
|
|
797
816
|
} catch (e) {
|
|
798
|
-
throw
|
|
817
|
+
throw a?.close(), await z(!1), S("error", e), e;
|
|
799
818
|
}
|
|
800
819
|
}
|
|
801
820
|
},
|
|
802
821
|
async stop() {
|
|
803
|
-
|
|
822
|
+
v = !0;
|
|
804
823
|
try {
|
|
805
|
-
|
|
824
|
+
m && y() && a?.sendRealtimeInput({ activityEnd: {} }), a?.sendRealtimeInput({ audioStreamEnd: !0 });
|
|
806
825
|
} catch {}
|
|
807
|
-
|
|
826
|
+
a?.close(), await z(!0);
|
|
808
827
|
}
|
|
809
828
|
};
|
|
810
829
|
}
|
|
811
830
|
//#endregion
|
|
812
|
-
export {
|
|
831
|
+
export { t as DEFAULT_OUTPUT_VOLUME_CALIBRATION, s as createElevenLabsAdapter, R as createGeminiLiveAdapter, r as createLiveKitAdapter, k as createOpenAIRealtimeAdapter, b as createPipecatAdapter, o as createVapiAdapter };
|