@dxos/plugin-transcription 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f

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 (243) hide show
  1. package/dist/lib/browser/TranscriptContainer-PFKLKRPQ.mjs +11 -0
  2. package/dist/lib/browser/{chunk-3TKXI6TQ.mjs → chunk-4KCUYW2F.mjs} +43 -26
  3. package/dist/lib/browser/chunk-4KCUYW2F.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-6ZR5MDK3.mjs → chunk-GOF7MJNV.mjs} +3 -3
  5. package/dist/lib/browser/{chunk-6ZR5MDK3.mjs.map → chunk-GOF7MJNV.mjs.map} +1 -1
  6. package/dist/lib/browser/chunk-IGEKO7ZU.mjs +8 -0
  7. package/dist/lib/browser/chunk-IGEKO7ZU.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-JHWEZRWC.mjs → chunk-NODIXNQP.mjs} +6 -15
  9. package/dist/lib/browser/chunk-NODIXNQP.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-K2LS2QOM.mjs → chunk-TJPJBE45.mjs} +136 -92
  11. package/dist/lib/browser/chunk-TJPJBE45.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-LTIQFX4W.mjs → chunk-W2KNYJD6.mjs} +4 -4
  13. package/dist/lib/browser/chunk-W2KNYJD6.mjs.map +7 -0
  14. package/dist/lib/browser/index.mjs +8 -31
  15. package/dist/lib/browser/index.mjs.map +3 -3
  16. package/dist/lib/browser/{intent-resolver-DZ62CJPC.mjs → intent-resolver-I2LJSQDR.mjs} +4 -8
  17. package/dist/lib/browser/intent-resolver-I2LJSQDR.mjs.map +7 -0
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/react-surface-ID2MLJHZ.mjs +34 -0
  20. package/dist/lib/browser/react-surface-ID2MLJHZ.mjs.map +7 -0
  21. package/dist/lib/browser/transcriber-NA7CIFIT.mjs +56 -0
  22. package/dist/lib/browser/transcriber-NA7CIFIT.mjs.map +7 -0
  23. package/dist/lib/browser/types/index.mjs +4 -8
  24. package/dist/lib/node/{TranscriptContainer-SSJVLRM6.cjs → TranscriptContainer-LHMC7553.cjs} +9 -9
  25. package/dist/lib/node/{TranscriptContainer-SSJVLRM6.cjs.map → TranscriptContainer-LHMC7553.cjs.map} +2 -2
  26. package/dist/lib/node/{chunk-EVE3H46F.cjs → chunk-3GS5UNO5.cjs} +141 -100
  27. package/dist/lib/node/chunk-3GS5UNO5.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-L27AK6FQ.cjs → chunk-5J3FBCON.cjs} +8 -23
  29. package/dist/lib/node/chunk-5J3FBCON.cjs.map +7 -0
  30. package/dist/lib/node/{chunk-NVZWGFJL.cjs → chunk-AFUZI63A.cjs} +6 -6
  31. package/dist/lib/node/{chunk-NVZWGFJL.cjs.map → chunk-AFUZI63A.cjs.map} +1 -1
  32. package/dist/lib/node/{chunk-EJWB53WK.cjs → chunk-EIMUQYCZ.cjs} +10 -21
  33. package/dist/lib/node/chunk-EIMUQYCZ.cjs.map +7 -0
  34. package/dist/lib/node/{chunk-JUGOXWES.cjs → chunk-FKDJNJ57.cjs} +8 -8
  35. package/dist/lib/node/chunk-FKDJNJ57.cjs.map +7 -0
  36. package/dist/lib/node/{chunk-WKZLGVEJ.cjs → chunk-ZFTXJZXH.cjs} +44 -29
  37. package/dist/lib/node/chunk-ZFTXJZXH.cjs.map +7 -0
  38. package/dist/lib/node/index.cjs +36 -56
  39. package/dist/lib/node/index.cjs.map +3 -3
  40. package/dist/lib/node/{intent-resolver-TRBKI24D.cjs → intent-resolver-LLMGF5I5.cjs} +9 -11
  41. package/dist/lib/node/intent-resolver-LLMGF5I5.cjs.map +7 -0
  42. package/dist/lib/node/meta.json +1 -1
  43. package/dist/lib/node/{react-surface-SZAMHCX7.cjs → react-surface-SEQLEL4K.cjs} +13 -21
  44. package/dist/lib/node/react-surface-SEQLEL4K.cjs.map +7 -0
  45. package/dist/lib/node/transcriber-RKKN7LDU.cjs +68 -0
  46. package/dist/lib/node/transcriber-RKKN7LDU.cjs.map +7 -0
  47. package/dist/lib/node/types/index.cjs +7 -11
  48. package/dist/lib/node/types/index.cjs.map +2 -2
  49. package/dist/lib/node-esm/{TranscriptContainer-M53LI2TX.mjs → TranscriptContainer-DLNRFVTA.mjs} +4 -4
  50. package/dist/lib/node-esm/{chunk-QYG2FOXA.mjs → chunk-BRPFVRAD.mjs} +6 -15
  51. package/dist/lib/node-esm/chunk-BRPFVRAD.mjs.map +7 -0
  52. package/dist/lib/node-esm/{chunk-V5IWBPYO.mjs → chunk-EFIWBQDF.mjs} +43 -26
  53. package/dist/lib/node-esm/chunk-EFIWBQDF.mjs.map +7 -0
  54. package/dist/lib/node-esm/chunk-KUWWHMOA.mjs +10 -0
  55. package/dist/lib/node-esm/chunk-KUWWHMOA.mjs.map +7 -0
  56. package/dist/lib/node-esm/{chunk-5E2MR5XK.mjs → chunk-MFJPEIVB.mjs} +4 -4
  57. package/dist/lib/node-esm/chunk-MFJPEIVB.mjs.map +7 -0
  58. package/dist/lib/node-esm/{chunk-4KC3E5T4.mjs → chunk-PR7EYODX.mjs} +136 -92
  59. package/dist/lib/node-esm/chunk-PR7EYODX.mjs.map +7 -0
  60. package/dist/lib/node-esm/{chunk-X4DDJIVL.mjs → chunk-TXMDLLBR.mjs} +3 -3
  61. package/dist/lib/node-esm/{chunk-X4DDJIVL.mjs.map → chunk-TXMDLLBR.mjs.map} +1 -1
  62. package/dist/lib/node-esm/index.mjs +8 -31
  63. package/dist/lib/node-esm/index.mjs.map +3 -3
  64. package/dist/lib/node-esm/{intent-resolver-HFVAL274.mjs → intent-resolver-WOZKOEBW.mjs} +4 -8
  65. package/dist/lib/node-esm/intent-resolver-WOZKOEBW.mjs.map +7 -0
  66. package/dist/lib/node-esm/meta.json +1 -1
  67. package/dist/lib/node-esm/{react-surface-UEJELL7I.mjs → react-surface-7MXUUTAL.mjs} +9 -19
  68. package/dist/lib/node-esm/react-surface-7MXUUTAL.mjs.map +7 -0
  69. package/dist/lib/node-esm/transcriber-5WSI6DYK.mjs +57 -0
  70. package/dist/lib/node-esm/transcriber-5WSI6DYK.mjs.map +7 -0
  71. package/dist/lib/node-esm/types/index.mjs +4 -8
  72. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  73. package/dist/types/src/capabilities/capabilities.d.ts +8 -8
  74. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  75. package/dist/types/src/capabilities/index.d.ts +1 -4
  76. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  77. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  78. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  79. package/dist/types/src/capabilities/transcriber.d.ts +2 -1
  80. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  81. package/dist/types/src/components/index.d.ts +0 -1
  82. package/dist/types/src/components/index.d.ts.map +1 -1
  83. package/dist/types/src/components/stories/FileTranscription.stories.d.ts +17 -0
  84. package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -0
  85. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +10 -0
  86. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -0
  87. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +19 -0
  88. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -0
  89. package/dist/types/src/components/stories/TranscriptionStory.d.ts +11 -0
  90. package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -0
  91. package/dist/types/src/components/stories/useIsSpeaking.d.ts +3 -0
  92. package/dist/types/src/components/stories/useIsSpeaking.d.ts.map +1 -0
  93. package/dist/types/src/hooks/useAudioFile.d.ts +1 -1
  94. package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
  95. package/dist/types/src/hooks/useAudioTrack.d.ts +1 -1
  96. package/dist/types/src/hooks/useAudioTrack.d.ts.map +1 -1
  97. package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +1 -1
  98. package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
  99. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  100. package/dist/types/src/model/model.d.ts.map +1 -1
  101. package/dist/types/src/segments-normalization/index.d.ts +4 -0
  102. package/dist/types/src/segments-normalization/index.d.ts.map +1 -0
  103. package/dist/types/src/segments-normalization/message-normalizer.d.ts +26 -0
  104. package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -0
  105. package/dist/types/src/segments-normalization/normalization.d.ts +520 -0
  106. package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -0
  107. package/dist/types/src/segments-normalization/normalization.test.d.ts +2 -0
  108. package/dist/types/src/segments-normalization/normalization.test.d.ts.map +1 -0
  109. package/dist/types/src/segments-normalization/utils.d.ts +3 -0
  110. package/dist/types/src/segments-normalization/utils.d.ts.map +1 -0
  111. package/dist/types/src/testing/testing.d.ts.map +1 -1
  112. package/dist/types/src/transcriber/media-stream-recorder.d.ts +8 -5
  113. package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
  114. package/dist/types/src/transcriber/transcriber.d.ts +4 -0
  115. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  116. package/dist/types/src/transcriber/transcription-manager.d.ts +2 -0
  117. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  118. package/dist/types/src/translations.d.ts +0 -2
  119. package/dist/types/src/translations.d.ts.map +1 -1
  120. package/dist/types/src/types/schema.d.ts +0 -3
  121. package/dist/types/src/types/schema.d.ts.map +1 -1
  122. package/dist/types/src/types/types.d.ts +1 -5
  123. package/dist/types/src/types/types.d.ts.map +1 -1
  124. package/package.json +54 -50
  125. package/src/TranscriptionPlugin.tsx +2 -24
  126. package/src/capabilities/capabilities.ts +15 -9
  127. package/src/capabilities/index.ts +0 -3
  128. package/src/capabilities/intent-resolver.ts +0 -2
  129. package/src/capabilities/react-surface.tsx +4 -11
  130. package/src/capabilities/transcriber.ts +34 -7
  131. package/src/components/Transcript/deprecated/OldTranscript.tsx +1 -1
  132. package/src/components/Transcript/transcript-extension.ts +2 -2
  133. package/src/components/index.ts +0 -1
  134. package/src/components/stories/FileTranscription.stories.tsx +240 -0
  135. package/src/components/stories/KeyWordRecognition.stories.tsx +128 -0
  136. package/src/components/stories/MicrophoneTranscription.stories.tsx +274 -0
  137. package/src/components/stories/TranscriptionStory.tsx +41 -0
  138. package/src/components/stories/useIsSpeaking.tsx +40 -0
  139. package/src/hooks/useAudioFile.ts +39 -9
  140. package/src/hooks/useAudioTrack.ts +2 -2
  141. package/src/hooks/useQueueModelAdapter.ts +7 -5
  142. package/src/hooks/useTranscriber.ts +4 -3
  143. package/src/meta.ts +2 -2
  144. package/src/model/model.ts +1 -1
  145. package/src/segments-normalization/index.ts +7 -0
  146. package/src/segments-normalization/message-normalizer.ts +108 -0
  147. package/src/segments-normalization/normalization.test.ts +142 -0
  148. package/src/segments-normalization/normalization.ts +103 -0
  149. package/src/segments-normalization/utils.ts +9 -0
  150. package/src/testing/testing.ts +17 -17
  151. package/src/transcriber/media-stream-recorder.ts +14 -7
  152. package/src/transcriber/transcriber.browser.test.ts +4 -4
  153. package/src/transcriber/transcriber.ts +13 -9
  154. package/src/transcriber/transcription-manager.ts +21 -14
  155. package/src/translations.ts +0 -3
  156. package/src/types/schema.ts +1 -2
  157. package/src/types/types.ts +1 -15
  158. package/dist/lib/browser/TranscriptContainer-CXA4ZBHW.mjs +0 -11
  159. package/dist/lib/browser/app-graph-builder-REQZ5SC5.mjs +0 -351
  160. package/dist/lib/browser/app-graph-builder-REQZ5SC5.mjs.map +0 -7
  161. package/dist/lib/browser/chunk-3TKXI6TQ.mjs.map +0 -7
  162. package/dist/lib/browser/chunk-JHWEZRWC.mjs.map +0 -7
  163. package/dist/lib/browser/chunk-K2LS2QOM.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-KLD7O5GJ.mjs +0 -25
  165. package/dist/lib/browser/chunk-KLD7O5GJ.mjs.map +0 -7
  166. package/dist/lib/browser/chunk-LCTMCTYY.mjs +0 -27
  167. package/dist/lib/browser/chunk-LCTMCTYY.mjs.map +0 -7
  168. package/dist/lib/browser/chunk-LTIQFX4W.mjs.map +0 -7
  169. package/dist/lib/browser/intent-resolver-DZ62CJPC.mjs.map +0 -7
  170. package/dist/lib/browser/meeting-transcription-state-MNA2XROE.mjs +0 -18
  171. package/dist/lib/browser/meeting-transcription-state-MNA2XROE.mjs.map +0 -7
  172. package/dist/lib/browser/react-surface-PUXZNAZL.mjs +0 -44
  173. package/dist/lib/browser/react-surface-PUXZNAZL.mjs.map +0 -7
  174. package/dist/lib/browser/settings-JWDS4J3F.mjs +0 -24
  175. package/dist/lib/browser/settings-JWDS4J3F.mjs.map +0 -7
  176. package/dist/lib/browser/transcriber-YWWIV6KP.mjs +0 -37
  177. package/dist/lib/browser/transcriber-YWWIV6KP.mjs.map +0 -7
  178. package/dist/lib/node/app-graph-builder-OAPU4GDH.cjs +0 -352
  179. package/dist/lib/node/app-graph-builder-OAPU4GDH.cjs.map +0 -7
  180. package/dist/lib/node/chunk-EJWB53WK.cjs.map +0 -7
  181. package/dist/lib/node/chunk-EVE3H46F.cjs.map +0 -7
  182. package/dist/lib/node/chunk-J72PUQ3C.cjs +0 -46
  183. package/dist/lib/node/chunk-J72PUQ3C.cjs.map +0 -7
  184. package/dist/lib/node/chunk-JUGOXWES.cjs.map +0 -7
  185. package/dist/lib/node/chunk-L27AK6FQ.cjs.map +0 -7
  186. package/dist/lib/node/chunk-WKZLGVEJ.cjs.map +0 -7
  187. package/dist/lib/node/intent-resolver-TRBKI24D.cjs.map +0 -7
  188. package/dist/lib/node/meeting-transcription-state-5XLTMWPA.cjs +0 -34
  189. package/dist/lib/node/meeting-transcription-state-5XLTMWPA.cjs.map +0 -7
  190. package/dist/lib/node/react-surface-SZAMHCX7.cjs.map +0 -7
  191. package/dist/lib/node/settings-AWWMOSCV.cjs +0 -38
  192. package/dist/lib/node/settings-AWWMOSCV.cjs.map +0 -7
  193. package/dist/lib/node/transcriber-AFUXFHCR.cjs +0 -50
  194. package/dist/lib/node/transcriber-AFUXFHCR.cjs.map +0 -7
  195. package/dist/lib/node-esm/app-graph-builder-UBP6EOBR.mjs +0 -352
  196. package/dist/lib/node-esm/app-graph-builder-UBP6EOBR.mjs.map +0 -7
  197. package/dist/lib/node-esm/chunk-4KC3E5T4.mjs.map +0 -7
  198. package/dist/lib/node-esm/chunk-5E2MR5XK.mjs.map +0 -7
  199. package/dist/lib/node-esm/chunk-MHQP2PAF.mjs +0 -28
  200. package/dist/lib/node-esm/chunk-MHQP2PAF.mjs.map +0 -7
  201. package/dist/lib/node-esm/chunk-QMHMEKB3.mjs +0 -27
  202. package/dist/lib/node-esm/chunk-QMHMEKB3.mjs.map +0 -7
  203. package/dist/lib/node-esm/chunk-QYG2FOXA.mjs.map +0 -7
  204. package/dist/lib/node-esm/chunk-V5IWBPYO.mjs.map +0 -7
  205. package/dist/lib/node-esm/intent-resolver-HFVAL274.mjs.map +0 -7
  206. package/dist/lib/node-esm/meeting-transcription-state-3WOZ52BQ.mjs +0 -19
  207. package/dist/lib/node-esm/meeting-transcription-state-3WOZ52BQ.mjs.map +0 -7
  208. package/dist/lib/node-esm/react-surface-UEJELL7I.mjs.map +0 -7
  209. package/dist/lib/node-esm/settings-QFNFGFJ5.mjs +0 -25
  210. package/dist/lib/node-esm/settings-QFNFGFJ5.mjs.map +0 -7
  211. package/dist/lib/node-esm/transcriber-7RJEFPDI.mjs +0 -38
  212. package/dist/lib/node-esm/transcriber-7RJEFPDI.mjs.map +0 -7
  213. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  214. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  215. package/dist/types/src/capabilities/meeting-transcription-state.d.ts +0 -4
  216. package/dist/types/src/capabilities/meeting-transcription-state.d.ts.map +0 -1
  217. package/dist/types/src/capabilities/settings.d.ts +0 -4
  218. package/dist/types/src/capabilities/settings.d.ts.map +0 -1
  219. package/dist/types/src/components/TranscriptionSettings/TranscriptionSettings.d.ts +0 -6
  220. package/dist/types/src/components/TranscriptionSettings/TranscriptionSettings.d.ts.map +0 -1
  221. package/dist/types/src/components/TranscriptionSettings/index.d.ts +0 -2
  222. package/dist/types/src/components/TranscriptionSettings/index.d.ts.map +0 -1
  223. package/dist/types/src/components/transcription.stories.d.ts +0 -18
  224. package/dist/types/src/components/transcription.stories.d.ts.map +0 -1
  225. package/dist/types/src/entity-extraction/entity-extraction.d.ts +0 -42
  226. package/dist/types/src/entity-extraction/entity-extraction.d.ts.map +0 -1
  227. package/dist/types/src/entity-extraction/entity-extraction.test.d.ts +0 -2
  228. package/dist/types/src/entity-extraction/entity-extraction.test.d.ts.map +0 -1
  229. package/dist/types/src/entity-extraction/index.d.ts +0 -2
  230. package/dist/types/src/entity-extraction/index.d.ts.map +0 -1
  231. package/src/capabilities/app-graph-builder.ts +0 -233
  232. package/src/capabilities/meeting-transcription-state.ts +0 -16
  233. package/src/capabilities/settings.ts +0 -20
  234. package/src/components/TranscriptionSettings/TranscriptionSettings.tsx +0 -26
  235. package/src/components/TranscriptionSettings/index.ts +0 -5
  236. package/src/components/transcription.stories.tsx +0 -295
  237. package/src/entity-extraction/entity-extraction.test.ts +0 -97
  238. package/src/entity-extraction/entity-extraction.ts +0 -149
  239. package/src/entity-extraction/index.ts +0 -5
  240. package/src/entity-extraction/system-prompt.tpl +0 -38
  241. package/src/entity-extraction/types.d.ts +0 -8
  242. /package/dist/lib/browser/{TranscriptContainer-CXA4ZBHW.mjs.map → TranscriptContainer-PFKLKRPQ.mjs.map} +0 -0
  243. /package/dist/lib/node-esm/{TranscriptContainer-M53LI2TX.mjs.map → TranscriptContainer-DLNRFVTA.mjs.map} +0 -0
