@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.
Files changed (264) hide show
  1. package/esm/browser/assistant/assistant-role.d.ts +9 -4
  2. package/esm/browser/assistant/assistant-role.js +17 -5
  3. package/esm/browser/assistant/assistant-task-util.d.ts +6 -0
  4. package/esm/browser/assistant/assistant-task-util.js +12 -1
  5. package/esm/browser/assistant/assistant-view.js +4 -1
  6. package/esm/browser/assistant/assistant.d.ts +2 -1
  7. package/esm/browser/assistant/assistant.js +9 -7
  8. package/esm/browser/assistant/call-conversing.d.ts +45 -0
  9. package/esm/browser/assistant/call-conversing.js +91 -0
  10. package/esm/browser/assistant/call-face.d.ts +13 -0
  11. package/esm/browser/assistant/call-face.js +81 -0
  12. package/esm/browser/assistant/call-keeper.d.ts +8 -4
  13. package/esm/browser/assistant/call-keeper.js +32 -11
  14. package/esm/browser/assistant/call-partnering.d.ts +37 -0
  15. package/esm/browser/assistant/call-partnering.js +79 -0
  16. package/esm/browser/assistant/call-scenes.d.ts +25 -0
  17. package/esm/browser/assistant/call-scenes.js +82 -0
  18. package/esm/browser/assistant/call-screen.d.ts +3 -0
  19. package/esm/browser/assistant/call-screen.js +15 -0
  20. package/esm/browser/assistant/mic-sense.d.ts +31 -0
  21. package/esm/browser/assistant/mic-sense.js +119 -0
  22. package/esm/browser/assistant/noise-gate.d.ts +32 -0
  23. package/esm/browser/assistant/noise-gate.js +66 -0
  24. package/esm/browser/assistant/pcm-util.d.ts +10 -0
  25. package/esm/browser/assistant/pcm-util.js +55 -0
  26. package/esm/browser/assistant/read-aloud.d.ts +2 -1
  27. package/esm/browser/assistant/realtime-voice-protocol.d.ts +84 -0
  28. package/esm/browser/assistant/realtime-voice-protocol.js +40 -0
  29. package/esm/browser/assistant/realtime-voice.d.ts +50 -62
  30. package/esm/browser/assistant/realtime-voice.js +213 -134
  31. package/esm/browser/assistant/spoken-timeline.d.ts +27 -0
  32. package/esm/browser/assistant/spoken-timeline.js +49 -0
  33. package/esm/browser/assistant/voice-call-bar.d.ts +9 -2
  34. package/esm/browser/assistant/voice-call-bar.js +81 -31
  35. package/esm/browser/assistant/voice-call-protocol.d.ts +61 -4
  36. package/esm/browser/assistant/voice-call.d.ts +16 -23
  37. package/esm/browser/assistant/voice-call.js +134 -117
  38. package/esm/browser/assistant/voice-reading.d.ts +83 -0
  39. package/esm/browser/assistant/voice-reading.js +150 -0
  40. package/esm/browser/avatar/dino-talk.d.ts +15 -0
  41. package/esm/browser/avatar/dino-talk.js +34 -0
  42. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  43. package/esm/browser/components/conversation-scroll-util.d.ts +8 -1
  44. package/esm/browser/components/conversation-scroll-util.js +21 -0
  45. package/esm/browser/components/conversation-scroll.js +10 -11
  46. package/esm/browser/components/gallery.js +28 -7
  47. package/esm/browser/components/host-view.d.ts +1 -1
  48. package/esm/browser/components/image-pull.d.ts +64 -0
  49. package/esm/browser/components/image-pull.js +202 -0
  50. package/esm/browser/components/kept-call-bar.js +2 -1
  51. package/esm/browser/components/lightbox.d.ts +1 -1
  52. package/esm/browser/components/lightbox.js +57 -2
  53. package/esm/browser/components/markdown.d.ts +3 -1
  54. package/esm/browser/components/markdown.js +8 -4
  55. package/esm/browser/components/partner-row.js +2 -1
  56. package/esm/browser/components/relay-services.d.ts +9 -3
  57. package/esm/browser/components/relay-services.js +73 -35
  58. package/esm/browser/components/session-view.js +4 -2
  59. package/esm/browser/components/settings-parts.js +2 -0
  60. package/esm/browser/components/ta-avatar.d.ts +15 -1
  61. package/esm/browser/components/ta-avatar.js +38 -5
  62. package/esm/browser/components/voice-services.js +6 -1
  63. package/esm/browser/extension/web-api-call.d.ts +64 -2
  64. package/esm/browser/extension/web-api-contributions.d.ts +1 -0
  65. package/esm/browser/extension/web-api-partners.d.ts +2 -0
  66. package/esm/browser/extension/web-extension-api.d.ts +6 -6
  67. package/esm/browser/extension/web-extension-context.js +1 -0
  68. package/esm/browser/extension/web-extension-protocol.d.ts +3 -1
  69. package/esm/browser/extension/web-extension-run.d.ts +3 -2
  70. package/esm/browser/extension/web-extension-run.js +2 -0
  71. package/esm/browser/i18n/locales.d.ts +24 -5
  72. package/esm/browser/i18n/messages-ja.js +25 -6
  73. package/esm/browser/i18n/messages-zh-tw.js +25 -6
  74. package/esm/browser/i18n/messages.d.ts +23 -4
  75. package/esm/browser/i18n/messages.js +50 -12
  76. package/esm/browser/markdown/code-renderers.d.ts +2 -0
  77. package/esm/browser/markdown/code-renderers.js +2 -0
  78. package/esm/browser/screen/page-answers.d.ts +2 -1
  79. package/esm/browser/screen/page-answers.js +7 -4
  80. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  81. package/esm/browser/settings/settings-protocol.js +2 -0
  82. package/esm/browser/style/chat-list.d.ts +1 -1
  83. package/esm/browser/style/chat-list.js +1 -1
  84. package/esm/browser/style/conversation.d.ts +1 -1
  85. package/esm/browser/style/conversation.js +6 -1
  86. package/esm/browser/style/device.js +1 -0
  87. package/esm/browser/style/dialogs.d.ts +1 -1
  88. package/esm/browser/style/dialogs.js +1 -1
  89. package/esm/browser/style/layout.d.ts +1 -1
  90. package/esm/browser/style/layout.js +135 -57
  91. package/esm/browser/style/shell.d.ts +1 -1
  92. package/esm/browser/style/shell.js +8 -0
  93. package/esm/browser/style/video-call.d.ts +2 -0
  94. package/esm/browser/style/video-call.js +52 -0
  95. package/esm/browser/style.js +2 -0
  96. package/esm/browser/util/desktop.d.ts +10 -1
  97. package/esm/browser/util/desktop.js +10 -0
  98. package/esm/browser/util/image-pull.d.ts +61 -0
  99. package/esm/browser/util/image-pull.js +88 -0
  100. package/esm/browser/util/spoken.d.ts +3 -3
  101. package/esm/browser/util/spoken.js +4 -4
  102. package/esm/browser/video-call/call-camera.d.ts +59 -0
  103. package/esm/browser/video-call/call-camera.js +188 -0
  104. package/esm/browser/video-call/call-window.d.ts +19 -0
  105. package/esm/browser/video-call/call-window.js +80 -0
  106. package/esm/browser/video-call/clip-plan.d.ts +47 -0
  107. package/esm/browser/video-call/clip-plan.js +60 -0
  108. package/esm/browser/video-call/face-clips.d.ts +33 -0
  109. package/esm/browser/video-call/face-clips.js +93 -0
  110. package/esm/browser/video-call/face-files.d.ts +31 -0
  111. package/esm/browser/video-call/face-files.js +77 -0
  112. package/esm/browser/video-call/video-call-view.d.ts +19 -0
  113. package/esm/browser/video-call/video-call-view.js +214 -0
  114. package/esm/browser/video-call/video-face.d.ts +13 -0
  115. package/esm/browser/video-call/video-face.js +497 -0
  116. package/esm/browser/workbench-hosts.d.ts +1 -0
  117. package/esm/browser/workbench-protocol.d.ts +2 -0
  118. package/esm/browser/workbench-util.d.ts +5 -0
  119. package/esm/browser/workbench-util.js +18 -0
  120. package/esm/browser/workbench.d.ts +6 -0
  121. package/esm/browser/workbench.js +36 -5
  122. package/lib/browser/assistant/assistant-role.d.ts +9 -4
  123. package/lib/browser/assistant/assistant-role.js +17 -5
  124. package/lib/browser/assistant/assistant-task-util.d.ts +6 -0
  125. package/lib/browser/assistant/assistant-task-util.js +11 -0
  126. package/lib/browser/assistant/assistant-view.js +3 -0
  127. package/lib/browser/assistant/assistant.d.ts +2 -1
  128. package/lib/browser/assistant/assistant.js +9 -7
  129. package/lib/browser/assistant/call-conversing.d.ts +46 -0
  130. package/lib/browser/assistant/call-conversing.js +96 -0
  131. package/lib/browser/assistant/call-face.d.ts +14 -0
  132. package/lib/browser/assistant/call-face.js +117 -0
  133. package/lib/browser/assistant/call-keeper.d.ts +8 -4
  134. package/lib/browser/assistant/call-keeper.js +32 -11
  135. package/lib/browser/assistant/call-partnering.d.ts +38 -0
  136. package/lib/browser/assistant/call-partnering.js +83 -0
  137. package/lib/browser/assistant/call-scenes.d.ts +26 -0
  138. package/lib/browser/assistant/call-scenes.js +85 -0
  139. package/lib/browser/assistant/call-screen.d.ts +3 -0
  140. package/lib/browser/assistant/call-screen.js +15 -0
  141. package/lib/browser/assistant/mic-sense.d.ts +32 -0
  142. package/lib/browser/assistant/mic-sense.js +123 -0
  143. package/lib/browser/assistant/noise-gate.d.ts +33 -0
  144. package/lib/browser/assistant/noise-gate.js +71 -0
  145. package/lib/browser/assistant/pcm-util.d.ts +11 -0
  146. package/lib/browser/assistant/pcm-util.js +58 -0
  147. package/lib/browser/assistant/read-aloud.d.ts +2 -1
  148. package/lib/browser/assistant/realtime-voice-protocol.d.ts +85 -0
  149. package/lib/browser/assistant/realtime-voice-protocol.js +43 -0
  150. package/lib/browser/assistant/realtime-voice.d.ts +50 -62
  151. package/lib/browser/assistant/realtime-voice.js +217 -138
  152. package/lib/browser/assistant/spoken-timeline.d.ts +28 -0
  153. package/lib/browser/assistant/spoken-timeline.js +53 -0
  154. package/lib/browser/assistant/voice-call-bar.d.ts +9 -2
  155. package/lib/browser/assistant/voice-call-bar.js +81 -30
  156. package/lib/browser/assistant/voice-call-protocol.d.ts +61 -4
  157. package/lib/browser/assistant/voice-call.d.ts +16 -23
  158. package/lib/browser/assistant/voice-call.js +134 -117
  159. package/lib/browser/assistant/voice-reading.d.ts +84 -0
  160. package/lib/browser/assistant/voice-reading.js +156 -0
  161. package/lib/browser/avatar/dino-talk.d.ts +16 -0
  162. package/lib/browser/avatar/dino-talk.js +37 -0
  163. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  164. package/lib/browser/components/conversation-scroll-util.d.ts +8 -1
  165. package/lib/browser/components/conversation-scroll-util.js +21 -0
  166. package/lib/browser/components/conversation-scroll.js +10 -11
  167. package/lib/browser/components/gallery.js +28 -7
  168. package/lib/browser/components/host-view.d.ts +1 -1
  169. package/lib/browser/components/image-pull.d.ts +65 -0
  170. package/lib/browser/components/image-pull.js +206 -0
  171. package/lib/browser/components/kept-call-bar.js +2 -1
  172. package/lib/browser/components/lightbox.d.ts +1 -1
  173. package/lib/browser/components/lightbox.js +57 -2
  174. package/lib/browser/components/markdown.d.ts +3 -1
  175. package/lib/browser/components/markdown.js +7 -3
  176. package/lib/browser/components/partner-row.js +2 -1
  177. package/lib/browser/components/relay-services.d.ts +9 -3
  178. package/lib/browser/components/relay-services.js +71 -33
  179. package/lib/browser/components/session-view.js +3 -1
  180. package/lib/browser/components/settings-parts.js +2 -0
  181. package/lib/browser/components/ta-avatar.d.ts +15 -1
  182. package/lib/browser/components/ta-avatar.js +38 -5
  183. package/lib/browser/components/voice-services.js +5 -0
  184. package/lib/browser/extension/web-api-call.d.ts +64 -2
  185. package/lib/browser/extension/web-api-contributions.d.ts +1 -0
  186. package/lib/browser/extension/web-api-partners.d.ts +2 -0
  187. package/lib/browser/extension/web-extension-api.d.ts +6 -6
  188. package/lib/browser/extension/web-extension-context.js +1 -0
  189. package/lib/browser/extension/web-extension-protocol.d.ts +3 -1
  190. package/lib/browser/extension/web-extension-run.d.ts +3 -2
  191. package/lib/browser/extension/web-extension-run.js +2 -0
  192. package/lib/browser/i18n/locales.d.ts +24 -5
  193. package/lib/browser/i18n/messages-ja.js +25 -6
  194. package/lib/browser/i18n/messages-zh-tw.js +25 -6
  195. package/lib/browser/i18n/messages.d.ts +23 -4
  196. package/lib/browser/i18n/messages.js +50 -12
  197. package/lib/browser/markdown/code-renderers.d.ts +2 -0
  198. package/lib/browser/markdown/code-renderers.js +3 -1
  199. package/lib/browser/screen/page-answers.d.ts +2 -1
  200. package/lib/browser/screen/page-answers.js +7 -4
  201. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  202. package/lib/browser/settings/settings-protocol.js +2 -0
  203. package/lib/browser/style/chat-list.d.ts +1 -1
  204. package/lib/browser/style/chat-list.js +1 -1
  205. package/lib/browser/style/conversation.d.ts +1 -1
  206. package/lib/browser/style/conversation.js +6 -1
  207. package/lib/browser/style/device.js +1 -0
  208. package/lib/browser/style/dialogs.d.ts +1 -1
  209. package/lib/browser/style/dialogs.js +1 -1
  210. package/lib/browser/style/layout.d.ts +1 -1
  211. package/lib/browser/style/layout.js +135 -57
  212. package/lib/browser/style/shell.d.ts +1 -1
  213. package/lib/browser/style/shell.js +8 -0
  214. package/lib/browser/style/video-call.d.ts +3 -0
  215. package/lib/browser/style/video-call.js +55 -0
  216. package/lib/browser/style.js +2 -0
  217. package/lib/browser/util/desktop.d.ts +10 -1
  218. package/lib/browser/util/desktop.js +10 -0
  219. package/lib/browser/util/image-pull.d.ts +62 -0
  220. package/lib/browser/util/image-pull.js +91 -0
  221. package/lib/browser/util/spoken.d.ts +3 -3
  222. package/lib/browser/util/spoken.js +4 -4
  223. package/lib/browser/video-call/call-camera.d.ts +60 -0
  224. package/lib/browser/video-call/call-camera.js +192 -0
  225. package/lib/browser/video-call/call-window.d.ts +20 -0
  226. package/lib/browser/video-call/call-window.js +83 -0
  227. package/lib/browser/video-call/clip-plan.d.ts +48 -0
  228. package/lib/browser/video-call/clip-plan.js +64 -0
  229. package/lib/browser/video-call/face-clips.d.ts +34 -0
  230. package/lib/browser/video-call/face-clips.js +96 -0
  231. package/lib/browser/video-call/face-files.d.ts +32 -0
  232. package/lib/browser/video-call/face-files.js +82 -0
  233. package/lib/browser/video-call/video-call-view.d.ts +20 -0
  234. package/lib/browser/video-call/video-call-view.js +250 -0
  235. package/lib/browser/video-call/video-face.d.ts +14 -0
  236. package/lib/browser/video-call/video-face.js +533 -0
  237. package/lib/browser/workbench-hosts.d.ts +1 -0
  238. package/lib/browser/workbench-protocol.d.ts +2 -0
  239. package/lib/browser/workbench-util.d.ts +5 -0
  240. package/lib/browser/workbench-util.js +18 -0
  241. package/lib/browser/workbench.d.ts +6 -0
  242. package/lib/browser/workbench.js +35 -4
  243. package/package.json +7 -7
  244. package/public/faces/README.md +27 -0
  245. package/public/faces/clap.mp4 +0 -0
  246. package/public/faces/dance.mp4 +0 -0
  247. package/public/faces/happy.mp4 +0 -0
  248. package/public/faces/heart.mp4 +0 -0
  249. package/public/faces/idle-1.mp4 +0 -0
  250. package/public/faces/idle-2.mp4 +0 -0
  251. package/public/faces/idle-3.mp4 +0 -0
  252. package/public/faces/laugh.mp4 +0 -0
  253. package/public/faces/lips.json +1 -0
  254. package/public/faces/listening.mp4 +0 -0
  255. package/public/faces/poster.jpg +0 -0
  256. package/public/faces/shy.mp4 +0 -0
  257. package/public/faces/sorry.mp4 +0 -0
  258. package/public/faces/stretch.mp4 +0 -0
  259. package/public/faces/surprised.mp4 +0 -0
  260. package/public/faces/talk-1.mp4 +0 -0
  261. package/public/faces/talk-2.mp4 +0 -0
  262. package/public/faces/think-2.mp4 +0 -0
  263. package/public/faces/thinking.mp4 +0 -0
  264. package/public/faces/wave.mp4 +0 -0
