@dxos/plugin-transcription 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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 (284) hide show
  1. package/dist/lib/browser/blueprints/index.mjs +31 -0
  2. package/dist/lib/browser/blueprints/index.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-3L623EVL.mjs +17 -0
  4. package/dist/lib/browser/chunk-3L623EVL.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  6. package/dist/lib/browser/chunk-KAEXRX3Y.mjs +35 -0
  7. package/dist/lib/browser/chunk-KAEXRX3Y.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-L4HW35L6.mjs +111 -0
  9. package/dist/lib/browser/chunk-L4HW35L6.mjs.map +7 -0
  10. package/dist/lib/browser/create-ULR5DPJZ.mjs +21 -0
  11. package/dist/lib/browser/create-ULR5DPJZ.mjs.map +7 -0
  12. package/dist/lib/browser/index.mjs +1085 -98
  13. package/dist/lib/browser/index.mjs.map +4 -4
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/open-SFMPLZVW.mjs +27 -0
  16. package/dist/lib/browser/open-SFMPLZVW.mjs.map +7 -0
  17. package/dist/lib/browser/operations/index.mjs +13 -0
  18. package/dist/lib/browser/operations/index.mjs.map +7 -0
  19. package/dist/lib/browser/summarize-I3POXUK3.mjs +79 -0
  20. package/dist/lib/browser/summarize-I3POXUK3.mjs.map +7 -0
  21. package/dist/lib/browser/translations.mjs +22 -0
  22. package/dist/lib/browser/translations.mjs.map +7 -0
  23. package/dist/lib/browser/types/index.mjs +4 -8
  24. package/dist/lib/node-esm/blueprints/index.mjs +32 -0
  25. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-7UIZWCD4.mjs +112 -0
  27. package/dist/lib/node-esm/chunk-7UIZWCD4.mjs.map +7 -0
  28. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  29. package/dist/lib/node-esm/chunk-KO3IOD2O.mjs +19 -0
  30. package/dist/lib/node-esm/chunk-KO3IOD2O.mjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-O533NBMK.mjs +37 -0
  32. package/dist/lib/node-esm/chunk-O533NBMK.mjs.map +7 -0
  33. package/dist/lib/node-esm/create-A5QHNWRF.mjs +22 -0
  34. package/dist/lib/node-esm/create-A5QHNWRF.mjs.map +7 -0
  35. package/dist/lib/node-esm/index.mjs +1085 -98
  36. package/dist/lib/node-esm/index.mjs.map +4 -4
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/open-OI24QNTO.mjs +28 -0
  39. package/dist/lib/node-esm/open-OI24QNTO.mjs.map +7 -0
  40. package/dist/lib/node-esm/operations/index.mjs +14 -0
  41. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  42. package/dist/lib/node-esm/summarize-F3LLJ45P.mjs +80 -0
  43. package/dist/lib/node-esm/summarize-F3LLJ45P.mjs.map +7 -0
  44. package/dist/lib/node-esm/translations.mjs +23 -0
  45. package/dist/lib/node-esm/translations.mjs.map +7 -0
  46. package/dist/lib/node-esm/types/index.mjs +4 -8
  47. package/dist/types/src/TranscriptionPlugin.d.ts +2 -1
  48. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  49. package/dist/types/src/blueprints/index.d.ts +2 -0
  50. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  51. package/dist/types/src/blueprints/transcription-blueprint.d.ts +4 -0
  52. package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -0
  53. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
  54. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/index.d.ts +6 -4
  56. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  58. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  59. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  60. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  61. package/dist/types/src/capabilities/transcriber.d.ts +4 -3
  62. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  63. package/dist/types/src/components/Transcription/Transcription.d.ts +18 -0
  64. package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
  65. package/dist/types/src/components/Transcription/Transcription.stories.d.ts +40 -0
  66. package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -0
  67. package/dist/types/src/components/Transcription/index.d.ts +2 -0
  68. package/dist/types/src/components/Transcription/index.d.ts.map +1 -0
  69. package/dist/types/src/components/Transcription/transcription-extension.d.ts +15 -0
  70. package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -0
  71. package/dist/types/src/components/index.d.ts +1 -3
  72. package/dist/types/src/components/index.d.ts.map +1 -1
  73. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts +6 -0
  74. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +1 -0
  75. package/dist/types/src/containers/TranscriptionContainer/index.d.ts +2 -0
  76. package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +1 -0
  77. package/dist/types/src/containers/index.d.ts +3 -0
  78. package/dist/types/src/containers/index.d.ts.map +1 -0
  79. package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
  80. package/dist/types/src/hooks/useAudioTrack.d.ts.map +1 -1
  81. package/dist/types/src/hooks/useQueueModelAdapter.d.ts +1 -1
  82. package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +1 -1
  83. package/dist/types/src/hooks/useTranscriber.d.ts +2 -2
  84. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  85. package/dist/types/src/hooks/useVoiceInput.d.ts.map +1 -1
  86. package/dist/types/src/index.d.ts +1 -1
  87. package/dist/types/src/index.d.ts.map +1 -1
  88. package/dist/types/src/meta.d.ts +2 -3
  89. package/dist/types/src/meta.d.ts.map +1 -1
  90. package/dist/types/src/model/model.d.ts +2 -2
  91. package/dist/types/src/model/model.d.ts.map +1 -1
  92. package/dist/types/src/{segments-normalization → normalization}/index.d.ts +1 -1
  93. package/dist/types/src/normalization/index.d.ts.map +1 -0
  94. package/dist/types/src/{segments-normalization → normalization}/message-normalizer.d.ts +5 -5
  95. package/dist/types/src/normalization/message-normalizer.d.ts.map +1 -0
  96. package/dist/types/src/normalization/normalization.d.ts +364 -0
  97. package/dist/types/src/normalization/normalization.d.ts.map +1 -0
  98. package/dist/types/src/normalization/normalization.test.d.ts.map +1 -0
  99. package/dist/types/src/normalization/utils.d.ts +3 -0
  100. package/dist/types/src/normalization/utils.d.ts.map +1 -0
  101. package/dist/types/src/operations/create.d.ts +5 -0
  102. package/dist/types/src/operations/create.d.ts.map +1 -0
  103. package/dist/types/src/operations/definitions.d.ts +917 -0
  104. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  105. package/dist/types/src/operations/index.d.ts +4 -0
  106. package/dist/types/src/operations/index.d.ts.map +1 -0
  107. package/dist/types/src/operations/open.d.ts +5 -0
  108. package/dist/types/src/operations/open.d.ts.map +1 -0
  109. package/dist/types/src/operations/summarize.d.ts +8 -0
  110. package/dist/types/src/operations/summarize.d.ts.map +1 -0
  111. package/dist/types/src/stories/FileTranscription.stories.d.ts +18 -0
  112. package/dist/types/src/stories/FileTranscription.stories.d.ts.map +1 -0
  113. package/dist/types/src/stories/KeyWordRecognition.stories.d.ts +14 -0
  114. package/dist/types/src/stories/KeyWordRecognition.stories.d.ts.map +1 -0
  115. package/dist/types/src/stories/MicrophoneTranscription.stories.d.ts +20 -0
  116. package/dist/types/src/stories/MicrophoneTranscription.stories.d.ts.map +1 -0
  117. package/dist/types/src/stories/TranscriptionStory.d.ts +23 -0
  118. package/dist/types/src/stories/TranscriptionStory.d.ts.map +1 -0
  119. package/dist/types/src/stories/useIsSpeaking.d.ts.map +1 -0
  120. package/dist/types/src/testing/testing.d.ts +10 -10
  121. package/dist/types/src/testing/testing.d.ts.map +1 -1
  122. package/dist/types/src/transcriber/media-stream-recorder.d.ts +3 -3
  123. package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
  124. package/dist/types/src/transcriber/transcriber.d.ts +60 -5
  125. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  126. package/dist/types/src/transcriber/transcriber.test.d.ts +2 -0
  127. package/dist/types/src/transcriber/transcriber.test.d.ts.map +1 -0
  128. package/dist/types/src/transcriber/transcription-manager.d.ts +12 -13
  129. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  130. package/dist/types/src/translations.d.ts +7 -8
  131. package/dist/types/src/translations.d.ts.map +1 -1
  132. package/dist/types/src/types/capabilities.d.ts +19 -0
  133. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  134. package/dist/types/src/types/defs.d.ts +5 -0
  135. package/dist/types/src/types/defs.d.ts.map +1 -0
  136. package/dist/types/src/types/index.d.ts +2 -2
  137. package/dist/types/src/types/index.d.ts.map +1 -1
  138. package/dist/types/src/util/array.d.ts.map +1 -1
  139. package/dist/types/src/util/get-time-str.d.ts.map +1 -1
  140. package/dist/types/src/util/index.d.ts +1 -0
  141. package/dist/types/src/util/index.d.ts.map +1 -1
  142. package/dist/types/src/util/monitor-audio-level.d.ts.map +1 -1
  143. package/dist/types/src/util/render-byline.d.ts +4 -0
  144. package/dist/types/src/util/render-byline.d.ts.map +1 -0
  145. package/dist/types/tsconfig.tsbuildinfo +1 -1
  146. package/package.json +108 -80
  147. package/src/TranscriptionPlugin.tsx +47 -60
  148. package/src/blueprints/index.ts +5 -0
  149. package/src/blueprints/transcription-blueprint.ts +29 -0
  150. package/src/capabilities/blueprint-definition.ts +17 -0
  151. package/src/capabilities/index.ts +9 -6
  152. package/src/capabilities/operation-handler.ts +16 -0
  153. package/src/capabilities/react-surface.tsx +23 -14
  154. package/src/capabilities/transcriber.ts +54 -42
  155. package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +77 -72
  156. package/src/components/Transcription/Transcription.tsx +64 -0
  157. package/src/components/{Transcript → Transcription}/index.ts +1 -1
  158. package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +15 -48
  159. package/src/components/index.ts +1 -6
  160. package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +35 -0
  161. package/src/containers/TranscriptionContainer/index.ts +5 -0
  162. package/src/containers/index.ts +7 -0
  163. package/src/hooks/useAudioFile.ts +49 -53
  164. package/src/hooks/useQueueModelAdapter.ts +1 -1
  165. package/src/hooks/useTranscriber.ts +12 -4
  166. package/src/hooks/useVoiceInput.ts +3 -3
  167. package/src/index.ts +1 -1
  168. package/src/meta.ts +9 -6
  169. package/src/model/model.test.ts +27 -21
  170. package/src/model/model.ts +3 -3
  171. package/src/{segments-normalization → normalization}/message-normalizer.ts +20 -19
  172. package/src/{segments-normalization → normalization}/normalization.test.ts +26 -33
  173. package/src/normalization/normalization.ts +77 -0
  174. package/src/{segments-normalization → normalization}/utils.ts +2 -2
  175. package/src/operations/create.ts +24 -0
  176. package/src/operations/definitions.ts +101 -0
  177. package/src/operations/index.ts +13 -0
  178. package/src/operations/open.ts +28 -0
  179. package/src/operations/summarize.ts +102 -0
  180. package/src/{components/stories → stories}/FileTranscription.stories.tsx +98 -71
  181. package/src/{components/stories → stories}/KeyWordRecognition.stories.tsx +46 -40
  182. package/src/{components/stories → stories}/MicrophoneTranscription.stories.tsx +84 -100
  183. package/src/stories/TranscriptionStory.tsx +93 -0
  184. package/src/testing/testing.ts +41 -41
  185. package/src/transcriber/media-stream-recorder.ts +4 -4
  186. package/src/transcriber/transcriber.browser.test.ts +5 -5
  187. package/src/transcriber/transcriber.test.ts +104 -0
  188. package/src/transcriber/transcriber.ts +101 -62
  189. package/src/transcriber/transcription-manager.ts +37 -52
  190. package/src/translations.ts +7 -7
  191. package/src/types/capabilities.ts +39 -0
  192. package/src/types/defs.ts +9 -0
  193. package/src/types/index.ts +2 -2
  194. package/src/util/index.ts +1 -0
  195. package/src/util/render-byline.ts +33 -0
  196. package/dist/lib/browser/TranscriptContainer-E5NBJPAY.mjs +0 -11
  197. package/dist/lib/browser/chunk-5WH45KBY.mjs +0 -19
  198. package/dist/lib/browser/chunk-5WH45KBY.mjs.map +0 -7
  199. package/dist/lib/browser/chunk-EQBICGOD.mjs +0 -8
  200. package/dist/lib/browser/chunk-EQBICGOD.mjs.map +0 -7
  201. package/dist/lib/browser/chunk-F2WY3YTD.mjs +0 -764
  202. package/dist/lib/browser/chunk-F2WY3YTD.mjs.map +0 -7
  203. package/dist/lib/browser/chunk-R7INNNUQ.mjs +0 -55
  204. package/dist/lib/browser/chunk-R7INNNUQ.mjs.map +0 -7
  205. package/dist/lib/browser/chunk-U6QBOGTN.mjs +0 -16
  206. package/dist/lib/browser/chunk-U6QBOGTN.mjs.map +0 -7
  207. package/dist/lib/browser/chunk-VDKDOZRR.mjs +0 -495
  208. package/dist/lib/browser/chunk-VDKDOZRR.mjs.map +0 -7
  209. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs +0 -30
  210. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs.map +0 -7
  211. package/dist/lib/browser/react-surface-FJTMNF3K.mjs +0 -34
  212. package/dist/lib/browser/react-surface-FJTMNF3K.mjs.map +0 -7
  213. package/dist/lib/browser/transcriber-YVOTUBKQ.mjs +0 -56
  214. package/dist/lib/browser/transcriber-YVOTUBKQ.mjs.map +0 -7
  215. package/dist/lib/node-esm/TranscriptContainer-UOS7JG72.mjs +0 -12
  216. package/dist/lib/node-esm/chunk-DN522SAP.mjs +0 -10
  217. package/dist/lib/node-esm/chunk-DN522SAP.mjs.map +0 -7
  218. package/dist/lib/node-esm/chunk-HSCG4XPR.mjs +0 -496
  219. package/dist/lib/node-esm/chunk-HSCG4XPR.mjs.map +0 -7
  220. package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs +0 -765
  221. package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs.map +0 -7
  222. package/dist/lib/node-esm/chunk-RHF2ALML.mjs +0 -17
  223. package/dist/lib/node-esm/chunk-RHF2ALML.mjs.map +0 -7
  224. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs +0 -56
  225. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs.map +0 -7
  226. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs +0 -21
  227. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs.map +0 -7
  228. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs +0 -31
  229. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs.map +0 -7
  230. package/dist/lib/node-esm/react-surface-57TSIDR2.mjs +0 -35
  231. package/dist/lib/node-esm/react-surface-57TSIDR2.mjs.map +0 -7
  232. package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs +0 -57
  233. package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs.map +0 -7
  234. package/dist/types/src/capabilities/capabilities.d.ts +0 -17
  235. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  236. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  237. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  238. package/dist/types/src/components/Transcript/Transcript.d.ts +0 -20
  239. package/dist/types/src/components/Transcript/Transcript.d.ts.map +0 -1
  240. package/dist/types/src/components/Transcript/Transcript.stories.d.ts +0 -24
  241. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +0 -1
  242. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -28
  243. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
  244. package/dist/types/src/components/Transcript/index.d.ts +0 -2
  245. package/dist/types/src/components/Transcript/index.d.ts.map +0 -1
  246. package/dist/types/src/components/Transcript/transcript-extension.d.ts +0 -19
  247. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
  248. package/dist/types/src/components/TranscriptContainer.d.ts +0 -9
  249. package/dist/types/src/components/TranscriptContainer.d.ts.map +0 -1
  250. package/dist/types/src/components/stories/FileTranscription.stories.d.ts +0 -17
  251. package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +0 -1
  252. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +0 -10
  253. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +0 -1
  254. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +0 -19
  255. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +0 -1
  256. package/dist/types/src/components/stories/TranscriptionStory.d.ts +0 -11
  257. package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +0 -1
  258. package/dist/types/src/components/stories/useIsSpeaking.d.ts.map +0 -1
  259. package/dist/types/src/segments-normalization/index.d.ts.map +0 -1
  260. package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +0 -1
  261. package/dist/types/src/segments-normalization/normalization.d.ts +0 -329
  262. package/dist/types/src/segments-normalization/normalization.d.ts.map +0 -1
  263. package/dist/types/src/segments-normalization/normalization.test.d.ts.map +0 -1
  264. package/dist/types/src/segments-normalization/utils.d.ts +0 -3
  265. package/dist/types/src/segments-normalization/utils.d.ts.map +0 -1
  266. package/dist/types/src/types/schema.d.ts +0 -41
  267. package/dist/types/src/types/schema.d.ts.map +0 -1
  268. package/dist/types/src/types/types.d.ts +0 -31
  269. package/dist/types/src/types/types.d.ts.map +0 -1
  270. package/src/capabilities/capabilities.ts +0 -33
  271. package/src/capabilities/intent-resolver.ts +0 -24
  272. package/src/components/Transcript/Transcript.tsx +0 -100
  273. package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
  274. package/src/components/TranscriptContainer.tsx +0 -35
  275. package/src/components/stories/TranscriptionStory.tsx +0 -41
  276. package/src/segments-normalization/normalization.ts +0 -106
  277. package/src/types/schema.ts +0 -41
  278. package/src/types/types.ts +0 -32
  279. package/dist/lib/browser/{TranscriptContainer-E5NBJPAY.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  280. package/dist/lib/node-esm/{TranscriptContainer-UOS7JG72.mjs.map → chunk-HSLMI22Q.mjs.map} +0 -0
  281. package/dist/types/src/{segments-normalization → normalization}/normalization.test.d.ts +0 -0
  282. package/dist/types/src/{components/stories → stories}/useIsSpeaking.d.ts +0 -0
  283. package/src/{segments-normalization → normalization}/index.ts +1 -1
  284. /package/src/{components/stories → stories}/useIsSpeaking.tsx +0 -0
@@ -1,122 +1,1109 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- TranscriptContainer
4
- } from "./chunk-DN522SAP.mjs";
5
- import {
6
- IntentResolver,
7
- ReactSurface,
8
- Transcriber as Transcriber2,
9
- Transcript,
10
- TranscriptionContainer,
11
- renderMarkdown,
12
- useAudioFile,
13
- useAudioTrack,
14
- useQueueModelAdapter,
15
- useTranscriber,
16
- useVoiceInput
17
- } from "./chunk-Q3JKLPTW.mjs";
18
- import {
19
- MediaStreamRecorder,
20
- Transcriber,
21
- TranscriptionManager
22
- } from "./chunk-HSCG4XPR.mjs";
23
- import {
24
- TranscriptType
25
- } from "./chunk-U65ZWK3L.mjs";
26
2
  import {
27
3
  TranscriptionCapabilities
28
- } from "./chunk-RHF2ALML.mjs";
4
+ } from "./chunk-KO3IOD2O.mjs";
29
5
  import {
30
- TRANSCRIPTION_PLUGIN,
31
- meta
32
- } from "./chunk-XMUCZBP3.mjs";
6
+ mergeFloat64Arrays,
7
+ renderByline
8
+ } from "./chunk-O533NBMK.mjs";
9
+ import "./chunk-HSLMI22Q.mjs";
33
10
 
