@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
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VoiceCall = void 0;
4
4
  const turn_end_1 = require("../util/turn-end");
5
5
  const voice_1 = require("../util/voice");
6
+ const call_conversing_1 = require("./call-conversing");
7
+ const call_partnering_1 = require("./call-partnering");
6
8
  const call_turn_end_1 = require("./call-turn-end");
9
+ const voice_reading_1 = require("./voice-reading");
7
10
  const voice_reopen_1 = require("./voice-reopen");
8
11
  const IDLE = { active: false, phase: 'listening', heard: '' };
9
12
  /**
@@ -27,9 +30,36 @@ class VoiceCall {
27
30
  this.calls = 0;
28
31
  /** Its voice service is opening: an answer that comes meanwhile waits for it (`waiting`, '' for none). */
29
32
  this.opening = false;
33
+ /** The answer begun on what the user said so far (CallPartner.draft). */
34
+ this.drafts = new call_conversing_1.CallDrafts();
30
35
  /** What waits to be said that the user did not ask for (a dialog, a task that ended), in order. */
31
36
  this.announcements = [];
37
+ /** For the face of the call (CallSounds): Ta's voice, whichever the call has (it opens after the call shows). */
38
+ this.sounds = new voice_reading_1.CallSounds(() => this.voice);
39
+ this.level = this.sounds.level;
32
40
  this.voice = device;
41
+ const call = this;
42
+ this.partners = new call_partnering_1.CallPartnering({
43
+ get calls() {
44
+ return call.calls;
45
+ },
46
+ get state() {
47
+ return call.state;
48
+ },
49
+ set: change => this.set(change),
50
+ turnEnded: reply => this.turnEnded(reply),
51
+ unsent: () => this.unsent(),
52
+ announce: text => this.announce(text),
53
+ }, options);
54
+ this.conversing = new call_conversing_1.CallConversing({
55
+ get state() {
56
+ return call.state;
57
+ },
58
+ set: change => this.set(change),
59
+ hangUp: () => this.hangUp(),
60
+ end: reason => this.end(reason),
61
+ lost: () => this.revoice(),
62
+ }, options.silentMs);
33
63
  this.turnEnd = new call_turn_end_1.CallTurnEnd(options, () => this.quiet(), text => this.suspect(text));
34
64
  }