@@ -1,6 +1,9 @@
1
1
  import { TurnEnd } from '../util/turn-end.js';
2
2
  import { Voice } from '../util/voice.js';
3
+ import { CallConversing, CallDrafts } from './call-conversing.js';
4
+ import { CallPartnering } from './call-partnering.js';
3
5
  import { CallTurnEnd, RETRY_MS, SILENT_MS, SILENT_ROUNDS } from './call-turn-end.js';
6
+ import { CallSounds } from './voice-reading.js';
4
7
  import { VoiceReopen } from './voice-reopen.js';
5
8
  const IDLE = { active: false, phase: 'listening', heard: '' };
6
9
  /**
@@ -24,9 +27,36 @@ export class VoiceCall {
24
27
  this.calls = 0;
25
28
  /** Its voice service is opening: an answer that comes meanwhile waits for it (`waiting`, '' for none). */
26
29
  this.opening = false;
30
+ /** The answer begun on what the user said so far (CallPartner.draft). */
31
+ this.drafts = new CallDrafts();
27
32
  /** What waits to be said that the user did not ask for (a dialog, a task that ended), in order. */
28
33
  this.announcements = [];
34
+ /** For the face of the call (CallSounds): Ta's voice, whichever the call has (it opens after the call shows). */
35
+ this.sounds = new CallSounds(() => this.voice);
36
+ this.level = this.sounds.level;
29
37
  this.voice = device;