34
- // src/TranscriptionPlugin.tsx
35
- import { Capabilities, Events, contributes, defineModule, definePlugin } from "@dxos/app-framework";
36
- import { Obj } from "@dxos/echo";
37
- import { ClientCapabilities, ClientEvents } from "@dxos/plugin-client";
38
- import { getSpace } from "@dxos/react-client/echo";
39
- import { DataType } from "@dxos/schema";
11
+ // src/components/Transcription/Transcription.tsx
12
+ import React from "react";
13
+ import { useThemeContext } from "@dxos/react-ui";
14
+ import { useTextEditor } from "@dxos/react-ui-editor";
15
+ import { autoScroll, createBasicExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown, documentSlots, preview } from "@dxos/ui-editor";
16
+ import { composable, composableProps } from "@dxos/ui-theme";
17
+ import { isTruthy } from "@dxos/util";
18
+
19
+ // src/components/Transcription/transcription-extension.ts
20
+ import { RangeSetBuilder } from "@codemirror/state";
21
+ import { EditorView, GutterMarker, ViewPlugin, gutter } from "@codemirror/view";
22
+ import { format } from "date-fns/format";
23
+ import { intervalToDuration } from "date-fns/intervalToDuration";
24
+ import { addEventListener, combine } from "@dxos/async";
40
25
 