35
65
  subscribe(listener) {
@@ -39,19 +69,21 @@ class VoiceCall {
39
69
  /**
40
70
  * Begins the call: Ta listens. With what the user said as they called (let go over 通话 of a talk), already being
41
71
  * sent by the box, Ta waits for its turn and reads the answer instead; should the sending fail, it listens.
42
- * `direct`: the conversation's voice kept on (let go over 持续说), the conversation answering, no partner.
43
- */
44
- start(said, { direct = false } = {}) {
45
- if (this.state.active) {
72
+ * `direct`: the conversation's voice kept on (let go over 持续说), no partner; `video`: a video call (CallState.video). */
73
+ start(said, { direct = false, video = false } = {}) {
74
+ if (this.state.active)
46
75
  return;
47
- }
48
76
  this.device.hush();
49
77
  this.silent = 0;
50
78
  this.spoke = Date.now();
51
79
  const call = ++this.calls;
52
80
  const opening = this.open(direct);
53
81
  // Said as they called: the turn is at work already, its answer is read once the voice is there.
54
- this.set(said ? { active: true, phase: 'thinking', heard: said.text, said: said.text } : { active: true, phase: opening ? 'connecting' : 'listening' });
82
+ this.set({
83
+ ...(said ? { active: true, phase: 'thinking', heard: said.text, said: said.text } : { active: true, phase: opening ? 'connecting' : 'listening' }),
84
+ ...(video ? { video } : {}),
85
+ since: Date.now(),
86
+ });
55
87
  said === null || said === void 0 ? void 0 : said.sent.catch(() => this.state.active && this.state.phase === 'thinking' && this.unsent());
56
88
  if (!opening) {
57
89
  if (!said) {
@@ -61,23 +93,19 @@ class VoiceCall {
61
93
  }
62
94
  this.opening = true;
63
95
  opening.then(([voice, partner]) => {
64
- var _a, _b;
96
+ var _a;
65
97
  if (!this.state.active || call !== this.calls) {
66
98
  (_a = voice === null || voice === void 0 ? void 0 : voice.stop) === null || _a === void 0 ? void 0 : _a.call(voice);
67
99
  partner === null || partner === void 0 ? void 0 : partner.close();
68
100
  return;
69
101
  }
70
102
  this.opening = false;
71
- this.partner = partner;
72
- // What the partner says by itself is said as news is: in a silence, and cut into as any answer.
73
- (_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));
74
- if (partner) {
75
- this.set({ partnered: true });
76
- }
77
- if (partner && said && this.state.phase === 'thinking') {
78
- // Said as they called, to the conversation: the partner answers it, not the turn.
103
+ this.partners.adopt(partner);
104
+ // Said as they called, to the conversation: the partner answers it, not the turn; a voice that thinks
105
+ // begins afresh.
106
+ if (partner && said && this.state.phase === 'thinking' && !(voice === null || voice === void 0 ? void 0 : voice.thinks)) {
79
107
  this.waiting = undefined;
80
- this.ask(said.text, true);
108
+ this.partners.ask(said.text, true);
81
109
  }
82
110
  if (voice) {
83
111
  this.takeVoice(voice);
@@ -89,15 +117,24 @@ class VoiceCall {
89
117
  }
90
118
  });
91
119
  }
92
- /** The voice of a service is the call's now: it hears the user cut in. */
120
+ /** The voice of a service is the call's now: it hears the user cut in, or answers by itself (thinks). */
93
121
  takeVoice(voice) {
94
- var _a;
95
122
  this.voice = voice;
96
- this.offSpeech = (_a = voice.onSpeech) === null || _a === void 0 ? void 0 : _a.call(voice, () => this.bargeIn());
123
+ this.offSpeech = this.sounds.follow(voice);
124
+ if (voice.thinks && voice.converse) {
125
+ const call = this.calls;
126
+ this.waiting = undefined;
127
+ voice.converse(this.conversing.talk(() => call === this.calls && this.state.active));
128
+ return;
129
+ }
130
+ this.partners.unvoice();
131
+ this.offSpeech = this.sounds.heard(voice, () => this.bargeIn());
97
132
  this.set({ bargeIn: !!voice.onSpeech && voice.cutsIn !== false });
98
133
  }
99
134
  /** Its voice is there: the answer that came meanwhile is read, a turn at work is waited for, else Ta listens. */
100
135
  voiced() {
136
+ if (this.voice.thinks)
137
+ return;
101
138
  const waiting = this.waiting;
102
139
  this.waiting = undefined;
103
140
  if (waiting !== undefined) {
@@ -117,23 +154,44 @@ class VoiceCall {
117
154
  * again as the connection comes back (VoiceReopen); a service no longer chosen gives the voice of the device.
118
155
  */
119
156
  revoice() {
120
- var _a, _b, _c;
157
+ var _a, _b, _c, _d;
121
158
  const call = this.calls;
122
- (_a = this.offSpeech) === null || _a === void 0 ? void 0 : _a.call(this);
159
+ // A voice that thought had the brain of the partner: both open again.
160
+ const thought = !!((_a = this.partners.partner) === null || _a === void 0 ? void 0 : _a.brain);
161
+ this.conversing.stop();
162
+ (_b = this.offSpeech) === null || _b === void 0 ? void 0 : _b.call(this);
123
163
  this.offSpeech = undefined;
124
- (_c = (_b = this.voice).stop) === null || _c === void 0 ? void 0 : _c.call(_b);
164
+ (_d = (_c = this.voice).stop) === null || _d === void 0 ? void 0 : _d.call(_c);
125
165
  this.voice = this.device;
166
+ if (thought) {
167
+ this.partners.close();
168
+ }
126
169
  this.opening = true;
127
170
  this.set({ phase: 'connecting', heard: '', bargeIn: false });
128
- const open = this.options.openVoice;
129
- this.reopening = new voice_reopen_1.VoiceReopen(() => open === null || open === void 0 ? void 0 : open());
171
+ let partner;
172
+ this.reopening = new voice_reopen_1.VoiceReopen(async () => {
173
+ var _a, _b, _c, _d, _e, _f, _g;
174
+ var _h;
175
+ if (!thought) {
176
+ return (_b = (_a = this.options).openVoice) === null || _b === void 0 ? void 0 : _b.call(_a);
177
+ }
178
+ partner === null || partner === void 0 ? void 0 : partner.close();
179
+ 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);
180
+ const voice = await ((_g = (_f = this.options).openVoice) === null || _g === void 0 ? void 0 : _g.call(_f, opening));
181
+ partner = await opening;
182
+ return voice;
183
+ });
130
184
  this.reopening.run().then(voice => {
131
185
  var _a;
132
186
  if (call !== this.calls || !this.state.active) {
133
187
  (_a = voice === null || voice === void 0 ? void 0 : voice.stop) === null || _a === void 0 ? void 0 : _a.call(voice);
188
+ partner === null || partner === void 0 ? void 0 : partner.close();
134
189
  return;
135
190
  }
136
191
  this.opening = false;
192
+ if (thought) {
193
+ this.partners.adopt(partner);
194
+ }
137
195
  if (voice) {
138
196
  this.takeVoice(voice);
139
197
  }
@@ -141,23 +199,22 @@ class VoiceCall {
141
199
  }, (error) => call === this.calls && this.state.active && this.end('failed', error instanceof Error ? error.message : String(error)));
142
200
  }
143
201
  hangUp() {
144
- var _a, _b, _c, _d, _e;
145
- if (!this.state.active) {
202
+ var _a, _b, _c, _d;
203
+ if (!this.state.active)
146
204
  return;
147
- }
148
- this.dropDraft();
149
- (_a = this.partner) === null || _a === void 0 ? void 0 : _a.close();
150
- this.partner = undefined;
205
+ this.drafts.drop();
206
+ this.conversing.stop();
207
+ this.partners.close();
151
208
  this.calls++;
152
- (_b = this.reopening) === null || _b === void 0 ? void 0 : _b.cancel();
209
+ (_a = this.reopening) === null || _a === void 0 ? void 0 : _a.cancel();
153
210
  this.reopening = undefined;
154
211
  this.opening = false;
155
212
  this.waiting = undefined;
156
213
  this.stopListening();
157
214
  this.voice.hush();
158
- (_c = this.offSpeech) === null || _c === void 0 ? void 0 : _c.call(this);
215
+ (_b = this.offSpeech) === null || _b === void 0 ? void 0 : _b.call(this);
159
216
  this.offSpeech = undefined;
160
- (_e = (_d = this.voice).stop) === null || _e === void 0 ? void 0 : _e.call(_d);
217
+ (_d = (_c = this.voice).stop) === null || _d === void 0 ? void 0 : _d.call(_c);
161
218
  this.voice = this.device;
162
219
  this.pending = undefined;
163
220
  this.announcements = [];
@@ -170,9 +227,9 @@ class VoiceCall {
170
227
  */
171
228
  announce(text) {
172
229
  const said = text.trim();
173
- if (!this.state.active || !said) {
230
+ // A voice that thinks is told the news of the work by Ta itself (TaVoiceEngine.tell).
231
+ if (!this.state.active || !said || this.voice.thinks)
174
232
  return;
175
- }
176
233
  this.announcements.push(said);
177
234
  if (!this.state.paused && !this.opening && this.state.phase === 'listening' && !this.state.heard.trim()) {
178
235
  this.listen();
@@ -189,11 +246,18 @@ class VoiceCall {
189
246
  * and waits, rather than look as if it listened. What was being said is said again on resume.
190
247
  */
191
248
  pause() {
249
+ var _a, _b;
192
250
  if (!this.state.active || this.state.paused) {
193
251
  return;
194
252
  }
253
+ if (this.voice.thinks) {
254
+ (_b = (_a = this.voice).mute) === null || _b === void 0 ? void 0 : _b.call(_a, true);
255
+ this.voice.hush();
256
+ this.set({ paused: true, phase: 'listening', heard: '' });
257
+ return;
258
+ }
195
259
  this.stopListening();
196
- this.dropDraft();
260
+ this.drafts.drop();
197
261
  if (this.state.phase === 'speaking') {
198
262
  this.voice.hush();
199
263
  this.pending = this.speaking;
@@ -202,11 +266,17 @@ class VoiceCall {
202
266
  }
203
267
  /** The page shows again: the answer that waits is read, a turn at work is waited for, else Ta listens. */
204
268
  resume() {
269
+ var _a, _b;
205
270
  if (!this.state.active || !this.state.paused) {
206
271
  return;
207
272
  }
208
273
  this.silent = 0;
209
274
  this.set({ paused: false });
275
+ if (this.voice.thinks) {
276
+ this.conversing.resumed();
277
+ (_b = (_a = this.voice).mute) === null || _b === void 0 ? void 0 : _b.call(_a, false);
278
+ return;
279
+ }
210
280
  const pending = this.pending;
211
281
  this.pending = undefined;
212
282
  if (pending) {
@@ -220,7 +290,12 @@ class VoiceCall {
220
290
  interrupt() {
221
291
  if (this.state.active && this.state.phase === 'speaking') {
222
292
  this.voice.hush();
223
- this.listen(false);
293
+ if (this.voice.thinks) {
294
+ this.set({ phase: 'listening', heard: '' });
295
+ }
296
+ else {
297
+ this.listen(false);
298
+ }
224
299
  }
225
300
  }
226
301
  /**
@@ -230,7 +305,7 @@ class VoiceCall {
230
305
  turn(working, reply) {
231
306
  var _a;
232
307
  // A partner answers in this call: the turns of the conversation are its work, not the call's.
233
- if (!this.state.active || this.state.phase !== 'thinking' || this.partner) {
308
+ if (!this.state.active || this.state.phase !== 'thinking' || this.partners.partner) {
234
309
  this.asked = undefined;
235
310
  return;
236
311
  }
@@ -272,7 +347,7 @@ class VoiceCall {
272
347
  /** What was said is over: Ta listens again, or hangs up when the partner ended the call. */
273
348
  over() {
274
349
  var _a, _b;
275
- if ((_b = (_a = this.partner) === null || _a === void 0 ? void 0 : _a.ending) === null || _b === void 0 ? void 0 : _b.call(_a)) {
350
+ if ((_b = (_a = this.partners.partner) === null || _a === void 0 ? void 0 : _a.ending) === null || _b === void 0 ? void 0 : _b.call(_a)) {
276
351
  this.hangUp();
277
352
  }
278
353
  else {
@@ -295,8 +370,12 @@ class VoiceCall {
295
370
  * alone a listen ended on, which what is heard now follows, gone or sent once it waited FILLER_MS for words.
296
371
  */
297
372
  listen(announce = true, held) {
373
+ if (this.voice.thinks) {
374
+ // It listens by itself.
375
+ return;
376
+ }
298
377
  this.stopListening();
299
- this.dropDraft();
378
+ this.drafts.drop();
300
379
  if (this.state.paused) {
301
380
  return;
302
381
  }
@@ -317,9 +396,7 @@ class VoiceCall {
317
396
  this.set(text.trim() ? { heard: text, said: undefined, reading: undefined } : { heard: text });
318
397
  if (more && text.trim()) {
319
398
  // They say more than the answer begun was to: it goes.
320
- if (this.drafted && this.drafted.text !== text.trim()) {
321
- this.dropDraft();
322
- }
399
+ this.drafts.heard(text);
323
400
  this.turnEnd.heard(text);
324
401
  }
325
402
  }
@@ -347,6 +424,9 @@ class VoiceCall {
347
424
  }
348
425
  /** The user says they are done (the mark of the bar tapped): what was heard goes now as it is, sounds alone too. */
349
426
  endTurn() {
427
+ if (this.voice.thinks) {
428
+ return;
429
+ }
350
430
  const said = this.listened();
351
431
  if (said) {
352
432
  this.stopListening();
@@ -409,15 +489,14 @@ class VoiceCall {
409
489
  this.silent = 0;
410
490
  this.spoke = Date.now();
411
491
  this.set({ phase: 'thinking', heard: said, said, reading: undefined });
412
- const drafted = this.drafted;
413
- this.drafted = undefined;
414
- if (this.partner && (drafted === null || drafted === void 0 ? void 0 : drafted.text) === said) {
415
- this.kept(drafted.draft, said);
492
+ const draft = this.drafts.take(said);
493
+ if (this.partners.partner && draft) {
494
+ this.partners.kept(draft, said);
416
495
  return;
417
496
  }
418
- drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
419
- if (this.partner) {
420
- this.ask(said);
497
+ draft === null || draft === void 0 ? void 0 : draft.drop();
498
+ if (this.partners.partner) {
499
+ this.partners.ask(said);
421
500
  }
422
501
  else {
423
502
  this.options.send(said).catch(() => this.state.active && this.unsent());
@@ -428,79 +507,18 @@ class VoiceCall {
428
507
  * should they be done with these words (take), dropped as they say more (docs/design/ta-call.md 10).
429
508
  */
430
509
  suspect(text) {
431
- var _a;
432
510
  const said = text.trim();
433
- const partner = this.partner;
434
- 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) {
435
- return;
511
+ if (this.listened() === said) {
512
+ this.drafts.begin(this.partners.partner, said);
436
513
  }
437
- this.dropDraft();
438
- const draft = partner.draft(said);
439
- draft.reply.catch(() => {
440
- this.draftless = partner;
441
- });
442
- this.drafted = { text: said, draft };
443
- }
444
- /** The user was done with the words of the draft: its answer is the reply; failing, the partner is asked as usual. */
445
- kept(draft, said) {
446
- const call = this.calls;
447
- const partner = this.partner;
448
- draft.keep();
449
- draft.reply.then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.partner === partner && this.ask(said));
450
- }
451
- dropDraft() {
452
- const drafted = this.drafted;
453
- this.drafted = undefined;
454
- drafted === null || drafted === void 0 ? void 0 : drafted.draft.drop();
455
514
  }
456
515
  /** The voice and the partner the call opens as it starts; undefined when it opens neither. A partner that fails is none. */
457
516
  open(direct) {
458
517
  var _a, _b, _c, _d, _e;
459
- const voice = (_b = (_a = this.options).openVoice) === null || _b === void 0 ? void 0 : _b.call(_a);
460
- 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);
518
+ 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);
519
+ const voice = (_e = (_d = this.options).openVoice) === null || _e === void 0 ? void 0 : _e.call(_d, partner);
461
520
  return voice || partner ? Promise.all([voice, partner]) : undefined;
462
521
  }
463
- /** The partner answers what the user said; its reply is read as a turn's is. */
464
- ask(text, sent) {
465
- const call = this.calls;
466
- const partner = this.partner;
467
- 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));
468
- }
469
- /**
470
- * The partner did not answer (the Ta service restarted, its side of the call is gone): it opens again once and
471
- * answers what was said; failing that, the conversation answers from then on. The call goes on either way.
472
- */
473
- reopen(failed, text, sent) {
474
- var _a, _b, _c;
475
- var _d;
476
- const call = this.calls;
477
- if (this.partner !== failed) {
478
- return;
479
- }
480
- failed.close();
481
- this.partner = undefined;
482
- 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);
483
- void again.then(partner => {
484
- var _a;
485
- if (call !== this.calls || !this.state.active) {
486
- partner === null || partner === void 0 ? void 0 : partner.close();
487
- return;
488
- }
489
- if (!partner) {
490
- this.set({ partnered: false });
491
- if (sent) {
492
- this.unsent();
493
- }
494
- else {
495
- this.options.send(text).catch(() => this.state.active && this.unsent());
496
- }
497
- return;
498
- }
499
- this.partner = partner;
500
- (_a = partner.news) === null || _a === void 0 ? void 0 : _a.call(partner, news => call === this.calls && this.announce(news));
501
- partner.say(text, sent ? { sent } : undefined).then(reply => call === this.calls && this.turnEnded(reply), () => call === this.calls && this.state.active && this.unsent());
502
- });
503
- }
504
522
  /** What the user said did not go: not in the captions as if it had, and Ta listens again. */
505
523
  unsent() {
506
524
  this.set({ said: undefined });
@@ -521,9 +539,8 @@ class VoiceCall {
521
539
  }
522
540
  set(change) {
523
541
  this.state = { ...this.state, ...change };
524
- for (const listener of this.listeners) {
542
+ for (const listener of this.listeners)
525
543
  listener();
526
- }
527
544
  }
528
545
  }
529
546
  exports.VoiceCall = VoiceCall;
@@ -0,0 +1,84 @@
1
+ import { SpokenTimeline } from './spoken-timeline';
2
+ import type { CallReading } from './voice-call-protocol';
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
+ }
84
+ //# sourceMappingURL=voice-reading.d.ts.map