@@ -0,0 +1,240 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
+
10
+ import { AIServiceEdgeClient } from '@dxos/ai';
11
+ import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
12
+ import { Events, IntentPlugin, SettingsPlugin } from '@dxos/app-framework';
13
+ import { withPluginManager } from '@dxos/app-framework/testing';
14
+ import { scheduleTask } from '@dxos/async';
15
+ import { Context } from '@dxos/context';
16
+ import { MemoryQueue } from '@dxos/echo-db';
17
+ import { create, createQueueDxn } from '@dxos/echo-schema';
18
+ import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
19
+ import { log } from '@dxos/log';
20
+ import { ClientPlugin } from '@dxos/plugin-client';
21
+ import { PreviewPlugin } from '@dxos/plugin-preview';
22
+ import { SpacePlugin } from '@dxos/plugin-space';
23
+ import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
24
+ import { ThemePlugin } from '@dxos/plugin-theme';
25
+ import { defaultTx } from '@dxos/react-ui-theme';
26
+ import { DataType } from '@dxos/schema';
27
+ import { seedTestData, Testing } from '@dxos/schema/testing';
28
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
29
+
30
+ import { TranscriptionStory } from './TranscriptionStory';
31
+ import { useIsSpeaking } from './useIsSpeaking';
32
+ import { TranscriptionPlugin } from '../../TranscriptionPlugin';
33
+ import { useAudioFile, useQueueModelAdapter, useTranscriber } from '../../hooks';
34
+ import { getActorId, MessageNormalizer } from '../../segments-normalization';
35
+ import { TestItem } from '../../testing';
36
+ import { type MediaStreamRecorderParams, type TranscriberParams } from '../../transcriber';
37
+ import { renderMarkdown } from '../Transcript';
38
+
39
+ const AudioFile = ({
40
+ detectSpeaking,
41
+ audioUrl,
42
+ normalizeSentences,
43
+ transcriberConfig,
44
+ recorderConfig,
45
+ audioConstraints,
46
+ }: {
47
+ detectSpeaking?: boolean;
48
+ normalizeSentences?: boolean;
49
+ audioUrl: string;
50
+ transcriberConfig?: TranscriberParams['config'];
51
+ recorderConfig?: MediaStreamRecorderParams['config'];
52
+ audioConstraints?: MediaTrackConstraints;
53
+ }) => {
54
+ const [running, setRunning] = useState(false);
55
+ const actor: DataType.Actor = useMemo(() => ({ name: 'You' }), []);
56
+
57
+ // Audio.
58
+ const { audio, track, stream } = useAudioFile(audioUrl, audioConstraints);
59
+
60
+ // Speaking.
61
+ const isSpeaking = detectSpeaking ? useIsSpeaking(track) : true;
62
+ const ref = useRef<HTMLAudioElement>(null);
63
+ useEffect(() => {
64
+ if (ref.current && stream) {
65
+ ref.current.srcObject = stream;
66
+ }
67
+ }, [stream]);
68
+
69
+ useEffect(() => {
70
+ if (!audio) {
71
+ log.warn('no audio');
72
+ return;
73
+ }
74
+
75
+ if (running) {
76
+ void audio.play();
77
+ } else {
78
+ void audio.pause();
79
+ }
80
+ }, [audio, running]);
81
+
82
+ // Transcriber.
83
+ const queueDxn = useMemo(() => createQueueDxn(), []);
84
+ const queue = useMemo(() => new MemoryQueue<DataType.Message>(queueDxn), [queueDxn]);
85
+
86
+ const model = useQueueModelAdapter(renderMarkdown([]), queue);
87
+ const handleSegments = useCallback<TranscriberParams['onSegments']>(
88
+ async (blocks) => {
89
+ const message = create(DataType.Message, { sender: actor, created: new Date().toISOString(), blocks });
90
+ void queue?.append([message]);
91
+ },
92
+ [queue],
93
+ );
94
+
95
+ const transcriber = useTranscriber({
96
+ audioStreamTrack: track,
97
+ onSegments: handleSegments,
98
+ transcriberConfig,
99
+ recorderConfig,
100
+ });
101
+
102
+ // Normalize sentences.
103
+ const normalizer = useMemo(() => {
104
+ if (!normalizeSentences) {
105
+ return;
106
+ }
107
+ const executor = new FunctionExecutor(
108
+ new ServiceContainer().setServices({
109
+ ai: {
110
+ client: new AIServiceEdgeClient({
111
+ endpoint: AI_SERVICE_ENDPOINT.REMOTE,
112
+ defaultGenerationOptions: {
113
+ model: '@anthropic/claude-3-5-sonnet-20241022',
114
+ },
115
+ }),
116
+ },
117
+ }),
118
+ );
119
+
120
+ return new MessageNormalizer({
121
+ functionExecutor: executor,
122
+ queue,
123
+ startingCursor: { actorId: getActorId(actor), timestamp: new Date().toISOString() },
124
+ });
125
+ }, [normalizeSentences, queue, actor]);
126
+
127
+ useEffect(() => {
128
+ if (!normalizer) {
129
+ return;
130
+ }
131
+ const ctx = new Context();
132
+ scheduleTask(ctx, async () => {
133
+ await normalizer.open();
134
+ ctx.onDispose(async () => {
135
+ await normalizer.close();
136
+ });
137
+ });
138
+ return () => {
139
+ void ctx.dispose();
140
+ };
141
+ }, [normalizer]);
142
+
143
+ const manageChunkRecording = () => {
144
+ if (running && isSpeaking) {
145
+ log.info('starting transcription');
146
+ transcriber?.startChunksRecording();
147
+ } else if (!isSpeaking || !running) {
148
+ log.info('stopping transcription');
149
+ transcriber?.stopChunksRecording();
150
+ }
151
+ };
152
+
153
+ useEffect(() => {
154
+ const ctx = new Context();
155
+ scheduleTask(ctx, async () => {
156
+ if (transcriber && running) {
157
+ await transcriber.open();
158
+ } else if (!running) {
159
+ await transcriber?.close();
160
+ }
161
+ manageChunkRecording();
162
+ });
163
+
164
+ return () => {
165
+ void ctx.dispose();
166
+ };
167
+ }, [transcriber, running]);
168
+
169
+ useEffect(() => {
170
+ manageChunkRecording();
171
+ }, [isSpeaking, stream]);
172
+
173
+ return <TranscriptionStory model={model} running={running} onRunningChange={setRunning} audioRef={ref} />;
174
+ };
175
+
176
+ const meta: Meta<typeof AudioFile> = {
177
+ title: 'plugins/plugin-transcription/FileTranscription',
178
+ decorators: [
179
+ withPluginManager({
180
+ plugins: [
181
+ ThemePlugin({ tx: defaultTx }),
182
+ StorybookLayoutPlugin(),
183
+ ClientPlugin({
184
+ types: [TestItem, DataType.Person, DataType.Organization, Testing.DocumentType],
185
+ onClientInitialized: async (_, client) => {
186
+ await client.halo.createIdentity();
187
+ await client.spaces.waitUntilReady();
188
+ await client.spaces.default.waitUntilReady();
189
+ await seedTestData(client.spaces.default);
190
+ },
191
+ }),
192
+ SpacePlugin(),
193
+ SettingsPlugin(),
194
+ PreviewPlugin(),
195
+ IntentPlugin(),
196
+ TranscriptionPlugin(),
197
+ ],
198
+ fireEvents: [Events.SetupAppGraph],
199
+ }),
200
+ withTheme,
201
+ withLayout({ fullscreen: true, classNames: 'justify-center' }),
202
+ ],
203
+ };
204
+
205
+ export default meta;
206
+
207
+ const TRANSCRIBER_CONFIG = {
208
+ transcribeAfterChunksAmount: 100,
209
+ prefixBufferChunksAmount: 50,
210
+ normalizeSentences: true,
211
+ };
212
+
213
+ const RECORDER_CONFIG = {
214
+ interval: 200,
215
+ };
216
+
217
+ export const Default: StoryObj<typeof AudioFile> = {
218
+ render: AudioFile,
219
+ args: {
220
+ detectSpeaking: true,
221
+ // https://learnenglish.britishcouncil.org/general-english/audio-zone/living-london
222
+ audioUrl: 'https://dxos.network/audio-london.m4a',
223
+ // textUrl: 'https://dxos.network/audio-london.txt',
224
+ transcriberConfig: TRANSCRIBER_CONFIG,
225
+ recorderConfig: RECORDER_CONFIG,
226
+ },
227
+ };
228
+
229
+ export const WithSentenceNormalization: StoryObj<typeof AudioFile> = {
230
+ render: AudioFile,
231
+ args: {
232
+ detectSpeaking: true,
233
+ normalizeSentences: true,
234
+ // https://learnenglish.britishcouncil.org/general-english/audio-zone/living-london
235
+ audioUrl: 'https://dxos.network/audio-london.m4a',
236
+ // textUrl: 'https://dxos.network/audio-london.txt',
237
+ transcriberConfig: TRANSCRIBER_CONFIG,
238
+ recorderConfig: RECORDER_CONFIG,
239
+ },
240
+ };
@@ -0,0 +1,128 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type StoryObj, type Meta } from '@storybook/react';
8
+ import React, { useEffect, useMemo, useState } from 'react';
9
+
10
+ import { log } from '@dxos/log';
11
+ import { Toolbar } from '@dxos/react-ui';
12
+ import { mx } from '@dxos/react-ui-theme';
13
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
14
+
15
+ type Word = {
16
+ text: string;
17
+ matched: boolean;
18
+ };
19
+
20
+ const SpeechRecognition = ({ keywords }: { keywords: string[] }) => {
21
+ const [running, setRunning] = useState(false);
22
+ const [matchingWords, setMatchingWords] = useState<Word[]>(keywords.map((word) => ({ text: word, matched: false })));
23
+
24
+ const [transcript, setTranscript] = useState('');
25
+ const recognition = useMemo(() => {
26
+ // TODO(mykola): Fix types
27
+ const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
28
+ const SpeechGrammarList = (window as any).SpeechGrammarList || (window as any).webkitSpeechGrammarList;
29
+ if (!SpeechRecognition || !SpeechGrammarList) {
30
+ log.error('Speech recognition not supported in this browser');
31
+ return;
32
+ }
33
+
34
+ const recognition = new SpeechRecognition();
35
+ recognition.continuous = true;
36
+ recognition.interimResults = true;
37
+ recognition.lang = 'en-US';
38
+ recognition.maxAlternatives = 1;
39
+ // Add this line to enable punctuation
40
+ recognition.grammars = new SpeechGrammarList();
41
+
42
+ // TODO(mykola): Fix types
43
+ recognition.onresult = (event: any) => {
44
+ log.info('recognition result', { event });
45
+ const current = event.resultIndex;
46
+ const transcript = event.results[current][0].transcript;
47
+
48
+ // Remove punctuation and normalize whitespace for comparison
49
+ const normalizeText = (text: string) =>
50
+ text
51
+ .toLowerCase()
52
+ .replace(/[.,!?]/g, '')
53
+ .replace(/\s+/g, ' ')
54
+ .trim();
55
+
56
+ const normalizedTranscript = normalizeText(transcript);
57
+
58
+ // Check each keyword and update matching words
59
+ const updatedWords = matchingWords.map((word) => {
60
+ const normalizedKeyword = normalizeText(word.text);
61
+ const matched = normalizedTranscript.includes(normalizedKeyword);
62
+ return { ...word, matched };
63
+ });
64
+
65
+ setMatchingWords(updatedWords);
66
+ setTranscript(transcript);
67
+ };
68
+
69
+ // TODO(mykola): Fix types
70
+ recognition.onerror = (event: any) => {
71
+ log.error('Speech recognition error:', { error: event.error });
72
+ setRunning(false);
73
+ };
74
+
75
+ return recognition;
76
+ }, []);
77
+
78
+ useEffect(() => {
79
+ if (running) {
80
+ recognition?.start();
81
+ } else {
82
+ recognition?.stop();
83
+ }
84
+ }, [running, recognition]);
85
+
86
+ return (
87
+ <div className={mx('flex flex-col gap-2 w-[30rem]')}>
88
+ <Toolbar.Root>
89
+ <Toolbar.IconButton
90
+ iconOnly
91
+ icon={running ? 'ph--pause--regular' : 'ph--play--regular'}
92
+ label={running ? 'Pause' : 'Play'}
93
+ onClick={() => setRunning((running) => !running)}
94
+ />
95
+ </Toolbar.Root>
96
+
97
+ <div className='flex flex-wrap'>
98
+ {matchingWords.map((word, index) => (
99
+ <span
100
+ key={index}
101
+ className={mx(
102
+ 'px-3 py-1 m-2 rounded border',
103
+ word.matched ? 'bg-red-200 text-red-800 border-red-300' : 'bg-gray-200 text-gray-600 border-gray-300',
104
+ )}
105
+ >
106
+ {word.text}
107
+ </span>
108
+ ))}
109
+ </div>
110
+
111
+ <span>{transcript || (running ? 'Listening...' : 'Click play to start speech recognition')}</span>
112
+ </div>
113
+ );
114
+ };
115
+
116
+ const meta: Meta<typeof SpeechRecognition> = {
117
+ title: 'plugins/plugin-transcription/KeyWordDetection',
118
+ decorators: [withTheme, withLayout({ fullscreen: true, classNames: 'justify-center' })],
119
+ };
120
+
121
+ export default meta;
122
+
123
+ export const SpeechRecognitionAPI: StoryObj<typeof SpeechRecognition> = {
124
+ render: SpeechRecognition,
125
+ args: {
126
+ keywords: ['kai', 'computer', 'hello'],
127
+ },
128
+ };
@@ -0,0 +1,274 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
9
+
10
+ import { AIServiceEdgeClient } from '@dxos/ai';
11
+ import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
12
+ import { Events, IntentPlugin, SettingsPlugin } from '@dxos/app-framework';
13
+ import { withPluginManager } from '@dxos/app-framework/testing';
14
+ import {
15
+ extractionAnthropicFn,
16
+ type ExtractionFunction,
17
+ extractionNerFn,
18
+ processTranscriptMessage,
19
+ getNer,
20
+ } from '@dxos/assistant';
21
+ import { Filter, MemoryQueue } from '@dxos/echo-db';
22
+ import { create, createQueueDxn, type Expando } from '@dxos/echo-schema';
23
+ import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
24
+ import { invariant } from '@dxos/invariant';
25
+ import { log } from '@dxos/log';
26
+ import { ClientPlugin } from '@dxos/plugin-client';
27
+ import { PreviewPlugin } from '@dxos/plugin-preview';
28
+ import { SpacePlugin } from '@dxos/plugin-space';
29
+ import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
30
+ import { ThemePlugin } from '@dxos/plugin-theme';
31
+ import { IndexKind, useSpace } from '@dxos/react-client/echo';
32
+ import { defaultTx } from '@dxos/react-ui-theme';
33
+ import { DataType } from '@dxos/schema';
34
+ import { seedTestData, Testing } from '@dxos/schema/testing';
35
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
36
+
37
+ import { TranscriptionStory } from './TranscriptionStory';
38
+ import { useIsSpeaking } from './useIsSpeaking';
39
+ import { TranscriptionPlugin } from '../../TranscriptionPlugin';
40
+ import { useAudioTrack, useQueueModelAdapter, useTranscriber } from '../../hooks';
41
+ import { TestItem } from '../../testing';
42
+ import { type MediaStreamRecorderParams, type TranscriberParams } from '../../transcriber';
43
+ import { renderMarkdown } from '../Transcript';
44
+
45
+ const TRANSCRIBER_CONFIG = {
46
+ transcribeAfterChunksAmount: 50,
47
+ prefixBufferChunksAmount: 10,
48
+ };
49
+
50
+ const RECORDER_CONFIG = {
51
+ interval: 200,
52
+ };
53
+
54
+ type StoryProps = {
55
+ detectSpeaking?: boolean;
56
+ transcriberConfig: TranscriberParams['config'];
57
+ recorderConfig: MediaStreamRecorderParams['config'];
58
+ audioConstraints?: MediaTrackConstraints;
59
+ entityExtraction: 'none' | 'ner' | 'llm';
60
+ };
61
+
62
+ const DefaultStory = ({
63
+ detectSpeaking,
64
+ entityExtraction = 'none',
65
+ transcriberConfig,
66
+ recorderConfig,
67
+ audioConstraints,
68
+ }: StoryProps) => {
69
+ const [running, setRunning] = useState(false);
70
+
71
+ // Audio.
72
+ const track = useAudioTrack(running, audioConstraints);
73
+
74
+ // Speaking.
75
+ const isSpeaking = detectSpeaking ? useIsSpeaking(track) : true;
76
+
77
+ // Queue.
78
+ const queueDxn = useMemo(() => createQueueDxn(), []);
79
+ const queue = useMemo(() => new MemoryQueue<DataType.Message>(queueDxn), [queueDxn]);
80
+ const model = useQueueModelAdapter(renderMarkdown([]), queue);
81
+ const space = useSpace();
82
+
83
+ useEffect(() => {
84
+ if (!space) {
85
+ log.warn('no space');
86
+ }
87
+ }, [space]);
88
+
89
+ // Entity extraction.
90
+ const { extractionFunction, executor, objects } = useMemo(() => {
91
+ if (!space) {
92
+ log.warn('no space');
93
+ return {};
94
+ }
95
+
96
+ let executor: FunctionExecutor | undefined;
97
+ let extractionFunction: ExtractionFunction | undefined;
98
+ let objects: Promise<Expando[]> | undefined;
99
+
100
+ if (entityExtraction === 'ner') {
101
+ // Init model loading. Takes time.
102
+ void getNer();
103
+ extractionFunction = extractionNerFn;
104
+ } else if (entityExtraction === 'llm') {
105
+ extractionFunction = extractionAnthropicFn;
106
+ objects = space.db
107
+ .query(
108
+ Filter.or(
109
+ Filter.type(DataType.Person),
110
+ Filter.type(DataType.Organization),
111
+ Filter.type(Testing.DocumentType),
112
+ ),
113
+ )
114
+ .run()
115
+ .then((result) => result.objects);
116
+ }
117
+ if (entityExtraction !== 'none') {
118
+ const aiService = new AIServiceEdgeClient({
119
+ endpoint: AI_SERVICE_ENDPOINT.REMOTE,
120
+ });
121
+ executor = new FunctionExecutor(
122
+ new ServiceContainer().setServices({ ai: { client: aiService }, database: { db: space!.db } }),
123
+ );
124
+ }
125
+
126
+ return { extractionFunction, executor, objects };
127
+ }, [entityExtraction, space]);
128
+
129
+ // Transcriber.
130
+ const handleSegments = useCallback<TranscriberParams['onSegments']>(
131
+ async (blocks) => {
132
+ const message = create(DataType.Message, { sender: { name: 'You' }, created: new Date().toISOString(), blocks });
133
+ if (!space) {
134
+ void queue.append([message]);
135
+ return;
136
+ }
137
+
138
+ if (entityExtraction !== 'none') {
139
+ invariant(extractionFunction, 'extractionFunction is required');
140
+ invariant(executor, 'executor is required');
141
+ const result = await processTranscriptMessage({
142
+ executor,
143
+ function: extractionFunction,
144
+ input: {
145
+ message,
146
+ objects: await objects,
147
+ },
148
+ options: {
149
+ fallbackToRaw: true,
150
+ timeout: 30_000,
151
+ },
152
+ });
153
+ void queue.append([result.message]);
154
+ } else {
155
+ void queue.append([message]);
156
+ }
157
+ },
158
+ [queue, space],
159
+ );
160
+
161
+ const transcriber = useTranscriber({
162
+ audioStreamTrack: track,
163
+ onSegments: handleSegments,
164
+ transcriberConfig,
165
+ recorderConfig,
166
+ });
167
+ const [isOpen, setIsOpen] = useState(false);
168
+ useEffect(() => {
169
+ void transcriber?.open().then(() => setIsOpen(true));
170
+ return () => {
171
+ void transcriber?.close().then(() => setIsOpen(false));
172
+ };
173
+ }, [transcriber]);
174
+
175
+ // Manage transcription state.
176
+ useEffect(() => {
177
+ if (running && transcriber?.isOpen && isSpeaking) {
178
+ transcriber?.startChunksRecording();
179
+ } else if (!running || !isSpeaking) {
180
+ transcriber?.stopChunksRecording();
181
+ }
182
+ }, [transcriber, running, isOpen, isSpeaking]);
183
+
184
+ return <TranscriptionStory model={model} running={running} onRunningChange={setRunning} />;
185
+ };
186
+
187
+ const meta: Meta<typeof DefaultStory> = {
188
+ title: 'plugins/plugin-transcription/MicrophoneTranscription',
189
+ render: DefaultStory,
190
+ decorators: [
191
+ withPluginManager({
192
+ plugins: [
193
+ ThemePlugin({ tx: defaultTx }),
194
+ StorybookLayoutPlugin(),
195
+ ClientPlugin({
196
+ types: [TestItem, DataType.Person, DataType.Organization, Testing.DocumentType],
197
+ onClientInitialized: async (_, client) => {
198
+ await client.halo.createIdentity();
199
+ await client.spaces.waitUntilReady();
200
+ await client.spaces.default.waitUntilReady();
201
+ // TODO(mykola): Make API easier to use.
202
+ // TODO(mykola): Delete after enabling vector indexing by default.
203
+ // Enable vector indexing.
204
+ await client.services.services.QueryService!.setConfig({
205
+ enabled: true,
206
+ indexes: [
207
+ //
208
+ { kind: IndexKind.Kind.SCHEMA_MATCH },
209
+ { kind: IndexKind.Kind.GRAPH },
210
+ { kind: IndexKind.Kind.VECTOR },
211
+ ],
212
+ });
213
+ await client.services.services.QueryService!.reindex();
214
+ await seedTestData(client.spaces.default);
215
+ },
216
+ }),
217
+ SpacePlugin(),
218
+ SettingsPlugin(),
219
+ PreviewPlugin(),
220
+ IntentPlugin(),
221
+ TranscriptionPlugin(),
222
+ ],
223
+ fireEvents: [Events.SetupAppGraph],
224
+ }),
225
+ withTheme,
226
+ withLayout({ fullscreen: true, classNames: 'justify-center' }),
227
+ ],
228
+ };
229
+
230
+ export default meta;
231
+
232
+ type Story = StoryObj<typeof DefaultStory>;
233
+
234
+ export const Default: Story = {
235
+ args: {
236
+ detectSpeaking: false,
237
+ entityExtraction: 'none',
238
+ transcriberConfig: TRANSCRIBER_CONFIG,
239
+ recorderConfig: RECORDER_CONFIG,
240
+ audioConstraints: {
241
+ echoCancellation: false,
242
+ noiseSuppression: false,
243
+ autoGainControl: false,
244
+ },
245
+ },
246
+ };
247
+
248
+ export const EntityExtraction: Story = {
249
+ args: {
250
+ detectSpeaking: true,
251
+ entityExtraction: 'ner',
252
+ transcriberConfig: TRANSCRIBER_CONFIG,
253
+ recorderConfig: RECORDER_CONFIG,
254
+ audioConstraints: {
255
+ echoCancellation: true,
256
+ noiseSuppression: true,
257
+ autoGainControl: true,
258
+ },
259
+ },
260
+ };
261
+
262
+ export const SpeechDetection: Story = {
263
+ args: {
264
+ detectSpeaking: true,
265
+ entityExtraction: 'none',
266
+ transcriberConfig: TRANSCRIBER_CONFIG,
267
+ recorderConfig: RECORDER_CONFIG,
268
+ audioConstraints: {
269
+ echoCancellation: true,
270
+ noiseSuppression: true,
271
+ autoGainControl: true,
272
+ },
273
+ },
274
+ };
@@ -0,0 +1,41 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import React, { type Dispatch, type FC, type RefObject, type SetStateAction } from 'react';
8
+
9
+ import { useSpace } from '@dxos/react-client/echo';
10
+ import { IconButton, Toolbar } from '@dxos/react-ui';
11
+ import { ScrollContainer } from '@dxos/react-ui-components';
12
+ import { type DataType } from '@dxos/schema';
13
+
14
+ import { type SerializationModel } from '../../model';
15
+ import { Transcript } from '../Transcript';
16
+
17
+ export const TranscriptionStory: FC<{
18
+ model: SerializationModel<DataType.Message>;
19
+ running: boolean;
20
+ onRunningChange: Dispatch<SetStateAction<boolean>>;
21
+ audioRef?: RefObject<HTMLAudioElement>;
22
+ }> = ({ model, running, onRunningChange, audioRef }) => {
23
+ const space = useSpace();
24
+
25
+ return (
26
+ <div className='flex flex-col w-[30rem]'>
27
+ {audioRef && <audio ref={audioRef} autoPlay />}
28
+ <Toolbar.Root>
29
+ <IconButton
30
+ iconOnly
31
+ icon={running ? 'ph--pause--regular' : 'ph--play--regular'}
32
+ label={running ? 'Pause' : 'Play'}
33
+ onClick={() => onRunningChange((running) => !running)}
34
+ />
35
+ </Toolbar.Root>
36
+ <ScrollContainer>
37
+ <Transcript space={space} model={model} attendableId='story' />
38
+ </ScrollContainer>
39
+ </div>
40
+ );
41
+ };