41
- // src/translations.ts
42
- var translations = [
43
- {
44
- "en-US": {
45
- [meta.id]: {
46
- "plugin name": "Transcription",
47
- "transcript companion label": "Transcript",
48
- "delete button": "Delete",
49
- "bookmark button": "Bookmark",
50
- "scroll to end label": "Scroll to latest",
51
- "settings entity extraction label": "Entity extraction"
26
+ // src/model/model.ts
27
+ import { Text } from "@codemirror/state";
28
+ import { Event } from "@dxos/async";
29
+ import { invariant } from "@dxos/invariant";
30
+ import { log } from "@dxos/log";
31
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/model/model.ts";
32
+ var DocumentAdapter = class {
33
+ _view;
34
+ constructor(_view) {
35
+ this._view = _view;
36
+ }
37
+ /** The document must always have at least one line. */
38
+ lineCount() {
39
+ return this._view.state.doc.lines - 1;
40
+ }
41
+ replaceLines(from, remove, insert) {
42
+ log("replaceLines", {
43
+ count: this._view.state.doc.lines,
44
+ from,
45
+ remove,
46
+ insert
47
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 19, S: this });
48
+ const numLines = this._view.state.doc.lines;
49
+ const posFrom = this._view.state.doc.line(from).from;
50
+ const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;
51
+ let text = insert.join("\n");
52
+ if (posTo === this._view.state.doc.length) {
53
+ text += "\n";
54
+ }
55
+ this._view.dispatch({
56
+ changes: {
57
+ from: posFrom,
58
+ to: posTo,
59
+ insert: text
60
+ }
61
+ });
62
+ }
63
+ };
64
+ var SerializationModel = class {
65
+ _renderer;
66
+ /** Emits when the document is updated. */
67
+ update = new Event();
68
+ /** Ordered set of chunks. */
69
+ _chunks = [];
70
+ /** Map of chunk IDs to their current line counts. */
71
+ _chunkLineCounts = /* @__PURE__ */ new Map();
72
+ /** Map of line numbers to chunk IDs. */
73
+ _lineToChunk = /* @__PURE__ */ new Map();
74
+ /** Track chunk changes since last sync. */
75
+ _changes = [];
76
+ constructor(_renderer, initialChunks = []) {
77
+ this._renderer = _renderer;
78
+ initialChunks.forEach((chunk) => {
79
+ this.appendChunk(chunk);
80
+ });
81
+ }
82
+ toJSON() {
83
+ return {
84
+ chunks: this._chunks.length,
85
+ changes: this._changes.length
86
+ };
87
+ }
88
+ get doc() {
89
+ return Text.of([
90
+ ...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)),
91
+ ""
92
+ ]);
93
+ }
94
+ get chunks() {
95
+ return this._chunks;
96
+ }
97
+ /**
98
+ * Get the block ID at the given line number.
99
+ */
100
+ getChunkAtLine(line) {
101
+ return this._lineToChunk.get(line);
102
+ }
103
+ reset() {
104
+ this._chunks.length = 0;
105
+ this._chunkLineCounts.clear();
106
+ this._lineToChunk.clear();
107
+ this.update.emit();
108
+ return this;
109
+ }
110
+ appendChunk(chunk) {
111
+ const index = this._chunks.length;
112
+ this._chunks.push(chunk);
113
+ this._changes.push({
114
+ type: "append",
115
+ index,
116
+ chunk
117
+ });
118
+ this.update.emit();
119
+ return this;
120
+ }
121
+ updateChunk(chunk) {
122
+ const index = this._chunks.findIndex((c) => c.id === chunk.id);
123
+ invariant(index !== -1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 102, S: this, A: ["index !== -1", ""] });
124
+ this._chunks[index] = chunk;
125
+ this._changes.push({
126
+ type: "update",
127
+ index,
128
+ chunk
129
+ });
130
+ this.update.emit();
131
+ return this;
132
+ }
133
+ deleteBlock(id) {
134
+ const index = this._chunks.findIndex((c) => c.id === id);
135
+ invariant(index !== -1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 114, S: this, A: ["index !== -1", ""] });
136
+ this._chunks.splice(index, 1);
137
+ this._changes.push({
138
+ type: "delete",
139
+ index,
140
+ id
141
+ });
142
+ this.update.emit();
143
+ return this;
144
+ }
145
+ /**
146
+ * Syncs the tracked changes with the ChunkDocument.
147
+ */
148
+ sync(document2) {
149
+ log("sync", {
150
+ changes: this._changes
151
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 127, S: this });
152
+ for (const change of this._changes) {
153
+ switch (change.type) {
154
+ case "append": {
155
+ const lines = this._renderer(change.chunk, change.index);
156
+ const lastLine = document2.lineCount();
157
+ document2.replaceLines(lastLine + 1, 0, lines);
158
+ break;
159
+ }
160
+ case "update": {
161
+ let lineStart = 1;
162
+ for (let i = 0; i < change.index; i++) {
163
+ lineStart += this._chunkLineCounts.get(this._chunks[i].id);
164
+ }
165
+ const previousLineCount = this._chunkLineCounts.get(change.chunk.id);
166
+ const newLines = this._renderer(change.chunk, change.index);
167
+ document2.replaceLines(lineStart, previousLineCount, newLines);
168
+ break;
169
+ }
170
+ case "delete": {
171
+ let lineStart = 1;
172
+ for (let i = 0; i < change.index; i++) {
173
+ lineStart += this._chunkLineCounts.get(this._chunks[i].id);
174
+ }
175
+ const previousLineCount = this._chunkLineCounts.get(change.id);
176
+ document2.replaceLines(lineStart, previousLineCount, []);
177
+ break;
178
+ }
179
+ }
180
+ }
181
+ this._lineToChunk.clear();
182
+ let currentLine = 1;
183
+ for (const [index, chunk] of this._chunks.entries()) {
184
+ const lineCount = this._renderer(chunk, index).length;
185
+ this._chunkLineCounts.set(chunk.id, lineCount);
186
+ this._lineToChunk.set(currentLine, chunk);
187
+ currentLine += lineCount;
188
+ }
189
+ const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));
190
+ for (const id of this._chunkLineCounts.keys()) {
191
+ if (!chunkIds.has(id)) {
192
+ this._chunkLineCounts.delete(id);
52
193
  }
53
194
  }
