@celljs/ta-web 4.27.0 → 4.28.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/esm/browser/assistant/assistant-role.d.ts +9 -4
- package/esm/browser/assistant/assistant-role.js +17 -5
- package/esm/browser/assistant/assistant-task-util.d.ts +6 -0
- package/esm/browser/assistant/assistant-task-util.js +12 -1
- package/esm/browser/assistant/assistant-view.js +4 -1
- package/esm/browser/assistant/assistant.d.ts +2 -1
- package/esm/browser/assistant/assistant.js +9 -7
- package/esm/browser/assistant/call-conversing.d.ts +45 -0
- package/esm/browser/assistant/call-conversing.js +91 -0
- package/esm/browser/assistant/call-face.d.ts +13 -0
- package/esm/browser/assistant/call-face.js +81 -0
- package/esm/browser/assistant/call-keeper.d.ts +8 -4
- package/esm/browser/assistant/call-keeper.js +32 -11
- package/esm/browser/assistant/call-partnering.d.ts +37 -0
- package/esm/browser/assistant/call-partnering.js +79 -0
- package/esm/browser/assistant/call-scenes.d.ts +25 -0
- package/esm/browser/assistant/call-scenes.js +82 -0
- package/esm/browser/assistant/call-screen.d.ts +3 -0
- package/esm/browser/assistant/call-screen.js +15 -0
- package/esm/browser/assistant/mic-sense.d.ts +31 -0
- package/esm/browser/assistant/mic-sense.js +119 -0
- package/esm/browser/assistant/noise-gate.d.ts +32 -0
- package/esm/browser/assistant/noise-gate.js +66 -0
- package/esm/browser/assistant/pcm-util.d.ts +10 -0
- package/esm/browser/assistant/pcm-util.js +55 -0
- package/esm/browser/assistant/read-aloud.d.ts +2 -1
- package/esm/browser/assistant/realtime-voice-protocol.d.ts +84 -0
- package/esm/browser/assistant/realtime-voice-protocol.js +40 -0
- package/esm/browser/assistant/realtime-voice.d.ts +50 -62
- package/esm/browser/assistant/realtime-voice.js +213 -134
- package/esm/browser/assistant/spoken-timeline.d.ts +27 -0
- package/esm/browser/assistant/spoken-timeline.js +49 -0
- package/esm/browser/assistant/voice-call-bar.d.ts +9 -2
- package/esm/browser/assistant/voice-call-bar.js +81 -31
- package/esm/browser/assistant/voice-call-protocol.d.ts +61 -4
- package/esm/browser/assistant/voice-call.d.ts +16 -23
- package/esm/browser/assistant/voice-call.js +134 -117
- package/esm/browser/assistant/voice-reading.d.ts +83 -0
- package/esm/browser/assistant/voice-reading.js +150 -0
- package/esm/browser/avatar/dino-talk.d.ts +15 -0
- package/esm/browser/avatar/dino-talk.js +34 -0
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/conversation-scroll-util.d.ts +8 -1
- package/esm/browser/components/conversation-scroll-util.js +21 -0
- package/esm/browser/components/conversation-scroll.js +10 -11
- package/esm/browser/components/gallery.js +28 -7
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/image-pull.d.ts +64 -0
- package/esm/browser/components/image-pull.js +202 -0
- package/esm/browser/components/kept-call-bar.js +2 -1
- package/esm/browser/components/lightbox.d.ts +1 -1
- package/esm/browser/components/lightbox.js +57 -2
- package/esm/browser/components/markdown.d.ts +3 -1
- package/esm/browser/components/markdown.js +8 -4
- package/esm/browser/components/partner-row.js +2 -1
- package/esm/browser/components/relay-services.d.ts +9 -3
- package/esm/browser/components/relay-services.js +73 -35
- package/esm/browser/components/session-view.js +4 -2
- package/esm/browser/components/settings-parts.js +2 -0
- package/esm/browser/components/ta-avatar.d.ts +15 -1
- package/esm/browser/components/ta-avatar.js +38 -5
- package/esm/browser/components/voice-services.js +6 -1
- package/esm/browser/extension/web-api-call.d.ts +64 -2
- package/esm/browser/extension/web-api-contributions.d.ts +1 -0
- package/esm/browser/extension/web-api-partners.d.ts +2 -0
- package/esm/browser/extension/web-extension-api.d.ts +6 -6
- package/esm/browser/extension/web-extension-context.js +1 -0
- package/esm/browser/extension/web-extension-protocol.d.ts +3 -1
- package/esm/browser/extension/web-extension-run.d.ts +3 -2
- package/esm/browser/extension/web-extension-run.js +2 -0
- package/esm/browser/i18n/locales.d.ts +24 -5
- package/esm/browser/i18n/messages-ja.js +25 -6
- package/esm/browser/i18n/messages-zh-tw.js +25 -6
- package/esm/browser/i18n/messages.d.ts +23 -4
- package/esm/browser/i18n/messages.js +50 -12
- package/esm/browser/markdown/code-renderers.d.ts +2 -0
- package/esm/browser/markdown/code-renderers.js +2 -0
- package/esm/browser/screen/page-answers.d.ts +2 -1
- package/esm/browser/screen/page-answers.js +7 -4
- package/esm/browser/settings/settings-protocol.d.ts +2 -0
- package/esm/browser/settings/settings-protocol.js +2 -0
- package/esm/browser/style/chat-list.d.ts +1 -1
- package/esm/browser/style/chat-list.js +1 -1
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +6 -1
- package/esm/browser/style/device.js +1 -0
- package/esm/browser/style/dialogs.d.ts +1 -1
- package/esm/browser/style/dialogs.js +1 -1
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +135 -57
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +8 -0
- package/esm/browser/style/video-call.d.ts +2 -0
- package/esm/browser/style/video-call.js +52 -0
- package/esm/browser/style.js +2 -0
- package/esm/browser/util/desktop.d.ts +10 -1
- package/esm/browser/util/desktop.js +10 -0
- package/esm/browser/util/image-pull.d.ts +61 -0
- package/esm/browser/util/image-pull.js +88 -0
- package/esm/browser/util/spoken.d.ts +3 -3
- package/esm/browser/util/spoken.js +4 -4
- package/esm/browser/video-call/call-camera.d.ts +59 -0
- package/esm/browser/video-call/call-camera.js +188 -0
- package/esm/browser/video-call/call-window.d.ts +19 -0
- package/esm/browser/video-call/call-window.js +80 -0
- package/esm/browser/video-call/clip-plan.d.ts +47 -0
- package/esm/browser/video-call/clip-plan.js +60 -0
- package/esm/browser/video-call/face-clips.d.ts +33 -0
- package/esm/browser/video-call/face-clips.js +93 -0
- package/esm/browser/video-call/face-files.d.ts +31 -0
- package/esm/browser/video-call/face-files.js +77 -0
- package/esm/browser/video-call/video-call-view.d.ts +19 -0
- package/esm/browser/video-call/video-call-view.js +214 -0
- package/esm/browser/video-call/video-face.d.ts +13 -0
- package/esm/browser/video-call/video-face.js +497 -0
- package/esm/browser/workbench-hosts.d.ts +1 -0
- package/esm/browser/workbench-protocol.d.ts +2 -0
- package/esm/browser/workbench-util.d.ts +5 -0
- package/esm/browser/workbench-util.js +18 -0
- package/esm/browser/workbench.d.ts +6 -0
- package/esm/browser/workbench.js +36 -5
- package/lib/browser/assistant/assistant-role.d.ts +9 -4
- package/lib/browser/assistant/assistant-role.js +17 -5
- package/lib/browser/assistant/assistant-task-util.d.ts +6 -0
- package/lib/browser/assistant/assistant-task-util.js +11 -0
- package/lib/browser/assistant/assistant-view.js +3 -0
- package/lib/browser/assistant/assistant.d.ts +2 -1
- package/lib/browser/assistant/assistant.js +9 -7
- package/lib/browser/assistant/call-conversing.d.ts +46 -0
- package/lib/browser/assistant/call-conversing.js +96 -0
- package/lib/browser/assistant/call-face.d.ts +14 -0
- package/lib/browser/assistant/call-face.js +117 -0
- package/lib/browser/assistant/call-keeper.d.ts +8 -4
- package/lib/browser/assistant/call-keeper.js +32 -11
- package/lib/browser/assistant/call-partnering.d.ts +38 -0
- package/lib/browser/assistant/call-partnering.js +83 -0
- package/lib/browser/assistant/call-scenes.d.ts +26 -0
- package/lib/browser/assistant/call-scenes.js +85 -0
- package/lib/browser/assistant/call-screen.d.ts +3 -0
- package/lib/browser/assistant/call-screen.js +15 -0
- package/lib/browser/assistant/mic-sense.d.ts +32 -0
- package/lib/browser/assistant/mic-sense.js +123 -0
- package/lib/browser/assistant/noise-gate.d.ts +33 -0
- package/lib/browser/assistant/noise-gate.js +71 -0
- package/lib/browser/assistant/pcm-util.d.ts +11 -0
- package/lib/browser/assistant/pcm-util.js +58 -0
- package/lib/browser/assistant/read-aloud.d.ts +2 -1
- package/lib/browser/assistant/realtime-voice-protocol.d.ts +85 -0
- package/lib/browser/assistant/realtime-voice-protocol.js +43 -0
- package/lib/browser/assistant/realtime-voice.d.ts +50 -62
- package/lib/browser/assistant/realtime-voice.js +217 -138
- package/lib/browser/assistant/spoken-timeline.d.ts +28 -0
- package/lib/browser/assistant/spoken-timeline.js +53 -0
- package/lib/browser/assistant/voice-call-bar.d.ts +9 -2
- package/lib/browser/assistant/voice-call-bar.js +81 -30
- package/lib/browser/assistant/voice-call-protocol.d.ts +61 -4
- package/lib/browser/assistant/voice-call.d.ts +16 -23
- package/lib/browser/assistant/voice-call.js +134 -117
- package/lib/browser/assistant/voice-reading.d.ts +84 -0
- package/lib/browser/assistant/voice-reading.js +156 -0
- package/lib/browser/avatar/dino-talk.d.ts +16 -0
- package/lib/browser/avatar/dino-talk.js +37 -0
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/conversation-scroll-util.d.ts +8 -1
- package/lib/browser/components/conversation-scroll-util.js +21 -0
- package/lib/browser/components/conversation-scroll.js +10 -11
- package/lib/browser/components/gallery.js +28 -7
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/image-pull.d.ts +65 -0
- package/lib/browser/components/image-pull.js +206 -0
- package/lib/browser/components/kept-call-bar.js +2 -1
- package/lib/browser/components/lightbox.d.ts +1 -1
- package/lib/browser/components/lightbox.js +57 -2
- package/lib/browser/components/markdown.d.ts +3 -1
- package/lib/browser/components/markdown.js +7 -3
- package/lib/browser/components/partner-row.js +2 -1
- package/lib/browser/components/relay-services.d.ts +9 -3
- package/lib/browser/components/relay-services.js +71 -33
- package/lib/browser/components/session-view.js +3 -1
- package/lib/browser/components/settings-parts.js +2 -0
- package/lib/browser/components/ta-avatar.d.ts +15 -1
- package/lib/browser/components/ta-avatar.js +38 -5
- package/lib/browser/components/voice-services.js +5 -0
- package/lib/browser/extension/web-api-call.d.ts +64 -2
- package/lib/browser/extension/web-api-contributions.d.ts +1 -0
- package/lib/browser/extension/web-api-partners.d.ts +2 -0
- package/lib/browser/extension/web-extension-api.d.ts +6 -6
- package/lib/browser/extension/web-extension-context.js +1 -0
- package/lib/browser/extension/web-extension-protocol.d.ts +3 -1
- package/lib/browser/extension/web-extension-run.d.ts +3 -2
- package/lib/browser/extension/web-extension-run.js +2 -0
- package/lib/browser/i18n/locales.d.ts +24 -5
- package/lib/browser/i18n/messages-ja.js +25 -6
- package/lib/browser/i18n/messages-zh-tw.js +25 -6
- package/lib/browser/i18n/messages.d.ts +23 -4
- package/lib/browser/i18n/messages.js +50 -12
- package/lib/browser/markdown/code-renderers.d.ts +2 -0
- package/lib/browser/markdown/code-renderers.js +3 -1
- package/lib/browser/screen/page-answers.d.ts +2 -1
- package/lib/browser/screen/page-answers.js +7 -4
- package/lib/browser/settings/settings-protocol.d.ts +2 -0
- package/lib/browser/settings/settings-protocol.js +2 -0
- package/lib/browser/style/chat-list.d.ts +1 -1
- package/lib/browser/style/chat-list.js +1 -1
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +6 -1
- package/lib/browser/style/device.js +1 -0
- package/lib/browser/style/dialogs.d.ts +1 -1
- package/lib/browser/style/dialogs.js +1 -1
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +135 -57
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +8 -0
- package/lib/browser/style/video-call.d.ts +3 -0
- package/lib/browser/style/video-call.js +55 -0
- package/lib/browser/style.js +2 -0
- package/lib/browser/util/desktop.d.ts +10 -1
- package/lib/browser/util/desktop.js +10 -0
- package/lib/browser/util/image-pull.d.ts +62 -0
- package/lib/browser/util/image-pull.js +91 -0
- package/lib/browser/util/spoken.d.ts +3 -3
- package/lib/browser/util/spoken.js +4 -4
- package/lib/browser/video-call/call-camera.d.ts +60 -0
- package/lib/browser/video-call/call-camera.js +192 -0
- package/lib/browser/video-call/call-window.d.ts +20 -0
- package/lib/browser/video-call/call-window.js +83 -0
- package/lib/browser/video-call/clip-plan.d.ts +48 -0
- package/lib/browser/video-call/clip-plan.js +64 -0
- package/lib/browser/video-call/face-clips.d.ts +34 -0
- package/lib/browser/video-call/face-clips.js +96 -0
- package/lib/browser/video-call/face-files.d.ts +32 -0
- package/lib/browser/video-call/face-files.js +82 -0
- package/lib/browser/video-call/video-call-view.d.ts +20 -0
- package/lib/browser/video-call/video-call-view.js +250 -0
- package/lib/browser/video-call/video-face.d.ts +14 -0
- package/lib/browser/video-call/video-face.js +533 -0
- package/lib/browser/workbench-hosts.d.ts +1 -0
- package/lib/browser/workbench-protocol.d.ts +2 -0
- package/lib/browser/workbench-util.d.ts +5 -0
- package/lib/browser/workbench-util.js +18 -0
- package/lib/browser/workbench.d.ts +6 -0
- package/lib/browser/workbench.js +35 -4
- package/package.json +7 -7
- package/public/faces/README.md +27 -0
- package/public/faces/clap.mp4 +0 -0
- package/public/faces/dance.mp4 +0 -0
- package/public/faces/happy.mp4 +0 -0
- package/public/faces/heart.mp4 +0 -0
- package/public/faces/idle-1.mp4 +0 -0
- package/public/faces/idle-2.mp4 +0 -0
- package/public/faces/idle-3.mp4 +0 -0
- package/public/faces/laugh.mp4 +0 -0
- package/public/faces/lips.json +1 -0
- package/public/faces/listening.mp4 +0 -0
- package/public/faces/poster.jpg +0 -0
- package/public/faces/shy.mp4 +0 -0
- package/public/faces/sorry.mp4 +0 -0
- package/public/faces/stretch.mp4 +0 -0
- package/public/faces/surprised.mp4 +0 -0
- package/public/faces/talk-1.mp4 +0 -0
- package/public/faces/talk-2.mp4 +0 -0
- package/public/faces/think-2.mp4 +0 -0
- package/public/faces/thinking.mp4 +0 -0
- package/public/faces/wave.mp4 +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who answers in a call in place of the conversation (CallOptions.openPartner, docs/design/ta-call.md): it is asked
|
|
3
|
+
* what the user said, opened again once when it does not answer, and given way to the conversation when it cannot.
|
|
4
|
+
*/
|
|
5
|
+
export class CallPartnering {
|
|
6
|
+
constructor(call, options) {
|
|
7
|
+
this.call = call;
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
/** The partner of the call now: what it says by itself is said as news is, in a silence, and cut into as any answer. */
|
|
11
|
+
adopt(partner) {
|
|
12
|
+
var _a;
|
|
13
|
+
const calls = this.call.calls;
|
|
14
|
+
this.partner = partner;
|
|
15
|
+
(_a = partner === null || partner === void 0 ? void 0 : partner.news) === null || _a === void 0 ? void 0 : _a.call(partner, text => calls === this.call.calls && this.call.announce(text));
|
|
16
|
+
this.call.set({ partnered: !!partner });
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = this.partner) === null || _a === void 0 ? void 0 : _a.close();
|
|
21
|
+
this.partner = undefined;
|
|
22
|
+
}
|
|
23
|
+
/** A partner opened for a voice service to answer, which does not: one that answers itself takes its place. */
|
|
24
|
+
unvoice() {
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
|
+
if (!((_a = this.partner) === null || _a === void 0 ? void 0 : _a.brain)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const calls = this.call.calls;
|
|
30
|
+
this.close();
|
|
31
|
+
void ((_d = (_c = (_b = this.options).openPartner) === null || _c === void 0 ? void 0 : _c.call(_b, true)) === null || _d === void 0 ? void 0 : _d.then(partner => (calls === this.call.calls && this.call.state.active ? this.adopt(partner) : partner === null || partner === void 0 ? void 0 : partner.close()), () => calls === this.call.calls && this.call.set({ partnered: false })));
|
|
32
|
+
}
|
|
33
|
+
/** The partner answers what the user said; its reply is read as a turn's is. */
|
|
34
|
+
ask(text, sent) {
|
|
35
|
+
const calls = this.call.calls;
|
|
36
|
+
const partner = this.partner;
|
|
37
|
+
partner === null || partner === void 0 ? void 0 : partner.say(text, sent ? { sent } : undefined).then(reply => calls === this.call.calls && this.call.turnEnded(reply), () => calls === this.call.calls && this.call.state.active && this.reopen(partner, text, sent));
|
|
38
|
+
}
|
|
39
|
+
/** The user was done with the words of the draft: its answer is the reply; failing, the partner is asked as usual. */
|
|
40
|
+
kept(draft, said) {
|
|
41
|
+
const calls = this.call.calls;
|
|
42
|
+
const partner = this.partner;
|
|
43
|
+
draft.keep();
|
|
44
|
+
draft.reply.then(reply => calls === this.call.calls && this.call.turnEnded(reply), () => calls === this.call.calls && this.call.state.active && this.partner === partner && this.ask(said));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The partner did not answer (the Ta service restarted, its side of the call is gone): it opens again once and
|
|
48
|
+
* answers what was said; failing that, the conversation answers from then on. The call goes on either way.
|
|
49
|
+
*/
|
|
50
|
+
reopen(failed, text, sent) {
|
|
51
|
+
var _a, _b, _c;
|
|
52
|
+
var _d;
|
|
53
|
+
const calls = this.call.calls;
|
|
54
|
+
if (this.partner !== failed) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.close();
|
|
58
|
+
const again = (_d = (_c = (_b = (_a = this.options).openPartner) === null || _b === void 0 ? void 0 : _b.call(_a, true)) === null || _c === void 0 ? void 0 : _c.catch(() => undefined)) !== null && _d !== void 0 ? _d : Promise.resolve(undefined);
|
|
59
|
+
void again.then(partner => {
|
|
60
|
+
if (calls !== this.call.calls || !this.call.state.active) {
|
|
61
|
+
partner === null || partner === void 0 ? void 0 : partner.close();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!partner) {
|
|
65
|
+
this.call.set({ partnered: false });
|
|
66
|
+
if (sent) {
|
|
67
|
+
this.call.unsent();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.options.send(text).catch(() => this.call.state.active && this.call.unsent());
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.adopt(partner);
|
|
75
|
+
partner.say(text, sent ? { sent } : undefined).then(reply => calls === this.call.calls && this.call.turnEnded(reply), () => calls === this.call.calls && this.call.state.active && this.call.unsent());
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=call-partnering.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TaCallScene, type TaCallView } from '@celljs/ta-protocol';
|
|
2
|
+
import type { VoiceCall } from './voice-call.js';
|
|
3
|
+
/** What the view of a call shows of it now (VideoCallView): the user's camera, and how the call shows. */
|
|
4
|
+
interface Shown {
|
|
5
|
+
camera?: boolean;
|
|
6
|
+
view?: TaCallView;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* How a call is for the user (TaCallScene, docs/design/ta-call.md 13), from the call (video or voice, when it began),
|
|
10
|
+
* the device and what its view shows (the camera, full screen or small): given to the partner as the call opens and as
|
|
11
|
+
* it changes, and to the conversation itself in a direct call. The words are TaCallSceneUtil's alone.
|
|
12
|
+
*/
|
|
13
|
+
export declare namespace CallScenes {
|
|
14
|
+
function of(call: VoiceCall, device: TaCallScene['device']): TaCallScene;
|
|
15
|
+
/** The view of the call shows this now. */
|
|
16
|
+
function show(call: VoiceCall, now: Shown): void;
|
|
17
|
+
/** Tells `changed` the scene of `call` as it changes and stays so a moment; until what it returns is called. */
|
|
18
|
+
function watch(call: VoiceCall, device: TaCallScene['device'], changed: (scene: TaCallScene) => void): () => void;
|
|
19
|
+
/**
|
|
20
|
+
* What a direct call tells the conversation with what the user said (SpokenReply.asked): what is new of the call
|
|
21
|
+
* since it last told it (TaCallSceneUtil.next). The conversation sees no picture of the camera.
|
|
22
|
+
*/
|
|
23
|
+
function next(call: VoiceCall, device: TaCallScene['device']): string | undefined;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { TaCallSceneUtil } from '@celljs/ta-protocol';
|
|
2
|
+
/** How long the scene must stay before it is told: a window that only passes (full, then small) is not. */
|
|
3
|
+
const SETTLE_MS = 800;
|
|
4
|
+
/**
|
|
5
|
+
* How a call is for the user (TaCallScene, docs/design/ta-call.md 13), from the call (video or voice, when it began),
|
|
6
|
+
* the device and what its view shows (the camera, full screen or small): given to the partner as the call opens and as
|
|
7
|
+
* it changes, and to the conversation itself in a direct call. The words are TaCallSceneUtil's alone.
|
|
8
|
+
*/
|
|
9
|
+
export var CallScenes;
|
|
10
|
+
(function (CallScenes) {
|
|
11
|
+
const shown = new WeakMap();
|
|
12
|
+
const listeners = new WeakMap();
|
|
13
|
+
/** What a direct call told its conversation, of the call that began then. */
|
|
14
|
+
const told = new WeakMap();
|
|
15
|
+
function of(call, device) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const { camera, view } = (_a = shown.get(call)) !== null && _a !== void 0 ? _a : {};
|
|
18
|
+
return {
|
|
19
|
+
video: call.state.video === true,
|
|
20
|
+
...(call.state.video && camera ? { camera } : {}),
|
|
21
|
+
...(call.state.video && view ? { view } : {}),
|
|
22
|
+
...(device ? { device } : {}),
|
|
23
|
+
since: (_b = call.state.since) !== null && _b !== void 0 ? _b : Date.now(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
CallScenes.of = of;
|
|
27
|
+
/** The view of the call shows this now. */
|
|
28
|
+
function show(call, now) {
|
|
29
|
+
var _a;
|
|
30
|
+
const before = shown.get(call);
|
|
31
|
+
if ((before === null || before === void 0 ? void 0 : before.camera) === now.camera && (before === null || before === void 0 ? void 0 : before.view) === now.view) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
shown.set(call, now);
|
|
35
|
+
for (const listener of [...((_a = listeners.get(call)) !== null && _a !== void 0 ? _a : [])]) {
|
|
36
|
+
listener();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
CallScenes.show = show;
|
|
40
|
+
/** Tells `changed` the scene of `call` as it changes and stays so a moment; until what it returns is called. */
|
|
41
|
+
function watch(call, device, changed) {
|
|
42
|
+
var _a;
|
|
43
|
+
let last = TaCallSceneUtil.key(of(call, device));
|
|
44
|
+
let timer;
|
|
45
|
+
const look = () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
timer = setTimeout(() => {
|
|
48
|
+
const scene = of(call, device);
|
|
49
|
+
const key = TaCallSceneUtil.key(scene);
|
|
50
|
+
if (call.state.active && key !== last) {
|
|
51
|
+
last = key;
|
|
52
|
+
changed(scene);
|
|
53
|
+
}
|
|
54
|
+
}, SETTLE_MS);
|
|
55
|
+
};
|
|
56
|
+
const own = (_a = listeners.get(call)) !== null && _a !== void 0 ? _a : new Set();
|
|
57
|
+
listeners.set(call, own);
|
|
58
|
+
own.add(look);
|
|
59
|
+
const offCall = call.subscribe(look);
|
|
60
|
+
return () => {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
own.delete(look);
|
|
63
|
+
offCall();
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
CallScenes.watch = watch;
|
|
67
|
+
/**
|
|
68
|
+
* What a direct call tells the conversation with what the user said (SpokenReply.asked): what is new of the call
|
|
69
|
+
* since it last told it (TaCallSceneUtil.next). The conversation sees no picture of the camera.
|
|
70
|
+
*/
|
|
71
|
+
function next(call, device) {
|
|
72
|
+
const scene = of(call, device);
|
|
73
|
+
let was = told.get(call);
|
|
74
|
+
if ((was === null || was === void 0 ? void 0 : was.since) !== scene.since) {
|
|
75
|
+
was = { since: scene.since, told: {} };
|
|
76
|
+
told.set(call, was);
|
|
77
|
+
}
|
|
78
|
+
return TaCallSceneUtil.next(scene, was.told, false, Date.now());
|
|
79
|
+
}
|
|
80
|
+
CallScenes.next = next;
|
|
81
|
+
})(CallScenes || (CallScenes = {}));
|
|
82
|
+
//# sourceMappingURL=call-scenes.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mood } from '../avatar/dino-avatar.js';
|
|
1
2
|
import type { Translate } from '../i18n/use-t.js';
|
|
2
3
|
import { type ScreenPartSpec, type TaScreen } from '../screen/screen-protocol.js';
|
|
3
4
|
import type { CallPhase } from './voice-call-protocol.js';
|
|
@@ -32,6 +33,8 @@ export declare namespace CallScreen {
|
|
|
32
33
|
}
|
|
33
34
|
/** What the call is at, as its bar says. */
|
|
34
35
|
function phase(t: Translate, seen: Pick<Seen, 'phase' | 'paused' | 'heard'>): string;
|
|
36
|
+
/** How Ta's face looks for what the call is at (CallFace). */
|
|
37
|
+
function mood(seen: Pick<Seen, 'phase' | 'paused'>): Mood;
|
|
35
38
|
/** Presses the button of an action of the call where it shows, as the user would; else does what it does. */
|
|
36
39
|
function press(screen: Pick<TaScreen, 'element'>, name: string, otherwise: () => void): void;
|
|
37
40
|
/** The part of the screen of the call: its state in a line, and what its buttons do now. */
|
|
@@ -24,6 +24,21 @@ export var CallScreen;
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
CallScreen.phase = phase;
|
|
27
|
+
/** How Ta's face looks for what the call is at (CallFace). */
|
|
28
|
+
function mood(seen) {
|
|
29
|
+
if (seen.paused) {
|
|
30
|
+
return 'sleeping';
|
|
31
|
+
}
|
|
32
|
+
switch (seen.phase) {
|
|
33
|
+
case 'speaking':
|
|
34
|
+
return 'speaking';
|
|
35
|
+
case 'listening':
|
|
36
|
+
return 'listening';
|
|
37
|
+
default:
|
|
38
|
+
return 'thinking';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
CallScreen.mood = mood;
|
|
27
42
|
/** Presses the button of an action of the call where it shows, as the user would; else does what it does. */
|
|
28
43
|
function press(screen, name, otherwise) {
|
|
29
44
|
const button = screen.element(CallScreen.PART, undefined, name);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { TaBargeIn } from '@celljs/ta-protocol';
|
|
2
|
+
import { type Doubt } from './realtime-voice-protocol.js';
|
|
3
|
+
/** What a piece of the microphone is (MicSense.measure). */
|
|
4
|
+
export interface MicPiece {
|
|
5
|
+
/** How loud (RMS, 0 to 1). */
|
|
6
|
+
level: number;
|
|
7
|
+
/** Periodic at the pitch of a voice: a vowel of someone speaking, not a cough, a knock, a fan. */
|
|
8
|
+
voiced: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What the microphone hears, piece by piece (docs/design/ta-voice.md 10): whether a piece is voiced, and the floor of
|
|
12
|
+
* the room, as minimum statistics do: it falls at once to a quieter piece, and rises only to what is not voiced (a fan,
|
|
13
|
+
* the hum of a room), so that the user speaking on and on never becomes the room.
|
|
14
|
+
*/
|
|
15
|
+
export declare class MicSense {
|
|
16
|
+
/** The floor of the room: the quietest it was lately, of what is not speech. */
|
|
17
|
+
floor: number;
|
|
18
|
+
measure(samples: Float32Array, rate: number): MicPiece;
|
|
19
|
+
/**
|
|
20
|
+
* A piece of the microphone while Ta reads and a sound may be the user cutting in (docs/design/ta-voice.md 10):
|
|
21
|
+
* voiced speech louder than `speech` in a run (gaps under GAP_MS) lowers the reading after DUCK_MS ('duck') and cuts
|
|
22
|
+
* in after speechMs ('cut'), unless it is no louder than `echo` (Ta's own voice heard back). What is not voiced (a
|
|
23
|
+
* cough, a knock) only counts as a gap.
|
|
24
|
+
*/
|
|
25
|
+
static weigh(doubt: Doubt, piece: MicPiece, ms: number, speech: number, echo: number, barge: TaBargeIn): 'duck' | 'cut' | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* How periodic `samples` are at the pitch of a voice: the highest normalized autocorrelation over the lags of
|
|
28
|
+
* PITCH_LOW to PITCH_HIGH, on samples averaged down to about VOICING_RATE; 0 for silence or noise, near 1 for a vowel.
|
|
29
|
+
*/
|
|
30
|
+
static voicing(samples: Float32Array, rate: number): number;
|
|
31
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PcmUtil } from './pcm-util.js';
|
|
2
|
+
import { DUCK_MS, GAP_MS } from './realtime-voice-protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* How fast the floor of the room rises, a step of 100 ms, to a piece louder than it that is not voiced: a fan turned on
|
|
5
|
+
* is the room in about two seconds. A voiced piece (someone speaking) never raises it.
|
|
6
|
+
*/
|
|
7
|
+
const RISE = 1.15;
|
|
8
|
+
/** The floor as a call begins: a quiet room, until the microphone says otherwise. */
|
|
9
|
+
const FLOOR = 0.003;
|
|
10
|
+
/** Normalized autocorrelation at the pitch of a voice above which a piece is voiced: vowels are, a cough or a knock not. */
|
|
11
|
+
const VOICED = 0.5;
|
|
12
|
+
/** The pitch a voice may have, in Hz. */
|
|
13
|
+
const PITCH_LOW = 70;
|
|
14
|
+
const PITCH_HIGH = 400;
|
|
15
|
+
/** The rate voicing is reckoned at: enough for a pitch, little to compute. */
|
|
16
|
+
const VOICING_RATE = 8000;
|
|
17
|
+
/**
|
|
18
|
+
* What the microphone hears, piece by piece (docs/design/ta-voice.md 10): whether a piece is voiced, and the floor of
|
|
19
|
+
* the room, as minimum statistics do: it falls at once to a quieter piece, and rises only to what is not voiced (a fan,
|
|
20
|
+
* the hum of a room), so that the user speaking on and on never becomes the room.
|
|
21
|
+
*/
|
|
22
|
+
export class MicSense {
|
|
23
|
+
constructor() {
|
|
24
|
+
/** The floor of the room: the quietest it was lately, of what is not speech. */
|
|
25
|
+
this.floor = FLOOR;
|
|
26
|
+
}
|
|
27
|
+
measure(samples, rate) {
|
|
28
|
+
const level = PcmUtil.rms(samples);
|
|
29
|
+
const voiced = MicSense.voicing(samples, rate) >= VOICED;
|
|
30
|
+
if (level < this.floor) {
|
|
31
|
+
this.floor = this.floor * 0.6 + level * 0.4;
|
|
32
|
+
}
|
|
33
|
+
else if (!voiced) {
|
|
34
|
+
this.floor = Math.min(level, this.floor * RISE ** ((samples.length / rate) * 10));
|
|
35
|
+
}
|
|
36
|
+
return { level, voiced };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A piece of the microphone while Ta reads and a sound may be the user cutting in (docs/design/ta-voice.md 10):
|
|
40
|
+
* voiced speech louder than `speech` in a run (gaps under GAP_MS) lowers the reading after DUCK_MS ('duck') and cuts
|
|
41
|
+
* in after speechMs ('cut'), unless it is no louder than `echo` (Ta's own voice heard back). What is not voiced (a
|
|
42
|
+
* cough, a knock) only counts as a gap.
|
|
43
|
+
*/
|
|
44
|
+
static weigh(doubt, piece, ms, speech, echo, barge) {
|
|
45
|
+
const loud = piece.level >= speech;
|
|
46
|
+
if (loud && piece.level < echo) {
|
|
47
|
+
doubt.echoed = true;
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
if (!loud || !piece.voiced) {
|
|
51
|
+
doubt.quiet += ms;
|
|
52
|
+
if (doubt.quiet >= GAP_MS) {
|
|
53
|
+
doubt.loud = 0;
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
doubt.quiet = 0;
|
|
58
|
+
doubt.voiced = true;
|
|
59
|
+
doubt.loud += ms;
|
|
60
|
+
if (doubt.loud >= barge.speechMs) {
|
|
61
|
+
return 'cut';
|
|
62
|
+
}
|
|
63
|
+
if (!doubt.ducked && doubt.loud >= Math.min(DUCK_MS, barge.speechMs)) {
|
|
64
|
+
doubt.ducked = true;
|
|
65
|
+
return 'duck';
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* How periodic `samples` are at the pitch of a voice: the highest normalized autocorrelation over the lags of
|
|
71
|
+
* PITCH_LOW to PITCH_HIGH, on samples averaged down to about VOICING_RATE; 0 for silence or noise, near 1 for a vowel.
|
|
72
|
+
*/
|
|
73
|
+
static voicing(samples, rate) {
|
|
74
|
+
const step = Math.max(1, Math.floor(rate / VOICING_RATE));
|
|
75
|
+
const n = Math.floor(samples.length / step);
|
|
76
|
+
if (n < 64) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
const x = new Float32Array(n);
|
|
80
|
+
let mean = 0;
|
|
81
|
+
for (let i = 0; i < n; i++) {
|
|
82
|
+
let sum = 0;
|
|
83
|
+
for (let j = 0; j < step; j++) {
|
|
84
|
+
sum += samples[i * step + j];
|
|
85
|
+
}
|
|
86
|
+
x[i] = sum / step;
|
|
87
|
+
mean += x[i];
|
|
88
|
+
}
|
|
89
|
+
mean /= n;
|
|
90
|
+
let energy = 0;
|
|
91
|
+
for (let i = 0; i < n; i++) {
|
|
92
|
+
x[i] -= mean;
|
|
93
|
+
energy += x[i] * x[i];
|
|
94
|
+
}
|
|
95
|
+
if (energy < 1e-8) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
const at = rate / step;
|
|
99
|
+
const low = Math.max(1, Math.floor(at / PITCH_HIGH));
|
|
100
|
+
const high = Math.min(n - 32, Math.ceil(at / PITCH_LOW));
|
|
101
|
+
let best = 0;
|
|
102
|
+
for (let lag = low; lag <= high; lag++) {
|
|
103
|
+
let cross = 0;
|
|
104
|
+
let a = 0;
|
|
105
|
+
let b = 0;
|
|
106
|
+
for (let i = 0; i + lag < n; i++) {
|
|
107
|
+
cross += x[i] * x[i + lag];
|
|
108
|
+
a += x[i] * x[i];
|
|
109
|
+
b += x[i + lag] * x[i + lag];
|
|
110
|
+
}
|
|
111
|
+
const r = a && b ? cross / Math.sqrt(a * b) : 0;
|
|
112
|
+
if (r > best) {
|
|
113
|
+
best = r;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return best;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=mic-sense.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What of the microphone a voice service hears (docs/design/ta-voice.md 9): speech, the sound louder than the room for
|
|
3
|
+
* two pieces at least, with the piece before it (its first sound) and HANG pieces after (the gaps between words); the
|
|
4
|
+
* rest goes as silence, so that the service neither answers a noise nor hears a knock or a cough as the user, and still
|
|
5
|
+
* hears them stop. Each piece waits for the next to be known, one piece of delay.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NoiseGate {
|
|
8
|
+
protected readonly hang: number;
|
|
9
|
+
protected pending?: Uint8Array;
|
|
10
|
+
protected wasLoud: boolean;
|
|
11
|
+
protected index: number;
|
|
12
|
+
protected lastVoiced: number;
|
|
13
|
+
constructor(hang?: number);
|
|
14
|
+
/** A piece of PCM16, `loud` when louder than the room: the piece before it as it should go, once known. */
|
|
15
|
+
push(pcm: Uint8Array, loud: boolean): Uint8Array | undefined;
|
|
16
|
+
/** The user is known to speak now (they cut in): what comes goes as it is, a while. */
|
|
17
|
+
open(): void;
|
|
18
|
+
/** What was heard is not to go (the service's own answer played): it begins again. */
|
|
19
|
+
reset(): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What of the microphone goes to a voice service (docs/design/ta-voice.md 9): speech alone (NoiseGate), and nothing
|
|
23
|
+
* while what plays is its own answer, which it would hear and answer: that is held, and goes only once the user cuts in.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MicFilter {
|
|
26
|
+
protected held: Uint8Array[];
|
|
27
|
+
protected readonly gate: NoiseGate;
|
|
28
|
+
/** A piece of the microphone: what to send now. `playing`: its own answer plays, or just did. */
|
|
29
|
+
take(pcm: Uint8Array, loud: boolean, playing: boolean): Uint8Array | undefined;
|
|
30
|
+
/** The user cut in: what was held of them, from the start of their words, to send now; then all they say. */
|
|
31
|
+
cutIn(): Uint8Array[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CHUNK_MS, HELD_MS } from './realtime-voice-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* What of the microphone a voice service hears (docs/design/ta-voice.md 9): speech, the sound louder than the room for
|
|
4
|
+
* two pieces at least, with the piece before it (its first sound) and HANG pieces after (the gaps between words); the
|
|
5
|
+
* rest goes as silence, so that the service neither answers a noise nor hears a knock or a cough as the user, and still
|
|
6
|
+
* hears them stop. Each piece waits for the next to be known, one piece of delay.
|
|
7
|
+
*/
|
|
8
|
+
export class NoiseGate {
|
|
9
|
+
constructor(hang = 4) {
|
|
10
|
+
this.hang = hang;
|
|
11
|
+
this.wasLoud = false;
|
|
12
|
+
this.index = 0;
|
|
13
|
+
this.lastVoiced = Number.NEGATIVE_INFINITY;
|
|
14
|
+
}
|
|
15
|
+
/** A piece of PCM16, `loud` when louder than the room: the piece before it as it should go, once known. */
|
|
16
|
+
push(pcm, loud) {
|
|
17
|
+
const at = this.index++;
|
|
18
|
+
if (loud && this.wasLoud) {
|
|
19
|
+
this.lastVoiced = at;
|
|
20
|
+
}
|
|
21
|
+
this.wasLoud = loud;
|
|
22
|
+
const pending = this.pending;
|
|
23
|
+
this.pending = pcm;
|
|
24
|
+
if (!pending) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return this.lastVoiced >= at - 1 - this.hang ? pending : new Uint8Array(pending.length);
|
|
28
|
+
}
|
|
29
|
+
/** The user is known to speak now (they cut in): what comes goes as it is, a while. */
|
|
30
|
+
open() {
|
|
31
|
+
this.lastVoiced = this.index;
|
|
32
|
+
}
|
|
33
|
+
/** What was heard is not to go (the service's own answer played): it begins again. */
|
|
34
|
+
reset() {
|
|
35
|
+
this.pending = undefined;
|
|
36
|
+
this.wasLoud = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What of the microphone goes to a voice service (docs/design/ta-voice.md 9): speech alone (NoiseGate), and nothing
|
|
41
|
+
* while what plays is its own answer, which it would hear and answer: that is held, and goes only once the user cuts in.
|
|
42
|
+
*/
|
|
43
|
+
export class MicFilter {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.held = [];
|
|
46
|
+
this.gate = new NoiseGate();
|
|
47
|
+
}
|
|
48
|
+
/** A piece of the microphone: what to send now. `playing`: its own answer plays, or just did. */
|
|
49
|
+
take(pcm, loud, playing) {
|
|
50
|
+
if (playing) {
|
|
51
|
+
this.held.push(pcm);
|
|
52
|
+
this.held.splice(0, Math.max(0, this.held.length - HELD_MS / CHUNK_MS));
|
|
53
|
+
this.gate.reset();
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// What was held was the room while it played, not the user.
|
|
57
|
+
this.held.length = 0;
|
|
58
|
+
return this.gate.push(pcm, loud);
|
|
59
|
+
}
|
|
60
|
+
/** The user cut in: what was held of them, from the start of their words, to send now; then all they say. */
|
|
61
|
+
cutIn() {
|
|
62
|
+
this.gate.open();
|
|
63
|
+
return this.held.splice(0);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=noise-gate.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The samples of a microphone, made PCM16 mono at another rate. */
|
|
2
|
+
export declare namespace PcmUtil {
|
|
3
|
+
/** Linear resampling of mono float samples to `to` Hz, as PCM16 little-endian. */
|
|
4
|
+
function toPcm16(samples: Float32Array, from: number, to: number): Uint8Array;
|
|
5
|
+
function toFloat(pcm: Uint8Array): Float32Array;
|
|
6
|
+
function base64(bytes: Uint8Array): string;
|
|
7
|
+
/** How loud samples are (RMS, 0 to 1). */
|
|
8
|
+
function rms(samples: Float32Array): number;
|
|
9
|
+
function bytes(base64: string): Uint8Array;
|
|
10
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** The samples of a microphone, made PCM16 mono at another rate. */
|
|
2
|
+
export var PcmUtil;
|
|
3
|
+
(function (PcmUtil) {
|
|
4
|
+
/** Linear resampling of mono float samples to `to` Hz, as PCM16 little-endian. */
|
|
5
|
+
function toPcm16(samples, from, to) {
|
|
6
|
+
const ratio = from / to;
|
|
7
|
+
const length = Math.floor(samples.length / ratio);
|
|
8
|
+
const out = new DataView(new ArrayBuffer(length * 2));
|
|
9
|
+
for (let i = 0; i < length; i++) {
|
|
10
|
+
const at = i * ratio;
|
|
11
|
+
const low = Math.floor(at);
|
|
12
|
+
const high = Math.min(low + 1, samples.length - 1);
|
|
13
|
+
const value = samples[low] + (samples[high] - samples[low]) * (at - low);
|
|
14
|
+
out.setInt16(i * 2, Math.max(-1, Math.min(1, value)) * 0x7fff, true);
|
|
15
|
+
}
|
|
16
|
+
return new Uint8Array(out.buffer);
|
|
17
|
+
}
|
|
18
|
+
PcmUtil.toPcm16 = toPcm16;
|
|
19
|
+
function toFloat(pcm) {
|
|
20
|
+
const view = new DataView(pcm.buffer, pcm.byteOffset, pcm.byteLength);
|
|
21
|
+
const out = new Float32Array(Math.floor(pcm.byteLength / 2));
|
|
22
|
+
for (let i = 0; i < out.length; i++) {
|
|
23
|
+
out[i] = view.getInt16(i * 2, true) / 0x8000;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
PcmUtil.toFloat = toFloat;
|
|
28
|
+
function base64(bytes) {
|
|
29
|
+
let text = '';
|
|
30
|
+
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
31
|
+
text += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
32
|
+
}
|
|
33
|
+
return btoa(text);
|
|
34
|
+
}
|
|
35
|
+
PcmUtil.base64 = base64;
|
|
36
|
+
/** How loud samples are (RMS, 0 to 1). */
|
|
37
|
+
function rms(samples) {
|
|
38
|
+
let sum = 0;
|
|
39
|
+
for (const sample of samples) {
|
|
40
|
+
sum += sample * sample;
|
|
41
|
+
}
|
|
42
|
+
return Math.sqrt(sum / (samples.length || 1));
|
|
43
|
+
}
|
|
44
|
+
PcmUtil.rms = rms;
|
|
45
|
+
function bytes(base64) {
|
|
46
|
+
const text = atob(base64);
|
|
47
|
+
const out = new Uint8Array(text.length);
|
|
48
|
+
for (let i = 0; i < text.length; i++) {
|
|
49
|
+
out[i] = text.charCodeAt(i);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
PcmUtil.bytes = bytes;
|
|
54
|
+
})(PcmUtil || (PcmUtil = {}));
|
|
55
|
+
//# sourceMappingURL=pcm-util.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RealtimeVoice
|
|
1
|
+
import { RealtimeVoice } from './realtime-voice.js';
|
|
2
|
+
import type { RealtimeVoiceHost } from './realtime-voice-protocol.js';
|
|
2
3
|
import type { CallVoice } from './voice-call-protocol.js';
|
|
3
4
|
/** How long a voice service opened to read stays open after it read, ready for the next reply. */
|
|
4
5
|
export declare const READ_IDLE_MS = 60000;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { TaVoiceEvent, TaVoiceServer } from '@celljs/ta-protocol';
|
|
2
|
+
import type { CallTalk } from './voice-call-protocol.js';
|
|
3
|
+
import type { VoiceReading } from './voice-reading.js';
|
|
4
|
+
/** What a voice of a service uses of the page's connection. */
|
|
5
|
+
export interface RealtimeVoiceHost {
|
|
6
|
+
readonly voice: TaVoiceServer;
|
|
7
|
+
onVoiceEvent(listener: (event: TaVoiceEvent) => void): () => void;
|
|
8
|
+
/**
|
|
9
|
+
* How the connection is: once it is not online, the voice is gone (ta serve closes the voices of a connection with
|
|
10
|
+
* it, and one that restarted has none), though no event of it says so.
|
|
11
|
+
*/
|
|
12
|
+
subscribe?(listener: (state: {
|
|
13
|
+
status: string;
|
|
14
|
+
}) => void): () => void;
|
|
15
|
+
}
|
|
16
|
+
/** How long a listen waits for a sentence before it counts as silence. */
|
|
17
|
+
export declare const REALTIME_SILENCE_MS = 12000;
|
|
18
|
+
/** The audio sent at once, in ms of sound. */
|
|
19
|
+
export declare const CHUNK_MS = 100;
|
|
20
|
+
/**
|
|
21
|
+
* Of a voice that thinks: what the microphone heard this long before the user cut in is sent then, the start of their
|
|
22
|
+
* words; and it sends nothing this long after its answer played, what is left of it in the room.
|
|
23
|
+
*/
|
|
24
|
+
export declare const HELD_MS = 800;
|
|
25
|
+
export declare const ECHO_TAIL_MS = 300;
|
|
26
|
+
/** Speech that cuts in is at least this many times as loud as the sound around it (noise, what is left of Ta's echo). */
|
|
27
|
+
export declare const ABOVE_NOISE = 2;
|
|
28
|
+
/** The sound around the user counts at most this loud: in a din, the level of BargeIn.level times this is speech. */
|
|
29
|
+
export declare const NOISE_CAP = 0.08;
|
|
30
|
+
/** ms of voiced speech before the reading goes lower: a cough, a knock, a word of someone else does not. */
|
|
31
|
+
export declare const DUCK_MS = 200;
|
|
32
|
+
/** A gap this long in what may be the user cutting in ends its run: coughs apart do not add up. */
|
|
33
|
+
export declare const GAP_MS = 250;
|
|
34
|
+
/** What goes to a voice service is louder than the floor of the room this many times (NoiseGate), and at least GATE_LEVEL. */
|
|
35
|
+
export declare const GATE_ABOVE = 2.5;
|
|
36
|
+
export declare const GATE_LEVEL = 0.004;
|
|
37
|
+
export interface Hearing {
|
|
38
|
+
onText(text: string, final: boolean): void;
|
|
39
|
+
onEnd(error?: string): void;
|
|
40
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
41
|
+
/** The user began a sentence: it does not end as silence. */
|
|
42
|
+
speaking: boolean;
|
|
43
|
+
/** What they said before they paused on a word that leads on: what they say next goes on from it. */
|
|
44
|
+
before?: string;
|
|
45
|
+
}
|
|
46
|
+
/** A sound heard while Ta reads, not yet known to be the user cutting in. */
|
|
47
|
+
export interface Doubt {
|
|
48
|
+
/** ms of voiced speech in it, in a run with gaps shorter than GAP_MS. */
|
|
49
|
+
loud: number;
|
|
50
|
+
/** ms since the last of it was voiced speech: past GAP_MS, the run begins again. */
|
|
51
|
+
quiet: number;
|
|
52
|
+
/** The reading went lower (DUCK_MS of speech). */
|
|
53
|
+
ducked?: boolean;
|
|
54
|
+
timer: ReturnType<typeof setTimeout>;
|
|
55
|
+
/** Some of it was loud as speech, but no louder than Ta's own voice heard back (TaBargeIn.echo). */
|
|
56
|
+
echoed?: boolean;
|
|
57
|
+
/** Some of it was louder than that: the user's. */
|
|
58
|
+
voiced?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface Reading {
|
|
61
|
+
say: number;
|
|
62
|
+
onEnd(): void;
|
|
63
|
+
/** All its audio came: it ends once the last piece played. */
|
|
64
|
+
said: boolean;
|
|
65
|
+
/** Where it is as it plays, its captions and the face of a video call by it (VoiceReading). */
|
|
66
|
+
clock?: VoiceReading;
|
|
67
|
+
}
|
|
68
|
+
/** A call its own model answers (converse): told what goes on; the answers up to `cut` stopped as the user spoke. */
|
|
69
|
+
export interface Talking {
|
|
70
|
+
talk: CallTalk;
|
|
71
|
+
cut: number;
|
|
72
|
+
muted: boolean;
|
|
73
|
+
/** The words of its answer `say` so far, in sentences. */
|
|
74
|
+
reply?: {
|
|
75
|
+
say: number;
|
|
76
|
+
pieces: readonly string[];
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export declare namespace Talking {
|
|
80
|
+
/** Its answer `say` so far: kept for the reading of its sound, which times its sentences by it as they come. */
|
|
81
|
+
function reply(talking: Talking, say: number, text: string, clock: Pick<VoiceReading, 'say' | 'words'> | undefined): void;
|
|
82
|
+
/** The sentences of the answer `say` known as its sound begins; one empty when none yet. */
|
|
83
|
+
function pieces(talking: Talking, say: number): readonly string[];
|
|
84
|
+
}
|