38
+ const call = this;
39
+ this.partners = new CallPartnering({
40
+ get calls() {
41
+ return call.calls;
42
+ },
43
+ get state() {
44
+ return call.state;
45
+ },
46
+ set: change => this.set(change),
47
+ turnEnded: reply => this.turnEnded(reply),
48
+ unsent: () => this.unsent(),
49
+ announce: text => this.announce(text),
50
+ }, options);
51
+ this.conversing = new CallConversing({
52
+ get state() {
53
+ return call.state;
54
+ },
55
+ set: change => this.set(change),
56
+ hangUp: () => this.hangUp(),
57
+ end: reason => this.end(reason),
58
+ lost: () => this.revoice(),
59
+ }, options.silentMs);
30
60
  this.turnEnd = new CallTurnEnd(options, () => this.quiet(), text => this.suspect(text));
31
61
  }
32
62
  subscribe(listener) {
@@ -36,19 +66,21 @@ export class VoiceCall {
36
66
  /**
37
67
  * Begins the call: Ta listens. With what the user said as they called (let go over 通话 of a talk), already being
38
68
  * sent by the box, Ta waits for its turn and reads the answer instead; should the sending fail, it listens.
39
- * `direct`: the conversation's voice kept on (let go over 持续说), the conversation answering, no partner.
40
- */
41
- start(said, { direct = false } = {}) {
42
- if (this.state.active) {
69
+ * `direct`: the conversation's voice kept on (let go over 持续说), no partner; `video`: a video call (CallState.video). */
70
+ start(said, { direct = false, video = false } = {}) {
71
+ if (this.state.active)
43
72
  return;
44
- }
45
73
  this.device.hush();
46
74
  this.silent = 0;
47
75
  this.spoke = Date.now();
48
76
  const call = ++this.calls;
49
77
  const opening = this.open(direct);
50
78
  // Said as they called: the turn is at work already, its answer is read once the voice is there.
51
- this.set(said ? { active: true, phase: 'thinking', heard: said.text, said: said.text } : { active: true, phase: opening ? 'connecting' : 'listening' });
79
+ this.set({
80
+ ...(said ? { active: true, phase: 'thinking', heard: said.text, said: said.text } : { active: true, phase: opening ? 'connecting' : 'listening' }),
81
+ ...(video ? { video } : {}),
82
+ since: Date.now(),
83
+ });
52
84
  said === null || said === void 0 ? void 0 : said.sent.catch(() => this.state.active && this.state.phase === 'thinking' && this.unsent());
53
85
  if (!opening) {
54
86
  if (!said) {
@@ -58,23 +90,19 @@ export class VoiceCall {
58
90
  }
59
91
  this.opening = true;
60
92
  opening.then(([voice, partner]) => {
61
- var _a, _b;
93
+ var _a;
62
94
  if (!this.state.active || call !== this.calls) {
63
95
  (_a = voice === null || voice === void 0 ? void 0 : voice.stop) === null || _a === void 0 ? void 0 : _a.call(voice);
64
96
  partner === null || partner === void 0 ? void 0 : partner.close();
65
97
  return;
66
98
  }
67
99
  this.opening = false;
68
- this.partner = partner;
69
- // What the partner says by itself is said as news is: in a silence, and cut into as any answer.
70
- (_b = partner === null || partner === void 0 ? void 0 : partner.news) === null || _b === void 0 ? void 0 : _b.call(partner, text => call === this.calls && this.announce(text));
71
- if (partner) {
72
- this.set({ partnered: true });
73
- }
74
- if (partner && said && this.state.phase === 'thinking') {
75
- // Said as they called, to the conversation: the partner answers it, not the turn.
100
+ this.partners.adopt(partner);
101
+ // Said as they called, to the conversation: the partner answers it, not the turn; a voice that thinks
102
+ // begins afresh.
103
+ if (partner && said && this.state.phase === 'thinking' && !(voice === null || voice === void 0 ? void 0 : voice.thinks)) {
76
104
  this.waiting = undefined;
77
- this.ask(said.text, true);
105
+ this.partners.ask(said.text, true);
78
106
  }
79
107
  if (voice) {
80
108
  this.takeVoice(voice);
@@ -86,15 +114,24 @@ export class VoiceCall {
86
114
  }
87
115
  });
88
116
  }
89
- /** The voice of a service is the call's now: it hears the user cut in. */
117
+ /** The voice of a service is the call's now: it hears the user cut in, or answers by itself (thinks). */
90
118
  takeVoice(voice) {
91
- var _a;
92
119
  this.voice = voice;
93
- this.offSpeech = (_a = voice.onSpeech) === null || _a === void 0 ? void 0 : _a.call(voice, () => this.bargeIn());
120
+ this.offSpeech = this.sounds.follow(voice);
121
+ if (voice.thinks && voice.converse) {
122
+ const call = this.calls;
123
+ this.waiting = undefined;
124
+ voice.converse(this.conversing.talk(() => call === this.calls && this.state.active));
125
+ return;
126
+ }
127
+ this.partners.unvoice();
128
+ this.offSpeech = this.sounds.heard(voice, () => this.bargeIn());
94
129
  this.set({ bargeIn: !!voice.onSpeech && voice.cutsIn !== false });
95
130
  }
96
131
  /** Its voice is there: the answer that came meanwhile is read, a turn at work is waited for, else Ta listens. */
97
132
  voiced() {
133
+ if (this.voice.thinks)
134
+ return;
98
135
  const waiting = this.waiting;
99
136
  this.waiting = undefined;
100
137
  if (waiting !== undefined) {
@@ -114,23 +151,44 @@ export class VoiceCall {
114
151
  * again as the connection comes back (VoiceReopen); a service no longer chosen gives the voice of the device.
115
152
  */
116
153
  revoice() {
117
- var _a, _b, _c;
154
+ var _a, _b, _c, _d;
118
155
  const call = this.calls;
119
- (_a = this.offSpeech) === null || _a === void 0 ? void 0 : _a.call(this);
156
+ // A voice that thought had the brain of the partner: both open again.
157
+ const thought = !!((_a = this.partners.partner) === null || _a === void 0 ? void 0 : _a.brain);
158
+ this.conversing.stop();
159
+ (_b = this.offSpeech) === null || _b === void 0 ? void 0 : _b.call(this);
120
160
  this.offSpeech = undefined;
121
- (_c = (_b = this.voice).stop) === null || _c === void 0 ? void 0 : _c.call(_b);
161
+ (_d = (_c = this.voice).stop) === null || _d === void 0 ? void 0 : _d.call(_c);
122
162
  this.voice = this.device;
163
+ if (thought) {
164
+ this.partners.close();
165
+ }
123
166
  this.opening = true;
124
167
  this.set({ phase: 'connecting', heard: '', bargeIn: false });
125
- const open = this.options.openVoice;
126
- this.reopening = new VoiceReopen(() => open === null || open === void 0 ? void 0 : open());
168
+ let partner;
169
+ this.reopening = new VoiceReopen(async () => {
170
+ var _a, _b, _c, _d, _e, _f, _g;
171
+ var _h;
172
+ if (!thought) {
173
+ return (_b = (_a = this.options).openVoice) === null || _b === void 0 ? void 0 : _b.call(_a);
174
+ }
175
+ partner === null || partner === void 0 ? void 0 : partner.close();
176
+ const opening = (_h = (_e = (_d = (_c = this.options).openPartner) === null || _d === void 0 ? void 0 : _d.call(_c)) === null || _e === void 0 ? void 0 : _e.catch(() => undefined)) !== null && _h !== void 0 ? _h : Promise.resolve(undefined);
177
+ const voice = await ((_g = (_f = this.options).openVoice) === null || _g === void 0 ? void 0 : _g.call(_f, opening));
178
+ partner = await opening;
179
+ return voice;
180
+ });
127
181
  this.reopening.run().then(voice => {
128
182
  var _a;
129
183
  if (call !== this.calls || !this.state.active) {
130
184
  (_a = voice === null || voice === void 0 ? void 0 : voice.stop) === null || _a === void 0 ? void 0 : _a.call(voice);
185
+ partner === null || partner === void 0 ? void 0 : partner.close();
131
186
  return;
132
187
  }
133
188
  this.opening = false;
189
+ if (thought) {
190
+ this.partners.adopt(partner);
191
+ }
134
192
  if (voice) {
135
193
  this.takeVoice(voice);
136
194
  }
@@ -138,23 +196,22 @@ export class VoiceCall {
138
196
  }, (error) => call === this.calls && this.state.active && this.end('failed', error instanceof Error ? error.message : String(error)));
139
197
  }
140
198
  hangUp() {
141
- var _a, _b, _c, _d, _e;
142
- if (!this.state.active) {
199
+ var _a, _b, _c, _d;
200
+ if (!this.state.active)
143
201
  return;
144
- }
145
- this.dropDraft();
146
- (_a = this.partner) === null || _a === void 0 ? void 0 : _a.close();
147
- this.partner = undefined;
202
+ this.drafts.drop();
203
+ this.conversing.stop();
204
+ this.partners.close();
148
205
  this.calls++;
149
- (_b = this.reopening) === null || _b === void 0 ? void 0 : _b.cancel();
206
+ (_a = this.reopening) === null || _a === void 0 ? void 0 : _a.cancel();
150
207
  this.reopening = undefined;
151
208
  this.opening = false;
152
209
  this.waiting = undefined;
153
210
  this.stopListening();
154
211
  this.voice.hush();
155
- (_c = this.offSpeech) === null || _c === void 0 ? void 0 : _c.call(this);
212
+ (_b = this.offSpeech) === null || _b === void 0 ? void 0 : _b.call(this);
156
213
  this.offSpeech = undefined;
157
- (_e = (_d = this.voice).stop) === null || _e === void 0 ? void 0 : _e.call(_d);
214
+ (_d = (_c = this.voice).stop) === null || _d === void 0 ? void 0 : _d.call(_c);
158
215
  this.voice = this.device;
159
216
  this.pending = undefined;
160
217
  this.announcements = [];
@@ -167,9 +224,9 @@ export class VoiceCall {
167
224
  */
168
225
  announce(text) {
169
226
  const said = text.trim();
170
- if (!this.state.active || !said) {
227
+ // A voice that thinks is told the news of the work by Ta itself (TaVoiceEngine.tell).
228
+ if (!this.state.active || !said || this.voice.thinks)
171
229
  return;
172
- }
173
230
  this.announcements.push(said);
174
231
  if (!this.state.paused && !this.opening && this.state.phase === 'listening' && !this.state.heard.trim()) {
175
232
  this.listen();
@@ -186,11 +243,18 @@ export class VoiceCall {
186
243
  * and waits, rather than look as if it listened. What was being said is said again on resume.
187
244
  */
188
245
  pause() {
246
+ var _a, _b;
189
247
  if (!this.state.active || this.state.paused) {
190
248
  return;
191
249
  }
250
+ if (this.voice.thinks) {
251
+ (_b = (_a = this.voice).mute) === null || _b === void 0 ? void 0 : _b.call(_a, true);
252
+ this.voice.hush();
253
+ this.set({ paused: true, phase: 'listening', heard: '' });
254
+ return;
255
+ }
192
256
  this.stopListening();
193
- this.dropDraft();
257
+ this.drafts.drop();
194
258
  if (this.state.phase === 'speaking') {
195
259
  this.voice.hush();
196
260
  this.pending = this.speaking;
@@ -199,11 +263,17 @@ export class VoiceCall {
199
263
  }
200
264
  /** The page shows again: the answer that waits is read, a turn at work is waited for, else Ta listens. */
201
265
  resume() {
266
+ var _a, _b;
202
267
  if (!this.state.active || !this.state.paused) {
203
268
  return;
204
269
  }
205
270
  this.silent = 0;
206
271
  this.set({ paused: false });
272
+ if (this.voice.thinks) {
273
+ this.conversing.resumed();
274
+ (_b = (_a = this.voice).mute) === null || _b === void 0 ? void 0 : _b.call(_a, false);
275
+ return;
276
+ }
207
277
  const pending = this.pending;
208
278
  this.pending = undefined;
209
279
  if (pending) {
@@ -217,7 +287,12 @@ export class VoiceCall {
217
287
  interrupt() {
218
288
  if (this.state.active && this.state.phase === 'speaking') {
219
289
  this.voice.hush();
220
- this.listen(false);
290
+ if (this.voice.thinks) {
291
+ this.set({ phase: 'listening', heard: '' });
292
+ }
293
+ else {
294
+ this.listen(false);
295
+ }
221
296
  }
222
297
  }
223
298
  /**
@@ -227,7 +302,7 @@ export class VoiceCall {
227
302
  turn(working, reply) {
228
303
  var _a;
229
304
  // A partner answers in this call: the turns of the conversation are its work, not the call's.
230
- if (!this.state.active || this.state.phase !== 'thinking' || this.partner) {
305
+ if (!this.state.active || this.state.phase !== 'thinking' || this.partners.partner) {
231
306
  this.asked = undefined;
232
307
  return;
233
308
  }
@@ -269,7 +344,7 @@ export class VoiceCall {
269
344
  /** What was said is over: Ta listens again, or hangs up when the partner ended the call. */
270
345
  over() {
271
346
  var _a, _b;
272
- if ((_b = (_a = this.partner) === null || _a === void 0 ? void 0 : _a.ending) === null || _b === void 0 ? void 0 : _b.call(_a)) {
347
+ if ((_b = (_a = this.partners.partner) === null || _a === void 0 ? void 0 : _a.ending) === null || _b === void 0 ? void 0 : _b.call(_a)) {
273
348
  this.hangUp();
274
349
  }
275
350
  else {
@@ -292,8 +367,12 @@ export class VoiceCall {
292
367
  * alone a listen ended on, which what is heard now follows, gone or sent once it waited FILLER_MS for words.
293
368
  */
294
369
  listen(announce = true, held) {
370
+ if (this.voice.thinks) {
371
+ // It listens by itself.
372
+ return;
373
+ }
295
374
  this.stopListening();
296
- this.dropDraft();
375
+ this.drafts.drop();
297
376
  if (this.state.paused) {
298
377
  return;
299
378
  }
@@ -314,9 +393,7 @@ export class VoiceCall {
314
393
  this.set(text.trim() ? { heard: text, said: undefined, reading: undefined } : { heard: text });
315
394
  if (more && text.trim()) {
316
395
  // They say more than the answer begun was to: it goes.
317
- if (this.drafted && this.drafted.text !== text.trim()) {
318
- this.dropDraft();
319
- }
396
+ this.drafts.heard(text);
320
397
  this.turnEnd.heard(text);
321
398
  }
322
399
  }
@@ -344,6 +421,9 @@ export class VoiceCall {
344
421
  }
345
422
  /** The user says they are done (the mark of the bar tapped): what was heard goes now as it is, sounds alone too. */
346
423
  endTurn() {
424
+ if (this.voice.thinks) {
425
+ return;
426
+ }
347
427
  const said = this.listened();
348
428
  if (said) {
349
429
  this.stopListening();
@@ -406,15 +486,14 @@ export class VoiceCall {
406
486
  this.silent = 0;
407
487
  this.spoke = Date.now();
408
488
  this.set({ phase: 'thinking', heard: said, said, reading: undefined });
409
- const drafted = this.drafted;
410
- this.drafted = undefined;
411
- if (this.partner && (drafted === null || drafted === void 0 ? void 0 : drafted.text) === said) {
412
- this.kept(drafted.draft, said);
489
+ const draft = this.drafts.take(said);
490
+ if (this.partners.partner && draft) {
491
+ this.partners.kept(draft, said);
413
492
  return;
414
493
  }
415
- drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
416
- if (this.partner) {
417
- this.ask(said);
494
+ draft === null || draft === void 0 ? void 0 : draft.drop();
495
+ if (this.partners.partner) {
496
+ this.partners.ask(said);
418
497
  }
419
498
  else {
420
499
  this.options.send(said).catch(() => this.state.active && this.unsent());
@@ -425,79 +504,18 @@ export class VoiceCall {
425
504
  * should they be done with these words (take), dropped as they say more (docs/design/ta-call.md 10).
426
505
  */
427
506
  suspect(text) {
428
- var _a;
429
507
  const said = text.trim();
430
- const partner = this.partner;
431
- if (!(partner === null || partner === void 0 ? void 0 : partner.draft) || this.draftless === partner || this.listened() !== said || ((_a = this.drafted) === null || _a === void 0 ? void 0 : _a.text) === said) {
432
- return;
508
+ if (this.listened() === said) {
509
+ this.drafts.begin(this.partners.partner, said);
433
510
  }
434
- this.dropDraft();
435
- const draft = partner.draft(said);
436
- draft.reply.catch(() => {
437
- this.draftless = partner;
438
- });
439
- this.drafted = { text: said, draft };
440
- }
441
- /** The user was done with the words of the draft: its answer is the reply; failing, the partner is asked as usual. */
442
- kept(draft, said) {
443
- const call = this.calls;
444
- const partner = this.partner;
445
- draft.keep();
446
- draft.reply.then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.partner === partner && this.ask(said));
447
- }
448
- dropDraft() {
449
- const drafted = this.drafted;
450
- this.drafted = undefined;
451
- drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
452
511
  }
453
512
  /** The voice and the partner the call opens as it starts; undefined when it opens neither. A partner that fails is none. */
454
513
  open(direct) {
455
514
  var _a, _b, _c, _d, _e;
456
- const voice = (_b = (_a = this.options).openVoice) === null || _b === void 0 ? void 0 : _b.call(_a);
457
- const partner = direct ? undefined : (_e = (_d = (_c = this.options).openPartner) === null || _d === void 0 ? void 0 : _d.call(_c)) === null || _e === void 0 ? void 0 : _e.catch(() => undefined);
515
+ const partner = direct ? undefined : (_c = (_b = (_a = this.options).openPartner) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.catch(() => undefined);
516
+ const voice = (_e = (_d = this.options).openVoice) === null || _e === void 0 ? void 0 : _e.call(_d, partner);
458
517
  return voice || partner ? Promise.all([voice, partner]) : undefined;
459
518
  }
460
- /** The partner answers what the user said; its reply is read as a turn's is. */
461
- ask(text, sent) {
462
- const call = this.calls;
463
- const partner = this.partner;
464
- partner === null || partner === void 0 ? void 0 : partner.say(text, sent ? { sent } : undefined).then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.reopen(partner, text, sent));
465
- }
466
- /**
467
- * The partner did not answer (the Ta service restarted, its side of the call is gone): it opens again once and
468
- * answers what was said; failing that, the conversation answers from then on. The call goes on either way.
469
- */
470
- reopen(failed, text, sent) {
471
- var _a, _b, _c;
472
- var _d;
473
- const call = this.calls;
474
- if (this.partner !== failed) {
475
- return;
476
- }
477
- failed.close();
478
- this.partner = undefined;
479
- const again = (_d = (_c = (_b = (_a = this.options).openPartner) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.catch(() => undefined)) !== null && _d !== void 0 ? _d : Promise.resolve(undefined);
480
- void again.then(partner => {
481
- var _a;
482
- if (call !== this.calls || !this.state.active) {
483
- partner === null || partner === void 0 ? void 0 : partner.close();
484
- return;
485
- }
486
- if (!partner) {
487
- this.set({ partnered: false });
488
- if (sent) {
489
- this.unsent();
490
- }
491
- else {
492
- this.options.send(text).catch(() => this.state.active && this.unsent());
493
- }
494
- return;
495
- }
496
- this.partner = partner;
497
- (_a = partner.news) === null || _a === void 0 ? void 0 : _a.call(partner, news => call === this.calls && this.announce(news));
498
- partner.say(text, sent ? { sent } : undefined).then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.unsent());
499
- });
500
- }
501
519
  /** What the user said did not go: not in the captions as if it had, and Ta listens again. */
502
520
  unsent() {
503
521
  this.set({ said: undefined });
@@ -518,9 +536,8 @@ export class VoiceCall {
518
536
  }
519
537
  set(change) {
520
538
  this.state = { ...this.state, ...change };
521
- for (const listener of this.listeners) {
539
+ for (const listener of this.listeners)
522
540
  listener();
523
- }
524
541
  }
525
542
  }
526
543
  //# sourceMappingURL=voice-call.js.map
@@ -0,0 +1,83 @@
1
+ import { SpokenTimeline } from './spoken-timeline.js';
2
+ import type { CallReading } from './voice-call-protocol.js';
3
+ /**
4
+ * What a voice service reads now, on the clock of its sound as it plays (CallReading): it begins where its first sound
5
+ * plays, held as long as the face of a video call asks (RealtimeVoice.hold), and its captions show each sentence as it
6
+ * is heard, by the same timeline the face asks.
7
+ */
8
+ export declare class VoiceReading implements CallReading {
9
+ readonly say: number;
10
+ pieces: readonly string[];
11
+ protected readonly context: AudioContext;
12
+ protected readonly holdS: number;
13
+ /** Whether it is still what plays: once not, its captions stop. */
14
+ protected readonly live: () => boolean;
15
+ protected readonly onPiece?: ((pieces: string[], index: number) => void) | undefined;
16
+ /** When its first sound plays, on the clock of the audio context. */
17
+ startAt?: number;
18
+ timeline: SpokenTimeline;
19
+ /** Its sound as it was put to play: from `at` on the clock of the audio context, `from` seconds into it, for `seconds`. */
20
+ protected readonly played: {
21
+ at: number;
22
+ from: number;
23
+ seconds: number;
24
+ }[];
25
+ protected shown: number;
26
+ /** The words the captions were last told: told again as more of them came. */
27
+ protected lastPieces?: readonly string[];
28
+ protected timer?: ReturnType<typeof setInterval>;
29
+ constructor(say: number, pieces: readonly string[], context: AudioContext, holdS: number,
30
+ /** Whether it is still what plays: once not, its captions stop. */
31
+ live: () => boolean, onPiece?: ((pieces: string[], index: number) => void) | undefined);
32
+ /**
33
+ * How far into its sound it plays: where the sound playing now is in it, or where the last played ended while what
34
+ * comes next is late (the sound stopped short), so that the words, the clip and the mouth wait with the voice.
35
+ */
36
+ now(): number;
37
+ pieceAt(seconds: number): number;
38
+ /** More of its sound came: when the first of it plays, and how much of it there is. */
39
+ heard(at: number, seconds: number): void;
40
+ /** Its words, more of them as they came (a voice that thinks says them as it goes): its sentences timed again. */
41
+ words(pieces: readonly string[]): void;
42
+ /** All of its sound came: the timeline knows how long it is. */
43
+ said(): void;
44
+ protected caption(): void;
45
+ }
46
+ /** The sound of what a voice reads, for the face of a video call (CallVoice.onSound), and the hold it asks (hold). */
47
+ export declare class VoiceSoundTap {
48
+ /** How long each reading waits before it plays, in seconds. */
49
+ holdS: number;
50
+ protected readonly listeners: Set<(say: number, pcm: Uint8Array | undefined, rate: number) => void>;
51
+ readonly on: (listener: (say: number, pcm: Uint8Array | undefined, rate: number) => void) => (() => void);
52
+ /** The voice it follows (follow), told the hold too. */
53
+ protected voice?: {
54
+ hold?(ms: number): void;
55
+ };
56
+ readonly hold: (ms: number) => void;
57
+ /** Of a call: the sound of its voice is told here, and the hold asked here goes to it; stops with what it returns. */
58
+ follow(voice: {
59
+ hold?(ms: number): void;
60
+ onSound?: VoiceSoundTap['on'];
61
+ }): () => void;
62
+ tell(say: number, pcm: Uint8Array | undefined, rate?: number): void;
63
+ }
64
+ /**
65
+ * What the face of a call reads of its voice, whichever voice the call has now: how loud it plays (RMS, 0 to 1;
66
+ * undefined for the device's, which cannot tell), what it reads on the clock of its sound, and that sound.
67
+ */
68
+ export declare class CallSounds extends VoiceSoundTap {
69
+ protected readonly voiceNow: () => {
70
+ level?(): number;
71
+ nowReading?(): CallReading | undefined;
72
+ };
73
+ constructor(voiceNow: () => {
74
+ level?(): number;
75
+ nowReading?(): CallReading | undefined;
76
+ });
77
+ readonly level: () => number | undefined;
78
+ readonly nowReading: () => CallReading | undefined;
79
+ /** Hears the user cut in while the voice of the call reads, and its sound (follow): stops both with what it returns. */
80
+ heard(voice: Parameters<VoiceSoundTap['follow']>[0] & {
81
+ onSpeech?(listener: () => void): () => void;
82
+ }, cut: () => void): () => void;
83
+ }