195
+ this._changes.length = 0;
196
+ return this;
54
197
  }
55
- ];
198
+ };
56
199
 
57
- // src/TranscriptionPlugin.tsx
58
- var TranscriptionPlugin = () => definePlugin(meta, [
59
- defineModule({
60
- id: `${meta.id}/module/translations`,
61
- activatesOn: Events.SetupTranslations,
62
- activate: () => contributes(Capabilities.Translations, translations)
63
- }),
64
- defineModule({
65
- id: `${meta.id}/module/metadata`,
66
- activatesOn: Events.SetupMetadata,
67
- activate: (context) => contributes(Capabilities.Metadata, {
68
- id: TranscriptType.typename,
69
- metadata: {
70
- icon: "ph--subtitles--regular",
71
- // TODO(wittjosiah): Factor out. Artifact? Separate capability?
72
- getTextContent: async (transcript) => {
73
- const space = getSpace(transcript);
74
- const members = space?.members.get().map((member) => member.identity) ?? [];
75
- const queue = space?.queues.get(transcript.queue.dxn);
76
- await queue?.refresh();
77
- const content = queue?.objects.filter((message) => Obj.instanceOf(DataType.Message, message)).flatMap((message, index) => renderMarkdown(members)(message, index)).join("\n\n");
78
- return content;
200
+ // src/components/Transcription/transcription-extension.ts
201
+ var transcription = ({ model, started }) => {
202
+ return [
203
+ // Show timestamps in the gutter.
204
+ gutter({
205
+ class: "cm-timestamp-gutter",
206
+ lineMarkerChange: (update) => update.docChanged || update.viewportChanged,
207
+ markers: (view) => {
208
+ const start = getStartTime(started, model.chunks[0]);
209
+ const builder = new RangeSetBuilder();
210
+ for (const { from, to } of view.visibleRanges) {
211
+ let line = view.state.doc.lineAt(from);
212
+ while (line.from <= to) {
213
+ const block = model.getChunkAtLine(line.number)?.blocks[0];
214
+ const timestamp = block?._tag === "transcript" && block.started;
215
+ if (timestamp) {
216
+ builder.add(line.from, line.from, new TimestampMarker(line.number, new Date(timestamp), start));
217
+ }
218
+ if (line.to + 1 > view.state.doc.length) {
219
+ break;
220
+ }
221
+ line = view.state.doc.lineAt(line.to + 1);
222
+ }
79
223
  }
224
+ return builder.finish();
225
+ }
226
+ }),
227
+ // Listen for model updates.
228
+ ViewPlugin.fromClass(class {
229
+ _controls;
230
+ _cleanup;
231
+ _adapter;
232
+ _initialized = false;
233
+ constructor(view) {
234
+ this._adapter = new DocumentAdapter(view);
235
+ const scroller = view.scrollDOM;
236
+ let isAutoScrolling = false;
237
+ let hasScrolled = false;
238
+ let timeout;
239
+ const scrollToBottom = (smooth = false) => {
240
+ scroller.style.scrollBehavior = smooth ? "smooth" : "";
241
+ scroller.classList.add("cm-hide-scrollbar");
242
+ isAutoScrolling = true;
243
+ clearTimeout(timeout);
244
+ timeout = setTimeout(() => {
245
+ this._controls?.classList.add("opacity-0");
246
+ scroller.classList.remove("cm-hide-scrollbar");
247
+ isAutoScrolling = false;
248
+ }, 500);
249
+ view.dispatch({
250
+ effects: EditorView.scrollIntoView(view.state.doc.length, {
251
+ y: "end"
252
+ })
253
+ });
254
+ };
255
+ this._cleanup = combine(addEventListener(view.scrollDOM, "scroll", () => {
256
+ if (!isAutoScrolling) {
257
+ hasScrolled = true;
258
+ this._controls?.classList.remove("opacity-0");
259
+ }
260
+ }), model.update.on(() => {
261
+ const autoScroll2 = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight === 0 || !hasScrolled;
262
+ model.sync(this._adapter);
263
+ if (autoScroll2) {
264
+ scrollToBottom(true);
265
+ }
266
+ }));
267
+ }
268
+ update(_update) {
269
+ if (!this._initialized) {
270
+ this._initialized = true;
271
+ setTimeout(() => {
272
+ model.sync(this._adapter);
273
+ });
274
+ }
275
+ }
276
+ destroy() {
277
+ this._controls?.remove();
278
+ this._cleanup();
279
+ }
280
+ }),
281
+ EditorView.theme({
282
+ ".cm-gutters": {
283
+ backgroundColor: "var(--color-base-surface)"
284
+ },
285
+ ".cm-timestamp-gutter": {
286
+ width: "6rem",
287
+ paddingLeft: "0.5rem",
288
+ paddingRight: "1rem"
289
+ },
290
+ ".cm-timestamp-gutter > .cm-gutterElement > div": {
291
+ display: "inline-flex",
292
+ textAlign: "right",
293
+ padding: "3px"
80
294
  }
81
295
  })
82
- }),
83
- defineModule({
84
- id: `${meta.id}/module/schema`,
85
- activatesOn: ClientEvents.SetupSchema,
86
- activate: () => [
87
- contributes(ClientCapabilities.Schema, [
88
- TranscriptType
89
- ])
90
- ]
91
- }),
92
- defineModule({
93
- id: `${meta.id}/module/react-surface`,
94
- activatesOn: Events.SetupReactSurface,
95
- activate: ReactSurface
96
- }),
97
- defineModule({
98
- id: `${meta.id}/module/intent-resolver`,
99
- activatesOn: Events.SetupIntentResolver,
100
- activate: IntentResolver
101
- }),
102
- defineModule({
103
- id: `${meta.id}/module/transcription`,
104
- activatesOn: Events.SetupAppGraph,
105
- activate: Transcriber2
296
+ ];
297
+ };
298
+ var TimestampMarker = class extends GutterMarker {
299
+ _line;
300
+ _timestamp;
301
+ _started;
302
+ constructor(_line, _timestamp, _started) {
303
+ super(), this._line = _line, this._timestamp = _timestamp, this._started = _started;
304
+ }
305
+ eq(other) {
306
+ return this._timestamp === other._timestamp;
307
+ }
308
+ toDOM(view) {
309
+ const el = document.createElement("div");
310
+ el.className = "text-sm text-subdued hover:bg-hover-surface cursor-pointer";
311
+ el.textContent = formatTimestamp(this._timestamp, this._started);
312
+ el.onclick = () => {
313
+ const pos = view.state.doc.line(this._line).from;
314
+ view.dispatch({
315
+ effects: EditorView.scrollIntoView(pos, {
316
+ y: "start"
317
+ })
318
+ });
319
+ };
320
+ return el;
321
+ }
322
+ };
323
+ var getStartTime = (started, message) => {
324
+ if (started) {
325
+ return started;
326
+ }
327
+ if (message?.blocks[0]?._tag === "transcript" && message.blocks[0].started) {
328
+ return new Date(message.blocks[0].started);
329
+ }
330
+ return void 0;
331
+ };
332
+ var formatTimestamp = (timestamp, relative) => {
333
+ if (relative) {
334
+ const pad = (n = 0) => String(n).padStart(2, "0");
335
+ const { hours, minutes, seconds } = intervalToDuration({
336
+ start: relative,
337
+ end: timestamp
338
+ });
339
+ return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
340
+ } else {
341
+ return format(timestamp, "HH:mm:ss");
342
+ }
343
+ };
344
+
345
+ // src/components/Transcription/Transcription.tsx
346
+ var Transcription = composable(({ transcript: object, model, children, ...props }, forwardedRef) => {
347
+ const { themeMode } = useThemeContext();
348
+ const { parentRef } = useTextEditor(() => {
349
+ return {
350
+ extensions: [
351
+ createBasicExtensions({
352
+ readOnly: true,
353
+ lineWrapping: true,
354
+ search: true
355
+ }),
356
+ createMarkdownExtensions(),
357
+ createThemeExtensions({
358
+ themeMode,
359
+ slots: documentSlots
360
+ }),
361
+ decorateMarkdown(),
362
+ preview(),
363
+ transcription({
364
+ model,
365
+ started: object?.started ? new Date(object.started) : void 0
366
+ }),
367
+ autoScroll()
368
+ ].filter(isTruthy)
369
+ };
370
+ }, [
371
+ model
372
+ ]);
373
+ return /* @__PURE__ */ React.createElement("div", {
374
+ ...composableProps(props, {
375
+ classNames: "dx-container"
376
+ }),
377
+ ref: parentRef,
378
+ "data-popover-collision-boundary": true
379
+ });
380
+ });
381
+
382
+ // src/hooks/useAudioFile.ts
383
+ import { useEffect, useState } from "react";
384
+ import { scheduleTask } from "@dxos/async";
385
+ import { Context } from "@dxos/context";
386
+ import { log as log2 } from "@dxos/log";
387
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useAudioFile.ts";
388
+ var useAudioFile = (audioUrl, constraints) => {
389
+ const [{ audio, stream, track }, setStream] = useState({});
390
+ useEffect(() => {
391
+ const ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 11 });
392
+ scheduleTask(ctx, async () => {
393
+ try {
394
+ const response = await fetch(audioUrl);
395
+ const blob = await response.blob();
396
+ const objectUrl = URL.createObjectURL(blob);
397
+ ctx.onDispose(() => {
398
+ URL.revokeObjectURL(objectUrl);
399
+ });
400
+ const audio2 = new Audio();
401
+ audio2.src = objectUrl;
402
+ await new Promise((resolve, reject) => {
403
+ audio2.addEventListener("error", (err) => {
404
+ log2.error("error", {
405
+ err
406
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 25, S: void 0 });
407
+ reject(err);
408
+ }, {
409
+ once: true
410
+ });
411
+ audio2.addEventListener("canplay", async () => {
412
+ resolve();
413
+ }, {
414
+ once: true
415
+ });
416
+ audio2.load();
417
+ });
418
+ const audioCtx = new AudioContext();
419
+ if (audioCtx.state === "suspended") {
420
+ await audioCtx.resume();
421
+ }
422
+ const destination = audioCtx.createMediaStreamDestination();
423
+ destination.channelCount = 1;
424
+ const source = audioCtx.createMediaElementSource(audio2);
425
+ source.connect(destination);
426
+ const track2 = destination.stream.getAudioTracks()[0];
427
+ if (constraints) {
428
+ await track2.applyConstraints(constraints).catch((err) => log2.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 50, S: void 0 }));
429
+ }
430
+ setStream({
431
+ audio: audio2,
432
+ stream: destination.stream,
433
+ track: destination.stream.getAudioTracks()[0]
434
+ });
435
+ } catch (err) {
436
+ log2.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 59, S: void 0 });
437
+ }
438
+ });
439
+ return () => {
440
+ void ctx.dispose();
441
+ };
442
+ }, [
443
+ audioUrl
444
+ ]);
445
+ return {
446
+ audio,
447
+ stream,
448
+ track
449
+ };
450
+ };
451
+
452
+ // src/hooks/useAudioTrack.ts
453
+ import { useEffect as useEffect2, useState as useState2 } from "react";
454
+ var useAudioTrack = (active, constraints) => {
455
+ const [track, setTrack] = useState2();
456
+ useEffect2(() => {
457
+ if (!active) {
458
+ track?.stop();
459
+ setTrack(void 0);
460
+ return;
461
+ }
462
+ const initAudio = async () => {
463
+ const audio = new Audio();
464
+ audio.srcObject = await navigator.mediaDevices.getUserMedia({
465
+ audio: constraints ?? true
466
+ });
467
+ const [track2] = audio.srcObject.getAudioTracks();
468
+ if (track2) {
469
+ setTrack(track2);
470
+ }
471
+ };
472
+ if (active) {
473
+ void initAudio();
474
+ }
475
+ }, [
476
+ active
477
+ ]);
478
+ return track;
479
+ };
480
+
481
+ // src/hooks/useQueueModelAdapter.ts
482
+ import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
483
+ var useQueueModelAdapter = (renderer, queue, initialChunks = []) => {
484
+ const model = useMemo(() => new SerializationModel(renderer, initialChunks), [
485
+ queue
486
+ ]);
487
+ const [loaded, setLoaded] = useState3(false);
488
+ useEffect3(() => {
489
+ if (!queue) {
490
+ return;
491
+ }
492
+ const update = () => {
493
+ for (const block of queue?.objects ?? []) {
494
+ model.appendChunk(block);
495
+ }
496
+ setLoaded(true);
497
+ };
498
+ let i;
499
+ if (queue.isLoading) {
500
+ i = setInterval(() => {
501
+ if (!queue?.isLoading) {
502
+ clearInterval(i);
503
+ update();
504
+ }
505
+ }, 1e3);
506
+ } else {
507
+ update();
508
+ }
509
+ return () => clearTimeout(i);
510
+ }, [
511
+ model,
512
+ queue
513
+ ]);
514
+ useEffect3(() => {
515
+ if (!loaded || !queue || model.chunks.length === queue.objects.length) {
516
+ return;
517
+ }
518
+ const chunk = queue.objects.at(-1);
519
+ if (chunk) {
520
+ model.appendChunk(chunk);
521
+ }
522
+ }, [
523
+ model,
524
+ loaded,
525
+ queue?.objects.length
526
+ ]);
527
+ return model;
528
+ };
529
+
530
+ // src/hooks/useTranscriber.ts
531
+ import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
532
+ import { useCapabilities } from "@dxos/app-framework/ui";
533
+ import { TranscriptionCapabilities as TranscriptionCapabilities2 } from "#types";
534
+ var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments, transcribe }) => {
535
+ const [getTranscriber] = useCapabilities(TranscriptionCapabilities2.Transcriber);
536
+ const transcriber = useMemo2(() => {
537
+ if (!getTranscriber || !audioStreamTrack || !onSegments) {
538
+ return void 0;
539
+ }
540
+ return getTranscriber({
541
+ audioStreamTrack,
542
+ recorderConfig,
543
+ transcriberConfig,
544
+ onSegments,
545
+ transcribe
546
+ });
547
+ }, [
548
+ getTranscriber,
549
+ audioStreamTrack,
550
+ recorderConfig,
551
+ transcriberConfig,
552
+ onSegments,
553
+ transcribe
554
+ ]);
555
+ useEffect4(() => {
556
+ return () => {
557
+ void transcriber?.close();
558
+ };
559
+ }, [
560
+ transcriber
561
+ ]);
562
+ return transcriber;
563
+ };
564
+
565
+ // src/hooks/useVoiceInput.ts
566
+ import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
567
+ import { scheduleMicroTask } from "@dxos/async";
568
+ import { Context as Context2 } from "@dxos/context";
569
+ import { log as log3 } from "@dxos/log";
570
+ import { useSoundEffect } from "@dxos/react-ui-sfx";
571
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
572
+ var useVoiceInput = ({ active, onUpdate }) => {
573
+ const soundStart = useSoundEffect("StartRecording");
574
+ const soundStop = useSoundEffect("StopRecording");
575
+ const handleSegments = useCallback(async (segments) => {
576
+ const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
577
+ onUpdate(text);
578
+ }, []);
579
+ const [recording, setRecording] = useState4(false);
580
+ const track = useAudioTrack(active);
581
+ const transcriber = useTranscriber({
582
+ audioStreamTrack: track,
583
+ onSegments: handleSegments
584
+ });
585
+ useEffect5(() => {
586
+ const ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 29 });
587
+ scheduleMicroTask(ctx, async () => {
588
+ if (active && transcriber) {
589
+ await transcriber.open();
590
+ log3.info("starting...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 33, S: void 0 });
591
+ setRecording(true);
592
+ void soundStart.play();
593
+ transcriber.startChunksRecording();
594
+ } else if (!active && transcriber?.isOpen) {
595
+ transcriber?.stopChunksRecording();
596
+ await transcriber?.close();
597
+ log3.info("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 40, S: void 0 });
598
+ setRecording(false);
599
+ void soundStop.play();
600
+ }
601
+ });
602
+ return () => {
603
+ void ctx.dispose();
604
+ };
605
+ }, [
606
+ active,
607
+ transcriber
608
+ ]);
609
+ return {
610
+ recording
611
+ };
612
+ };
613
+
614
+ // src/meta.ts
615
+ import { trim } from "@dxos/util";
616
+ var meta = {
617
+ id: "org.dxos.plugin.transcription",
618
+ name: "Transcription",
619
+ description: trim`
620
+ Real-time voice-to-text transcription service for capturing spoken content.
621
+ Convert audio input into searchable text that integrates seamlessly with notes and documents.
622
+ `,
623
+ icon: "ph--microphone--regular",
624
+ iconHue: "sky",
625
+ source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-transcription",
626
+ tags: [
627
+ "labs"
628
+ ],
629
+ screenshots: []
630
+ };
631
+
632
+ // src/transcriber/media-stream-recorder.ts
633
+ import { MediaRecorder, register } from "extendable-media-recorder";
634
+ import { WaveFile } from "wavefile";
635
+ import { synchronized } from "@dxos/async";
636
+ import { invariant as invariant2 } from "@dxos/invariant";
637
+ import { log as log4 } from "@dxos/log";
638
+ import { trace } from "@dxos/tracing";
639
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/transcriber/media-stream-recorder.ts";
640
+ function _ts_decorate(decorators, target, key, desc) {
641
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
642
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
643
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
644
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
645
+ }
646
+ var initializingPromise;
647
+ var initializeExtendableMediaRecorder = async () => {
648
+ const { connect } = await import("extendable-media-recorder-wav-encoder");
649
+ await register(await connect());
650
+ };
651
+ var MediaStreamRecorder = class {
652
+ _mediaStreamTrack;
653
+ /**
654
+ * Default MediaRecorder implementation do not support wav encoding.
655
+ */
656
+ _config;
657
+ _mediaRecorder = void 0;
658
+ _header = void 0;
659
+ _onChunk;
660
+ constructor({ mediaStreamTrack, config }) {
661
+ this._mediaStreamTrack = mediaStreamTrack;
662
+ this._config = config;
663
+ }
664
+ get wavConfig() {
665
+ const settings = this._mediaStreamTrack.getSettings();
666
+ return {
667
+ channels: settings.channelCount ?? 1,
668
+ sampleRate: settings.sampleRate ?? 16e3,
669
+ bitDepthCode: settings.sampleSize ? String(settings.sampleSize) : "16"
670
+ };
671
+ }
672
+ get mediaStreamTrack() {
673
+ return this._mediaStreamTrack;
674
+ }
675
+ setOnChunk(onChunk) {
676
+ this._onChunk = onChunk;
677
+ }
678
+ async start() {
679
+ await (initializingPromise ??= initializeExtendableMediaRecorder()).catch((err) => log4.info("initializeExtendableMediaRecorder", {
680
+ err
681
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 48, S: this }));
682
+ if (!this._mediaRecorder) {
683
+ const stream = new MediaStream([
684
+ this._mediaStreamTrack
685
+ ]);
686
+ this._mediaRecorder = new MediaRecorder(stream, {
687
+ mimeType: "audio/wav"
688
+ });
689
+ }
690
+ if (this._mediaRecorder.state === "recording") {
691
+ return;
692
+ }
693
+ invariant2(this._onChunk, "MediaStreamRecorder: onChunk is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 62, S: this, A: ["this._onChunk", "'MediaStreamRecorder: onChunk is not set'"] });
694
+ this._mediaRecorder.ondataavailable = (event) => this._ondataavailable(event);
695
+ this._mediaRecorder.start(this._config.interval);
696
+ }
697
+ async stop() {
698
+ if (this._mediaRecorder?.state !== "recording") {
699
+ return;
700
+ }
701
+ this._mediaRecorder.stop();
702
+ }
703
+ async _ondataavailable(event) {
704
+ const blob = event.data;
705
+ const uint8Array = new Uint8Array(await blob.arrayBuffer());
706
+ const isHeader = uint8Array[0] === 82 && // R
707
+ uint8Array[1] === 73 && // I
708
+ uint8Array[2] === 70 && // F
709
+ uint8Array[3] === 70;
710
+ let wav;
711
+ if (isHeader) {
712
+ wav = new WaveFile(uint8Array);
713
+ this._header = uint8Array.slice(0, 44);
714
+ } else if (this._header) {
715
+ wav = new WaveFile(new Uint8Array([
716
+ ...this._header,
717
+ ...uint8Array
718
+ ]));
719
+ } else {
720
+ log4.warn("MediaStreamRecorder: no header", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 90, S: this });
721
+ return;
722
+ }
723
+ this._onChunk({
724
+ timestamp: Date.now(),
725
+ data: wav.getSamples()
726
+ });
727
+ }
728
+ };
729
+ _ts_decorate([
730
+ synchronized
731
+ ], MediaStreamRecorder.prototype, "_ondataavailable", null);
732
+ MediaStreamRecorder = _ts_decorate([
733
+ trace.resource()
734
+ ], MediaStreamRecorder);
735
+
736
+ // src/transcriber/transcriber.ts
737
+ import { WaveFile as WaveFile2 } from "wavefile";
738
+ import { DeferredTask, Trigger } from "@dxos/async";
739
+ import { LifecycleState, Resource } from "@dxos/context";
740
+ import { log as log5 } from "@dxos/log";
741
+ import { trace as trace2 } from "@dxos/tracing";
742
+ import { TRANSCRIPTION_URL } from "#types";
743
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/transcriber/transcriber.ts";
744
+ function _ts_decorate2(decorators, target, key, desc) {
745
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
746
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
747
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
748
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
749
+ }
750
+ var Transcriber = class extends Resource {
751
+ _audioChunks = [];
752
+ _lastUsedTimestamp = 0;
753
+ _openTrigger = new Trigger({
754
+ autoReset: true
755
+ });
756
+ _config;
757
+ _recorder;
758
+ _onSegments;
759
+ _transcribeFn;
760
+ _recording = false;
761
+ _transcribeTask = void 0;
762
+ constructor({ config, recorder, onSegments, transcribe }) {
763
+ super();
764
+ this._config = config;
765
+ this._recorder = recorder;
766
+ this._onSegments = onSegments;
767
+ this._transcribeFn = transcribe;
768
+ }
769
+ async _open(ctx) {
770
+ log5.info("opening", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 41, S: this });
771
+ this._recorder.setOnChunk((chunk) => this._saveAudioChunk(chunk));
772
+ await this._recorder.start();
773
+ this._transcribeTask = new DeferredTask(ctx, async () => this._transcribe());
774
+ this._openTrigger.wake();
775
+ }
776
+ async _close() {
777
+ log5.info("closing", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 48, S: this });
778
+ this._recording = false;
779
+ this._transcribeTask = void 0;
780
+ await this._recorder.stop();
781
+ }
782
+ startChunksRecording() {
783
+ log5.info("starting", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 54, S: this });
784
+ if (this._lifecycleState !== LifecycleState.OPEN) {
785
+ return;
786
+ }
787
+ this._recording = true;
788
+ }
789
+ stopChunksRecording() {
790
+ if (this._lifecycleState !== LifecycleState.OPEN || !this._recording) {
791
+ return;
792
+ }
793
+ this._recording = false;
794
+ this._transcribeTask?.schedule();
795
+ log5.info("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 66, S: this });
796
+ }
797
+ _saveAudioChunk(chunk) {
798
+ log5("saving audio chunk", {
799
+ chunk
800
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 69, S: this });
801
+ this._audioChunks.push(chunk);
802
+ if (!this._recording && (!this._transcribeTask || !this._transcribeTask.scheduled) && this._audioChunks.length >= this._config.prefixBufferChunksAmount) {
803
+ this._audioChunks = this._dropOldChunks();
804
+ } else if (this._audioChunks.length >= this._config.transcribeAfterChunksAmount && this._recording) {
805
+ this._transcribeTask?.schedule();
806
+ }
807
+ }
808
+ async _transcribe() {
809
+ log5("transcribing", {
810
+ chunks: this._audioChunks.length
811
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 81, S: this });
812
+ const chunks = this._audioChunks;
813
+ this._audioChunks = this._dropOldChunks();
814
+ if (chunks.length === 0) {
815
+ return;
816
+ }
817
+ const audio = await this._mergeAudioChunks(chunks);
818
+ const segments = await this._fetchTranscription(audio);
819
+ if (!Array.isArray(segments) || segments.length === 0) {
820
+ return;
821
+ }
822
+ const alignedSegments = this._alignSegments(segments, chunks);
823
+ if (alignedSegments.length > 0) {
824
+ await this._onSegments(alignedSegments);
825
+ }
826
+ }
827
+ _dropOldChunks() {
828
+ return this._config.prefixBufferChunksAmount > 0 ? this._audioChunks.slice(-this._config.prefixBufferChunksAmount) : [];
829
+ }
830
+ async _mergeAudioChunks(chunks) {
831
+ const file = new WaveFile2();
832
+ const wavConfig = this._recorder.wavConfig;
833
+ file.fromScratch(wavConfig.channels, wavConfig.sampleRate, wavConfig.bitDepthCode, mergeFloat64Arrays(chunks.map(({ data }) => data)));
834
+ return file.toBase64();
835
+ }
836
+ async _fetchTranscription(audio) {
837
+ if (audio.length === 0) {
838
+ throw new Error("No audio to send for transcribing");
839
+ }
840
+ let segments;
841
+ if (this._transcribeFn) {
842
+ segments = await this._transcribeFn(audio);
843
+ } else {
844
+ const endpoint = this._config.endpoint ?? TRANSCRIPTION_URL;
845
+ const response = await fetch(`${endpoint}/transcribe`, {
846
+ method: "POST",
847
+ body: JSON.stringify({
848
+ audio
849
+ }),
850
+ headers: {
851
+ "Content-Type": "application/json"
852
+ }
853
+ });
854
+ if (!response.ok) {
855
+ throw new Error(`Transcription failed: ${response.statusText}`);
856
+ }
857
+ ({ segments } = await response.json());
858
+ }
859
+ if (!Array.isArray(segments)) {
860
+ throw new Error("Transcription response payload is invalid");
861
+ }
862
+ log5.info("transcription response", {
863
+ segments: segments.length
864
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 134, S: this });
865
+ return segments;
866
+ }
867
+ _alignSegments(segments, originalChunks) {
868
+ const result = alignWhisperSegments(segments, originalChunks, this._lastUsedTimestamp);
869
+ if (result.lastUsedTimestamp !== void 0) {
870
+ this._lastUsedTimestamp = result.lastUsedTimestamp;
871
+ }
872
+ return result.transcripts;
873
+ }
874
+ };
875
+ _ts_decorate2([
876
+ trace2.span({
877
+ showInBrowserTimeline: true
106
878
  })
107
- ]);
879
+ ], Transcriber.prototype, "_mergeAudioChunks", null);
880
+ _ts_decorate2([
881
+ trace2.span({
882
+ showInBrowserTimeline: true
883
+ })
884
+ ], Transcriber.prototype, "_fetchTranscription", null);
885
+ var alignWhisperSegments = (segments, originalChunks, lastUsedTimestamp) => {
886
+ if (originalChunks.length === 0) {
887
+ return {
888
+ transcripts: []
889
+ };
890
+ }
891
+ const zeroTimestamp = originalChunks[0].timestamp;
892
+ const filteredSegments = segments.filter((segment) => zeroTimestamp + segment.end * 1e3 >= lastUsedTimestamp).map((segment) => {
893
+ const words = segment.words.filter((word) => zeroTimestamp + word.start * 1e3 >= lastUsedTimestamp);
894
+ return {
895
+ ...segment,
896
+ words,
897
+ text: words.map((word) => word.word).join(""),
898
+ start: words.at(0)?.start ?? segment.end
899
+ };
900
+ }).filter((segment) => segment.words.length > 0);
901
+ if (filteredSegments.length === 0) {
902
+ return {
903
+ transcripts: []
904
+ };
905
+ }
906
+ return {
907
+ transcripts: filteredSegments.map((segment) => ({
908
+ _tag: "transcript",
909
+ started: new Date(zeroTimestamp + segment.start * 1e3).toISOString(),
910
+ text: segment.text.trim()
911
+ })),
912
+ lastUsedTimestamp: zeroTimestamp + filteredSegments.at(-1).end * 1e3
913
+ };
914
+ };
915
+
916
+ // src/transcriber/transcription-manager.ts
917
+ import { Atom } from "@effect-atom/atom-react";
918
+ import { synchronized as synchronized2 } from "@dxos/async";
919
+ import { Resource as Resource2 } from "@dxos/context";
920
+ import { Obj } from "@dxos/echo";
921
+ import { Message } from "@dxos/types";
922
+ function _ts_decorate3(decorators, target, key, desc) {
923
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
924
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
925
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
926
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
927
+ }
928
+ var RECORD_INTERVAL = 200;
929
+ var PREFIXED_CHUNKS_AMOUNT = 10;
930
+ var TRANSCRIBE_AFTER_CHUNKS_AMOUNT = 50;
931
+ var TranscriptionManager = class extends Resource2 {
932
+ _edgeClient;
933
+ _messageEnricher;
934
+ _registry;
935
+ _audioStreamTrack = void 0;
936
+ _identityDid = void 0;
937
+ _mediaRecorder = void 0;
938
+ _transcriber = void 0;
939
+ _queue = void 0;
940
+ _enabledAtom = Atom.make(false);
941
+ constructor(options) {
942
+ super();
943
+ this._edgeClient = options.edgeClient;
944
+ this._messageEnricher = options.messageEnricher;
945
+ this._registry = options.registry;
946
+ }
947
+ get enabled() {
948
+ return this._enabledAtom;
949
+ }
950
+ getEnabled() {
951
+ return this._registry.get(this._enabledAtom);
952
+ }
953
+ setQueue(queue) {
954
+ this._queue = queue;
955
+ return this;
956
+ }
957
+ setIdentityDid(did) {
958
+ if (this._identityDid !== did) {
959
+ this._identityDid = did;
960
+ }
961
+ return this;
962
+ }
963
+ setRecording(recording) {
964
+ if (!this.isOpen || !this.getEnabled()) {
965
+ return this;
966
+ }
967
+ if (recording) {
968
+ this._transcriber?.startChunksRecording();
969
+ } else {
970
+ this._transcriber?.stopChunksRecording();
971
+ }
972
+ return this;
973
+ }
974
+ async setEnabled(enabled) {
975
+ if (this.getEnabled() === enabled) {
976
+ return;
977
+ }
978
+ this._registry.set(this._enabledAtom, enabled ?? false);
979
+ if (enabled) {
980
+ await this._maybeRestartTranscriber();
981
+ } else {
982
+ await this._stopTranscriber();
983
+ }
984
+ }
985
+ async setAudioTrack(track) {
986
+ if (this._audioStreamTrack === track) {
987
+ return;
988
+ }
989
+ this._audioStreamTrack = track;
990
+ await this._maybeRestartTranscriber();
991
+ }
992
+ async _open() {
993
+ await this._maybeRestartTranscriber();
994
+ }
995
+ async _close() {
996
+ await this._stopTranscriber();
997
+ }
998
+ async _maybeRestartTranscriber() {
999
+ if (!this._audioStreamTrack || !this.getEnabled() || !this.isOpen) {
1000
+ return;
1001
+ }
1002
+ let needReinit = false;
1003
+ if (this._audioStreamTrack !== this._mediaRecorder?.mediaStreamTrack) {
1004
+ this._mediaRecorder = new MediaStreamRecorder({
1005
+ mediaStreamTrack: this._audioStreamTrack,
1006
+ config: {
1007
+ interval: RECORD_INTERVAL
1008
+ }
1009
+ });
1010
+ needReinit = true;
1011
+ }
1012
+ if (needReinit) {
1013
+ await this._transcriber?.close();
1014
+ this._transcriber = new Transcriber({
1015
+ config: {
1016
+ transcribeAfterChunksAmount: TRANSCRIBE_AFTER_CHUNKS_AMOUNT,
1017
+ prefixBufferChunksAmount: PREFIXED_CHUNKS_AMOUNT
1018
+ },
1019
+ recorder: this._mediaRecorder,
1020
+ onSegments: (segments) => this._onSegments(segments)
1021
+ });
1022
+ await this._transcriber?.open();
1023
+ }
1024
+ }
1025
+ async _stopTranscriber() {
1026
+ await this._transcriber?.close();
1027
+ }
1028
+ async _onSegments(segments) {
1029
+ if (!this.isOpen || !this._queue) {
1030
+ return;
1031
+ }
1032
+ let block = Obj.make(Message.Message, {
1033
+ created: (/* @__PURE__ */ new Date()).toISOString(),
1034
+ blocks: segments,
1035
+ sender: {
1036
+ identityDid: this._identityDid
1037
+ }
1038
+ });
1039
+ if (this._messageEnricher) {
1040
+ block = await this._messageEnricher(block);
1041
+ }
1042
+ await this._queue.append([
1043
+ block
1044
+ ]);
1045
+ }
1046
+ };
1047
+ _ts_decorate3([
1048
+ synchronized2
1049
+ ], TranscriptionManager.prototype, "setAudioTrack", null);
1050
+
1051
+ // src/TranscriptionPlugin.tsx
1052
+ import * as Option from "effect/Option";
1053
+ import { Plugin } from "@dxos/app-framework";
1054
+ import { AppActivationEvents, AppPlugin } from "@dxos/app-toolkit";
1055
+ import { Annotation, Feed, Obj as Obj2 } from "@dxos/echo";
1056
+ import { getSpace } from "@dxos/react-client/echo";
1057
+ import { Message as Message2, Transcript } from "@dxos/types";
1058
+ import { BlueprintDefinition, OperationHandler, ReactSurface, Transcriber as Transcriber2 } from "#capabilities";
1059
+ import { meta as meta2 } from "#meta";
1060
+ import { translations } from "#translations";
1061
+ var TranscriptionPlugin = Plugin.define(meta2).pipe(AppPlugin.addBlueprintDefinitionModule({
1062
+ activate: BlueprintDefinition
1063
+ }), AppPlugin.addMetadataModule({
1064
+ metadata: {
1065
+ id: Transcript.Transcript.typename,
1066
+ metadata: {
1067
+ icon: Annotation.IconAnnotation.get(Transcript.Transcript).pipe(Option.getOrThrow).icon,
1068
+ iconHue: Annotation.IconAnnotation.get(Transcript.Transcript).pipe(Option.getOrThrow).hue ?? "white",
1069
+ // TODO(wittjosiah): Factor out. Artifact? Separate capability?
1070
+ getTextContent: async (transcript) => {
1071
+ const space = getSpace(transcript);
1072
+ const members = space?.members.get().map((member) => member.identity) ?? [];
1073
+ const feed = await transcript.feed.load();
1074
+ const queueDxn = Feed.getQueueDxn(feed);
1075
+ const queue = queueDxn ? space?.queues.get(queueDxn) : void 0;
1076
+ await queue?.refresh();
1077
+ const content = queue?.objects.filter((message) => Obj2.instanceOf(Message2.Message, message)).flatMap((message, index) => renderByline(members)(message, index)).join("\n\n");
1078
+ return content;
1079
+ }
1080
+ }
1081
+ }
1082
+ }), AppPlugin.addOperationHandlerModule({
1083
+ activate: OperationHandler
1084
+ }), AppPlugin.addSchemaModule({
1085
+ schema: [
1086
+ Transcript.Transcript
1087
+ ]
1088
+ }), AppPlugin.addSurfaceModule({
1089
+ activate: ReactSurface
1090
+ }), AppPlugin.addTranslationsModule({
1091
+ translations
1092
+ }), Plugin.addModule({
1093
+ id: "transcription",
1094
+ activatesOn: AppActivationEvents.SetupAppGraph,
1095
+ activate: Transcriber2
1096
+ }), Plugin.make);
108
1097
  export {
109
1098
  MediaStreamRecorder,
110
- TRANSCRIPTION_PLUGIN,
111
1099
  Transcriber,
112
- Transcript,
113
- TranscriptContainer,
1100
+ Transcription,
114
1101
  TranscriptionCapabilities,
115
- TranscriptionContainer,
116
1102
  TranscriptionManager,
117
1103
  TranscriptionPlugin,
1104
+ alignWhisperSegments,
118
1105
  meta,
119
- renderMarkdown,
1106
+ renderByline,
120
1107
  useAudioFile,
121
1108
  useAudioTrack,
122
1109
  useQueueModelAdapter,