@dxos/plugin-transcription 0.9.0 → 0.9.1-staging.ee54ba693a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PLUGIN.mdl +25 -5
- package/dist/lib/neutral/{TranscriptionArticle-L6XANBH5.mjs → TranscriptionArticle-FEWCWG4A.mjs} +4 -7
- package/dist/lib/neutral/TranscriptionArticle-FEWCWG4A.mjs.map +7 -0
- package/dist/lib/neutral/TranscriptionPlugin.mjs +29 -6
- package/dist/lib/neutral/TranscriptionPlugin.mjs.map +4 -4
- package/dist/lib/neutral/TranscriptionPlugin.node.mjs +3 -3
- package/dist/lib/neutral/TranscriptionPlugin.node.mjs.map +3 -3
- package/dist/lib/neutral/app-graph-builder-GQRMI22E.mjs +48 -0
- package/dist/lib/neutral/app-graph-builder-GQRMI22E.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +19 -5
- package/dist/lib/neutral/capabilities/index.mjs.map +3 -3
- package/dist/lib/neutral/chunk-5BVHY75B.mjs +54 -0
- package/dist/lib/neutral/chunk-5BVHY75B.mjs.map +7 -0
- package/dist/lib/neutral/chunk-HNXSU7HJ.mjs +8 -0
- package/dist/lib/neutral/{chunk-KXJZEYS7.mjs.map → chunk-HNXSU7HJ.mjs.map} +2 -2
- package/dist/lib/neutral/chunk-KOXLGGSL.mjs +30 -0
- package/dist/lib/neutral/chunk-KOXLGGSL.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MDV7NBFJ.mjs +182 -0
- package/dist/lib/neutral/chunk-MDV7NBFJ.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +114 -258
- package/dist/lib/neutral/components/index.mjs.map +4 -4
- package/dist/lib/neutral/containers/index.mjs +1 -1
- package/dist/lib/neutral/{create-RVR7VC33.mjs → create-HNHGCKZ4.mjs} +2 -2
- package/dist/lib/neutral/enrich-message-DSJU4TXC.mjs +24 -0
- package/dist/lib/neutral/enrich-message-DSJU4TXC.mjs.map +7 -0
- package/dist/lib/neutral/entity-lookup-PCDW7NC4.mjs +25 -0
- package/dist/lib/neutral/entity-lookup-PCDW7NC4.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +93 -15
- package/dist/lib/neutral/hooks/index.mjs.map +4 -4
- package/dist/lib/neutral/index.mjs +8 -32
- package/dist/lib/neutral/markdown-extension-CCDXXY7E.mjs +16 -0
- package/dist/lib/neutral/markdown-extension-CCDXXY7E.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/meta.mjs +1 -1
- package/dist/lib/neutral/{open-A5KXKRH4.mjs → open-SNMZXXYO.mjs} +4 -6
- package/dist/lib/neutral/open-SNMZXXYO.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +1 -1
- package/dist/lib/neutral/pipeline-status-XMWMAUJY.mjs +17 -0
- package/dist/lib/neutral/pipeline-status-XMWMAUJY.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +2 -2
- package/dist/lib/neutral/recording-session-IADO7ATU.mjs +15 -0
- package/dist/lib/neutral/recording-session-IADO7ATU.mjs.map +7 -0
- package/dist/lib/neutral/settings-7KE4MABW.mjs +31 -0
- package/dist/lib/neutral/settings-7KE4MABW.mjs.map +7 -0
- package/dist/lib/neutral/skill-definition-DXNK324V.mjs +15 -0
- package/dist/lib/neutral/skill-definition-DXNK324V.mjs.map +7 -0
- package/dist/lib/neutral/skills/index.mjs +8 -0
- package/dist/lib/neutral/{summarize-5XPPMVTE.mjs → summarize-LBUZTOTH.mjs} +4 -4
- package/dist/lib/neutral/summarize-LBUZTOTH.mjs.map +7 -0
- package/dist/lib/neutral/{text-content-KBB37HSM.mjs → text-content-NOWR642C.mjs} +9 -9
- package/dist/lib/neutral/text-content-NOWR642C.mjs.map +7 -0
- package/dist/lib/neutral/transcriber-6XZHUUHK.mjs +174 -0
- package/dist/lib/neutral/transcriber-6XZHUUHK.mjs.map +7 -0
- package/dist/lib/neutral/transcription-driver-DN6ELQXZ.mjs +207 -0
- package/dist/lib/neutral/transcription-driver-DN6ELQXZ.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +8 -1
- package/dist/lib/neutral/translations.mjs.map +3 -3
- package/dist/lib/neutral/types/index.mjs +3 -1
- package/dist/types/dx.config.d.ts +28 -0
- package/dist/types/dx.config.d.ts.map +1 -0
- package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +5 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/entity-lookup.d.ts +10 -0
- package/dist/types/src/capabilities/entity-lookup.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +11 -8
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown-extension.d.ts +5 -0
- package/dist/types/src/capabilities/markdown-extension.d.ts.map +1 -0
- package/dist/types/src/capabilities/pipeline-status.d.ts +9 -0
- package/dist/types/src/capabilities/pipeline-status.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +2 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/recording-session.d.ts +5 -0
- package/dist/types/src/capabilities/recording-session.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings.d.ts +5 -0
- package/dist/types/src/capabilities/settings.d.ts.map +1 -0
- package/dist/types/src/capabilities/skill-definition.d.ts +5 -0
- package/dist/types/src/capabilities/skill-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/text-content.d.ts +1 -4
- package/dist/types/src/capabilities/transcriber.d.ts +4 -3
- package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
- package/dist/types/src/capabilities/transcription-driver.d.ts +5 -0
- package/dist/types/src/capabilities/transcription-driver.d.ts.map +1 -0
- package/dist/types/src/components/Mic/Mic.d.ts +12 -0
- package/dist/types/src/components/Mic/Mic.d.ts.map +1 -0
- package/dist/types/src/components/{Oracle/Oracle.stories.d.ts → Mic/Mic.stories.d.ts} +9 -7
- package/dist/types/src/components/Mic/Mic.stories.d.ts.map +1 -0
- package/dist/types/src/components/Mic/index.d.ts +2 -0
- package/dist/types/src/components/Mic/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.d.ts.map +1 -1
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.stories.d.ts +7 -0
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -5
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTranscriptionRecording.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +32 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/normalization/message-normalizer.d.ts +2 -2
- package/dist/types/src/normalization/message-normalizer.d.ts.map +1 -1
- package/dist/types/src/normalization/normalization.d.ts +98 -733
- package/dist/types/src/normalization/normalization.d.ts.map +1 -1
- package/dist/types/src/operations/enrich-message.d.ts +9 -0
- package/dist/types/src/operations/enrich-message.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/operations/open.d.ts.map +1 -1
- package/dist/types/src/operations/summarize.d.ts.map +1 -1
- package/dist/types/src/skills/index.d.ts +2 -0
- package/dist/types/src/skills/index.d.ts.map +1 -0
- package/dist/types/src/skills/transcription-skill.d.ts +4 -0
- package/dist/types/src/skills/transcription-skill.d.ts.map +1 -0
- package/dist/types/src/stories/Keyword.stories.d.ts +51 -0
- package/dist/types/src/stories/Keyword.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Pipeline.stories.d.ts +60 -0
- package/dist/types/src/stories/Pipeline.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Transcription.stories.d.ts +23 -0
- package/dist/types/src/stories/Transcription.stories.d.ts.map +1 -0
- package/dist/types/src/testing/decorators.d.ts +21 -0
- package/dist/types/src/testing/decorators.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +3 -13
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/{transcriber/transcription-manager.d.ts → transcription-manager.d.ts} +6 -5
- package/dist/types/src/transcription-manager.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +7 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Settings.d.ts +13 -0
- package/dist/types/src/types/Settings.d.ts.map +1 -0
- package/dist/types/src/types/TranscriptOperation.d.ts +114 -1564
- package/dist/types/src/types/TranscriptOperation.d.ts.map +1 -1
- package/dist/types/src/types/TranscriptionCapabilities.d.ts +52 -11
- package/dist/types/src/types/TranscriptionCapabilities.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -3
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dx.config.ts +42 -0
- package/package.json +69 -69
- package/src/TranscriptionPlugin.node.ts +2 -2
- package/src/TranscriptionPlugin.test.ts +2 -2
- package/src/TranscriptionPlugin.tsx +40 -3
- package/src/capabilities/app-graph-builder.tsx +49 -0
- package/src/capabilities/entity-lookup.ts +32 -0
- package/src/capabilities/index.ts +8 -7
- package/src/capabilities/markdown-extension.ts +17 -0
- package/src/capabilities/pipeline-status.ts +23 -0
- package/src/capabilities/recording-session.ts +17 -0
- package/src/capabilities/settings.ts +34 -0
- package/src/capabilities/skill-definition.ts +15 -0
- package/src/capabilities/text-content.ts +10 -7
- package/src/capabilities/transcriber.ts +5 -48
- package/src/capabilities/transcription-driver.tsx +263 -0
- package/src/components/Mic/Mic.stories.tsx +66 -0
- package/src/components/Mic/Mic.tsx +136 -0
- package/src/components/Mic/index.ts +5 -0
- package/src/components/index.ts +1 -2
- package/src/containers/TranscriptionArticle/TranscriptionArticle.stories.tsx +4 -0
- package/src/containers/TranscriptionArticle/TranscriptionArticle.tsx +5 -6
- package/src/hooks/index.ts +0 -5
- package/src/hooks/useTranscriptionRecording.ts +27 -9
- package/src/index.ts +1 -5
- package/src/meta.ts +2 -35
- package/src/normalization/message-normalizer.ts +3 -3
- package/src/normalization/normalization.ts +3 -0
- package/src/operations/enrich-message.ts +27 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/open.ts +2 -2
- package/src/operations/summarize.ts +2 -2
- package/src/skills/index.ts +5 -0
- package/src/skills/transcription-skill.ts +29 -0
- package/src/stories/Keyword.stories.tsx +98 -0
- package/src/stories/Pipeline.stories.tsx +361 -0
- package/src/stories/Transcription.stories.tsx +178 -0
- package/src/testing/decorators.ts +78 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/testing.ts +14 -134
- package/src/{transcriber/transcription-manager.ts → transcription-manager.ts} +13 -12
- package/src/translations.ts +9 -1
- package/src/types/Settings.ts +59 -0
- package/src/types/TranscriptOperation.ts +22 -4
- package/src/types/TranscriptionCapabilities.ts +61 -20
- package/src/types/index.ts +1 -0
- package/src/util/index.ts +0 -3
- package/dist/lib/neutral/TranscriptionArticle-L6XANBH5.mjs.map +0 -7
- package/dist/lib/neutral/blueprint-definition-DA4QFRYJ.mjs +0 -15
- package/dist/lib/neutral/blueprint-definition-DA4QFRYJ.mjs.map +0 -7
- package/dist/lib/neutral/blueprints/index.mjs +0 -8
- package/dist/lib/neutral/chunk-FHNI26QW.mjs +0 -45
- package/dist/lib/neutral/chunk-FHNI26QW.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KAEXRX3Y.mjs +0 -35
- package/dist/lib/neutral/chunk-KAEXRX3Y.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KMT3BMMQ.mjs +0 -124
- package/dist/lib/neutral/chunk-KMT3BMMQ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KXJZEYS7.mjs +0 -8
- package/dist/lib/neutral/chunk-MLRJWAQH.mjs +0 -179
- package/dist/lib/neutral/chunk-MLRJWAQH.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TO77KAQK.mjs +0 -298
- package/dist/lib/neutral/chunk-TO77KAQK.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TX3NQISZ.mjs +0 -435
- package/dist/lib/neutral/chunk-TX3NQISZ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZR4BH4QQ.mjs +0 -30
- package/dist/lib/neutral/chunk-ZR4BH4QQ.mjs.map +0 -7
- package/dist/lib/neutral/open-A5KXKRH4.mjs.map +0 -7
- package/dist/lib/neutral/summarize-5XPPMVTE.mjs.map +0 -7
- package/dist/lib/neutral/text-content-KBB37HSM.mjs.map +0 -7
- package/dist/lib/neutral/transcriber-OGSF3XO5.mjs +0 -59
- package/dist/lib/neutral/transcriber-OGSF3XO5.mjs.map +0 -7
- package/dist/types/src/blueprints/index.d.ts +0 -2
- package/dist/types/src/blueprints/index.d.ts.map +0 -1
- package/dist/types/src/blueprints/transcription-blueprint.d.ts +0 -4
- package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +0 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -6
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
- package/dist/types/src/components/Oracle/Oracle.d.ts +0 -24
- package/dist/types/src/components/Oracle/Oracle.d.ts.map +0 -1
- package/dist/types/src/components/Oracle/Oracle.stories.d.ts.map +0 -1
- package/dist/types/src/components/Oracle/index.d.ts +0 -2
- package/dist/types/src/components/Oracle/index.d.ts.map +0 -1
- package/dist/types/src/components/Transcription/Transcription.d.ts +0 -11
- package/dist/types/src/components/Transcription/Transcription.d.ts.map +0 -1
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts +0 -37
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +0 -1
- package/dist/types/src/components/Transcription/index.d.ts +0 -2
- package/dist/types/src/components/Transcription/index.d.ts.map +0 -1
- package/dist/types/src/components/Transcription/transcription-extension.d.ts +0 -15
- package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +0 -1
- package/dist/types/src/enrichment/conversation.test.d.ts +0 -2
- package/dist/types/src/enrichment/conversation.test.d.ts.map +0 -1
- package/dist/types/src/enrichment/operations.d.ts +0 -200
- package/dist/types/src/enrichment/operations.d.ts.map +0 -1
- package/dist/types/src/enrichment/parser.d.ts +0 -26
- package/dist/types/src/enrichment/parser.d.ts.map +0 -1
- package/dist/types/src/enrichment/stream-simulator.d.ts +0 -38
- package/dist/types/src/enrichment/stream-simulator.d.ts.map +0 -1
- package/dist/types/src/hooks/useAudioFile.d.ts +0 -7
- package/dist/types/src/hooks/useAudioFile.d.ts.map +0 -1
- package/dist/types/src/hooks/useAudioTrack.d.ts +0 -5
- package/dist/types/src/hooks/useAudioTrack.d.ts.map +0 -1
- package/dist/types/src/hooks/useFeedModelAdapter.d.ts +0 -12
- package/dist/types/src/hooks/useFeedModelAdapter.d.ts.map +0 -1
- package/dist/types/src/hooks/useTranscriber.d.ts +0 -7
- package/dist/types/src/hooks/useTranscriber.d.ts.map +0 -1
- package/dist/types/src/hooks/useVoiceInput.d.ts +0 -11
- package/dist/types/src/hooks/useVoiceInput.d.ts.map +0 -1
- package/dist/types/src/model/index.d.ts +0 -2
- package/dist/types/src/model/index.d.ts.map +0 -1
- package/dist/types/src/model/model.d.ts +0 -68
- package/dist/types/src/model/model.d.ts.map +0 -1
- package/dist/types/src/model/model.test.d.ts +0 -2
- package/dist/types/src/model/model.test.d.ts.map +0 -1
- package/dist/types/src/stories/FileTranscription.stories.d.ts +0 -20
- package/dist/types/src/stories/FileTranscription.stories.d.ts.map +0 -1
- package/dist/types/src/stories/KeyWordRecognition.stories.d.ts +0 -14
- package/dist/types/src/stories/KeyWordRecognition.stories.d.ts.map +0 -1
- package/dist/types/src/stories/LiveTranscription.stories.d.ts +0 -20
- package/dist/types/src/stories/LiveTranscription.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TranscriptionStory.d.ts +0 -21
- package/dist/types/src/stories/TranscriptionStory.d.ts.map +0 -1
- package/dist/types/src/stories/common.d.ts +0 -248
- package/dist/types/src/stories/common.d.ts.map +0 -1
- package/dist/types/src/transcriber/audio-recorder.d.ts +0 -47
- package/dist/types/src/transcriber/audio-recorder.d.ts.map +0 -1
- package/dist/types/src/transcriber/index.d.ts +0 -5
- package/dist/types/src/transcriber/index.d.ts.map +0 -1
- package/dist/types/src/transcriber/media-stream-recorder.d.ts +0 -30
- package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +0 -1
- package/dist/types/src/transcriber/transcriber.browser.test.d.ts +0 -2
- package/dist/types/src/transcriber/transcriber.browser.test.d.ts.map +0 -1
- package/dist/types/src/transcriber/transcriber.d.ts +0 -105
- package/dist/types/src/transcriber/transcriber.d.ts.map +0 -1
- package/dist/types/src/transcriber/transcriber.test.d.ts +0 -2
- package/dist/types/src/transcriber/transcriber.test.d.ts.map +0 -1
- package/dist/types/src/transcriber/transcription-manager.d.ts.map +0 -1
- package/dist/types/src/util/array.d.ts +0 -2
- package/dist/types/src/util/array.d.ts.map +0 -1
- package/dist/types/src/util/monitor-audio-level.d.ts +0 -6
- package/dist/types/src/util/monitor-audio-level.d.ts.map +0 -1
- package/dist/types/src/util/render-byline.d.ts +0 -4
- package/dist/types/src/util/render-byline.d.ts.map +0 -1
- package/src/blueprints/index.ts +0 -5
- package/src/blueprints/transcription-blueprint.ts +0 -29
- package/src/capabilities/blueprint-definition.ts +0 -19
- package/src/components/Oracle/Oracle.stories.tsx +0 -147
- package/src/components/Oracle/Oracle.tsx +0 -142
- package/src/components/Oracle/index.ts +0 -5
- package/src/components/Transcription/Transcription.stories.tsx +0 -213
- package/src/components/Transcription/Transcription.tsx +0 -55
- package/src/components/Transcription/index.ts +0 -5
- package/src/components/Transcription/transcription-extension.ts +0 -203
- package/src/enrichment/conversation.test.ts +0 -162
- package/src/enrichment/conversation.txt +0 -23
- package/src/enrichment/operations.ts +0 -271
- package/src/enrichment/parser.ts +0 -101
- package/src/enrichment/stream-simulator.ts +0 -125
- package/src/hooks/useAudioFile.ts +0 -88
- package/src/hooks/useAudioTrack.ts +0 -35
- package/src/hooks/useFeedModelAdapter.ts +0 -46
- package/src/hooks/useTranscriber.ts +0 -47
- package/src/hooks/useVoiceInput.ts +0 -66
- package/src/model/index.ts +0 -5
- package/src/model/model.test.ts +0 -175
- package/src/model/model.ts +0 -229
- package/src/stories/FileTranscription.stories.tsx +0 -143
- package/src/stories/KeyWordRecognition.stories.tsx +0 -132
- package/src/stories/LiveTranscription.stories.tsx +0 -153
- package/src/stories/TranscriptionStory.tsx +0 -101
- package/src/stories/common.ts +0 -233
- package/src/transcriber/audio-recorder.ts +0 -56
- package/src/transcriber/index.ts +0 -8
- package/src/transcriber/media-stream-recorder.ts +0 -120
- package/src/transcriber/transcriber.browser.test.ts +0 -230
- package/src/transcriber/transcriber.test.ts +0 -104
- package/src/transcriber/transcriber.ts +0 -303
- package/src/util/array.ts +0 -14
- package/src/util/monitor-audio-level.ts +0 -58
- package/src/util/render-byline.ts +0 -33
- /package/dist/lib/neutral/{create-RVR7VC33.mjs.map → create-HNHGCKZ4.mjs.map} +0 -0
- /package/dist/lib/neutral/{blueprints → skills}/index.mjs.map +0 -0
package/src/model/model.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Text } from '@codemirror/state';
|
|
6
|
-
import { type EditorView } from '@codemirror/view';
|
|
7
|
-
|
|
8
|
-
import { Event } from '@dxos/async';
|
|
9
|
-
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
|
|
12
|
-
export type Chunk = { id: string };
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Covert block to a set of markdown lines.
|
|
16
|
-
*/
|
|
17
|
-
export type ChunkRenderer<T extends Chunk> = (chunk: T, index: number, debug?: boolean) => string[];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Abstract representation of the document model.
|
|
21
|
-
*/
|
|
22
|
-
export interface ChunkDocument {
|
|
23
|
-
lineCount(): number;
|
|
24
|
-
replaceLines(from: number, remove: number, insert: string[]): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Codemirror document adapter.
|
|
29
|
-
*/
|
|
30
|
-
export class DocumentAdapter implements ChunkDocument {
|
|
31
|
-
constructor(private readonly _view: EditorView) {}
|
|
32
|
-
|
|
33
|
-
/** The document must always have at least one line. */
|
|
34
|
-
lineCount(): number {
|
|
35
|
-
return this._view.state.doc.lines - 1;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
replaceLines(from: number, remove: number, insert: string[]): void {
|
|
39
|
-
log('replaceLines', { count: this._view.state.doc.lines, from, remove, insert });
|
|
40
|
-
|
|
41
|
-
const numLines = this._view.state.doc.lines;
|
|
42
|
-
const posFrom = this._view.state.doc.line(from).from;
|
|
43
|
-
const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;
|
|
44
|
-
|
|
45
|
-
// Don't remove the last line.
|
|
46
|
-
let text = insert.join('\n');
|
|
47
|
-
if (posTo === this._view.state.doc.length) {
|
|
48
|
-
text += '\n';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this._view.dispatch({
|
|
52
|
-
changes: { from: posFrom, to: posTo, insert: text },
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type ChunkChange<T extends Chunk> =
|
|
58
|
-
| {
|
|
59
|
-
type: 'append';
|
|
60
|
-
index: number;
|
|
61
|
-
chunk: T;
|
|
62
|
-
}
|
|
63
|
-
| {
|
|
64
|
-
type: 'update';
|
|
65
|
-
index: number;
|
|
66
|
-
chunk: T;
|
|
67
|
-
}
|
|
68
|
-
| {
|
|
69
|
-
type: 'delete';
|
|
70
|
-
index: number;
|
|
71
|
-
id: string;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Each Chunk can be converted into a set of lines.
|
|
76
|
-
* Chunks can be added, updated or deleted from the Queue.
|
|
77
|
-
* A Document is an immutable projection that represents a flat list of lines corresponding to the Queue.
|
|
78
|
-
*
|
|
79
|
-
* Ideally we would implement a custom virtual Text model for the View, but this currently isn't possible in Codemirror.
|
|
80
|
-
* Instead this model tracks changes and syncs them with the ChunkDocument.
|
|
81
|
-
*/
|
|
82
|
-
export class SerializationModel<T extends Chunk> {
|
|
83
|
-
/** Emits when the document is updated. */
|
|
84
|
-
public readonly update = new Event<void>();
|
|
85
|
-
|
|
86
|
-
/** Ordered set of chunks. */
|
|
87
|
-
private readonly _chunks: T[] = [];
|
|
88
|
-
|
|
89
|
-
/** Map of chunk IDs to their current line counts. */
|
|
90
|
-
private readonly _chunkLineCounts = new Map<string, number>();
|
|
91
|
-
|
|
92
|
-
/** Map of line numbers to chunk IDs. */
|
|
93
|
-
private readonly _lineToChunk = new Map<number, T>();
|
|
94
|
-
|
|
95
|
-
/** Track chunk changes since last sync. */
|
|
96
|
-
private readonly _changes: Array<ChunkChange<T>> = [];
|
|
97
|
-
|
|
98
|
-
constructor(
|
|
99
|
-
private readonly _renderer: ChunkRenderer<T>,
|
|
100
|
-
initialChunks: T[] = [],
|
|
101
|
-
) {
|
|
102
|
-
initialChunks.forEach((chunk) => {
|
|
103
|
-
this.appendChunk(chunk);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
toJSON(): { chunks: number; changes: number } {
|
|
108
|
-
return {
|
|
109
|
-
chunks: this._chunks.length,
|
|
110
|
-
changes: this._changes.length,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get doc() {
|
|
115
|
-
return Text.of([...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)), '']);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get chunks() {
|
|
119
|
-
return this._chunks;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Get the block ID at the given line number.
|
|
124
|
-
*/
|
|
125
|
-
getChunkAtLine(line: number): T | undefined {
|
|
126
|
-
return this._lineToChunk.get(line);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
reset(): this {
|
|
130
|
-
this._chunks.length = 0;
|
|
131
|
-
this._chunkLineCounts.clear();
|
|
132
|
-
this._lineToChunk.clear();
|
|
133
|
-
this.update.emit();
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
appendChunk(chunk: T): this {
|
|
138
|
-
const index = this._chunks.length;
|
|
139
|
-
this._chunks.push(chunk);
|
|
140
|
-
this._changes.push({ type: 'append', index, chunk });
|
|
141
|
-
this.update.emit();
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
updateChunk(chunk: T): this {
|
|
146
|
-
const index = this._chunks.findIndex((c) => c.id === chunk.id);
|
|
147
|
-
invariant(index !== -1);
|
|
148
|
-
this._chunks[index] = chunk;
|
|
149
|
-
this._changes.push({ type: 'update', index, chunk });
|
|
150
|
-
this.update.emit();
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
deleteBlock(id: string): this {
|
|
155
|
-
const index = this._chunks.findIndex((c) => c.id === id);
|
|
156
|
-
invariant(index !== -1);
|
|
157
|
-
this._chunks.splice(index, 1);
|
|
158
|
-
this._changes.push({ type: 'delete', index, id });
|
|
159
|
-
this.update.emit();
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Syncs the tracked changes with the ChunkDocument.
|
|
165
|
-
*/
|
|
166
|
-
sync(document: ChunkDocument): this {
|
|
167
|
-
log('sync', { changes: this._changes });
|
|
168
|
-
|
|
169
|
-
// Process each change in order.
|
|
170
|
-
for (const change of this._changes) {
|
|
171
|
-
switch (change.type) {
|
|
172
|
-
case 'append': {
|
|
173
|
-
// For appends, convert block to lines and add at the end.
|
|
174
|
-
const lines = this._renderer(change.chunk, change.index);
|
|
175
|
-
const lastLine = document.lineCount();
|
|
176
|
-
document.replaceLines(lastLine + 1, 0, lines);
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
case 'update': {
|
|
181
|
-
// For updates, find the block's line range and replace with new lines.
|
|
182
|
-
let lineStart = 1;
|
|
183
|
-
for (let i = 0; i < change.index; i++) {
|
|
184
|
-
lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;
|
|
185
|
-
}
|
|
186
|
-
const previousLineCount = this._chunkLineCounts.get(change.chunk.id)!;
|
|
187
|
-
const newLines = this._renderer(change.chunk, change.index);
|
|
188
|
-
document.replaceLines(lineStart, previousLineCount, newLines);
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
case 'delete': {
|
|
193
|
-
// For deletes, find the block's line range and remove those lines.
|
|
194
|
-
let lineStart = 1;
|
|
195
|
-
for (let i = 0; i < change.index; i++) {
|
|
196
|
-
lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;
|
|
197
|
-
}
|
|
198
|
-
const previousLineCount = this._chunkLineCounts.get(change.id)!;
|
|
199
|
-
document.replaceLines(lineStart, previousLineCount, []);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Clear the line-to-block mapping.
|
|
206
|
-
this._lineToChunk.clear();
|
|
207
|
-
|
|
208
|
-
// Update all block line counts and line-to-block mapping after processing changes.
|
|
209
|
-
let currentLine = 1;
|
|
210
|
-
for (const [index, chunk] of this._chunks.entries()) {
|
|
211
|
-
const lineCount = this._renderer(chunk, index).length;
|
|
212
|
-
this._chunkLineCounts.set(chunk.id, lineCount);
|
|
213
|
-
this._lineToChunk.set(currentLine, chunk);
|
|
214
|
-
currentLine += lineCount;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Clean up deleted blocks.
|
|
218
|
-
const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));
|
|
219
|
-
for (const id of this._chunkLineCounts.keys()) {
|
|
220
|
-
if (!chunkIds.has(id)) {
|
|
221
|
-
this._chunkLineCounts.delete(id);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Clear changes after sync.
|
|
226
|
-
this._changes.length = 0;
|
|
227
|
-
return this;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { useAudioFile } from '#hooks';
|
|
9
|
-
|
|
10
|
-
import { type MediaStreamRecorderProps, type TranscriberProps } from '../transcriber';
|
|
11
|
-
import {
|
|
12
|
-
useIsSpeaking,
|
|
13
|
-
createStoryDecorators,
|
|
14
|
-
useStoryAppendSegments,
|
|
15
|
-
useStoryMessageModel,
|
|
16
|
-
useStoryTranscriber,
|
|
17
|
-
} from './common';
|
|
18
|
-
import { TranscriptionStory } from './TranscriptionStory';
|
|
19
|
-
|
|
20
|
-
const DEFAULT_TRANSCRIBER_CONFIG = {
|
|
21
|
-
transcribeAfterChunksAmount: 100,
|
|
22
|
-
prefixBufferChunksAmount: 50,
|
|
23
|
-
normalizeSentences: true,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const DEFAULT_RECORDER_CONFIG = {
|
|
27
|
-
interval: 200,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type DefaultStoryProps = {
|
|
31
|
-
detectSpeaking?: boolean;
|
|
32
|
-
normalizeSentences?: boolean;
|
|
33
|
-
audioUrl: string;
|
|
34
|
-
transcriberConfig?: TranscriberProps['config'];
|
|
35
|
-
recorderConfig?: MediaStreamRecorderProps['config'];
|
|
36
|
-
audioConstraints?: MediaTrackConstraints;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const DefaultStory = ({
|
|
40
|
-
detectSpeaking,
|
|
41
|
-
audioUrl,
|
|
42
|
-
normalizeSentences,
|
|
43
|
-
transcriberConfig = DEFAULT_TRANSCRIBER_CONFIG,
|
|
44
|
-
recorderConfig = DEFAULT_RECORDER_CONFIG,
|
|
45
|
-
audioConstraints,
|
|
46
|
-
}: DefaultStoryProps) => {
|
|
47
|
-
const [running, setRunning] = useState(false);
|
|
48
|
-
|
|
49
|
-
// Optional uploaded file overrides the default URL; revoke the previous URL on change/unmount.
|
|
50
|
-
const [uploadedUrl, setUploadedUrl] = useState<string>();
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
return () => {
|
|
53
|
-
if (uploadedUrl) {
|
|
54
|
-
URL.revokeObjectURL(uploadedUrl);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}, [uploadedUrl]);
|
|
58
|
-
|
|
59
|
-
const handleUpload = useCallback((file: File) => {
|
|
60
|
-
setRunning(false);
|
|
61
|
-
setUploadedUrl(URL.createObjectURL(file));
|
|
62
|
-
}, []);
|
|
63
|
-
|
|
64
|
-
const sourceUrl = uploadedUrl ?? audioUrl;
|
|
65
|
-
const { audio, track, stream } = useAudioFile(sourceUrl, audioConstraints);
|
|
66
|
-
const isSpeaking = detectSpeaking ? useIsSpeaking(track) : true;
|
|
67
|
-
|
|
68
|
-
// Pipe the decoded stream into the <audio> element so the user hears playback.
|
|
69
|
-
const ref = useRef<HTMLAudioElement>(null);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (ref.current && stream) {
|
|
72
|
-
ref.current.srcObject = stream;
|
|
73
|
-
}
|
|
74
|
-
}, [stream]);
|
|
75
|
-
|
|
76
|
-
// Mirror the toolbar's running flag to the underlying HTMLAudioElement.
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!audio) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (running) {
|
|
83
|
-
void audio.play();
|
|
84
|
-
} else {
|
|
85
|
-
void audio.pause();
|
|
86
|
-
}
|
|
87
|
-
}, [audio, running]);
|
|
88
|
-
|
|
89
|
-
const { model, appendMessage } = useStoryMessageModel();
|
|
90
|
-
const handleSegments = useStoryAppendSegments(appendMessage);
|
|
91
|
-
|
|
92
|
-
useStoryTranscriber({
|
|
93
|
-
audioStreamTrack: track,
|
|
94
|
-
running,
|
|
95
|
-
isSpeaking,
|
|
96
|
-
transcriberConfig,
|
|
97
|
-
recorderConfig,
|
|
98
|
-
onSegments: handleSegments,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// TODO(burdon): Sentence normalization moved to require a real space-backed Feed + FeedService runtime.
|
|
102
|
-
// Re-enable here once the story has access to one.
|
|
103
|
-
void normalizeSentences;
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<TranscriptionStory
|
|
107
|
-
audioRef={ref}
|
|
108
|
-
disabled={!stream}
|
|
109
|
-
model={model}
|
|
110
|
-
running={running}
|
|
111
|
-
onRunningChange={setRunning}
|
|
112
|
-
onUpload={handleUpload}
|
|
113
|
-
/>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const meta = {
|
|
118
|
-
title: 'plugins/plugin-transcription/stories/FileTranscription',
|
|
119
|
-
render: DefaultStory,
|
|
120
|
-
decorators: createStoryDecorators(),
|
|
121
|
-
} satisfies Meta<DefaultStoryProps>;
|
|
122
|
-
|
|
123
|
-
export default meta;
|
|
124
|
-
|
|
125
|
-
type Story = StoryObj<typeof meta>;
|
|
126
|
-
|
|
127
|
-
export const Default: Story = {
|
|
128
|
-
args: {
|
|
129
|
-
detectSpeaking: true,
|
|
130
|
-
// https://learnenglish.britishcouncil.org/general-english/audio-zone/living-london
|
|
131
|
-
audioUrl: 'https://dxos.network/audio-london.m4a',
|
|
132
|
-
// textUrl: 'https://dxos.network/audio-london.txt',
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// TODO(mykola): Fix sentence normalization.
|
|
137
|
-
// export const WithSentenceNormalization: StoryObj<typeof AudioFile> = {
|
|
138
|
-
// args: {
|
|
139
|
-
// detectSpeaking: true,
|
|
140
|
-
// normalizeSentences: true,
|
|
141
|
-
// audioUrl: 'https://dxos.network/audio-london.m4a',
|
|
142
|
-
// },
|
|
143
|
-
// };
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { log } from '@dxos/log';
|
|
9
|
-
import { Panel, Toolbar } from '@dxos/react-ui';
|
|
10
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
|
-
import { mx } from '@dxos/ui-theme';
|
|
12
|
-
|
|
13
|
-
type Word = {
|
|
14
|
-
text: string;
|
|
15
|
-
matched: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type DefaultStoryProps = {
|
|
19
|
-
keywords: string[];
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const DefaultStory = ({ keywords }: DefaultStoryProps) => {
|
|
23
|
-
const [running, setRunning] = useState(false);
|
|
24
|
-
const [matchingWords, setMatchingWords] = useState<Word[]>(keywords.map((word) => ({ text: word, matched: false })));
|
|
25
|
-
|
|
26
|
-
const recognition = useMemo(() => {
|
|
27
|
-
// TODO(mykola): Fix types
|
|
28
|
-
const SpeechRecognition = (window as any).SpeechRecognition || (window as any).webkitSpeechRecognition;
|
|
29
|
-
const SpeechGrammarList = (window as any).SpeechGrammarList || (window as any).webkitSpeechGrammarList;
|
|
30
|
-
if (!SpeechRecognition || !SpeechGrammarList) {
|
|
31
|
-
log.error('Speech recognition not supported in this browser');
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const recognition = new SpeechRecognition();
|
|
36
|
-
recognition.continuous = true;
|
|
37
|
-
recognition.interimResults = true;
|
|
38
|
-
recognition.lang = 'en-US';
|
|
39
|
-
recognition.maxAlternatives = 1;
|
|
40
|
-
// Add this line to enable punctuation.
|
|
41
|
-
recognition.grammars = new SpeechGrammarList();
|
|
42
|
-
|
|
43
|
-
// TODO(mykola): Fix types.
|
|
44
|
-
recognition.onresult = (event: any) => {
|
|
45
|
-
log.info('recognition result', { event });
|
|
46
|
-
const current = event.resultIndex;
|
|
47
|
-
const transcript = event.results[current][0].transcript;
|
|
48
|
-
|
|
49
|
-
// Remove punctuation and normalize whitespace for comparison.
|
|
50
|
-
const normalizeText = (text: string) =>
|
|
51
|
-
text
|
|
52
|
-
.toLowerCase()
|
|
53
|
-
.replace(/[.,!?]/g, '')
|
|
54
|
-
.replace(/\s+/g, ' ')
|
|
55
|
-
.trim();
|
|
56
|
-
|
|
57
|
-
const normalizedTranscript = normalizeText(transcript);
|
|
58
|
-
|
|
59
|
-
// Check each keyword and update matching words.
|
|
60
|
-
const updatedWords = matchingWords.map((word) => {
|
|
61
|
-
const normalizedKeyword = normalizeText(word.text);
|
|
62
|
-
const matched = normalizedTranscript.includes(normalizedKeyword);
|
|
63
|
-
return { ...word, matched };
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
setMatchingWords(updatedWords);
|
|
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
|
-
<Panel.Root>
|
|
88
|
-
<Panel.Toolbar asChild>
|
|
89
|
-
<Toolbar.Root>
|
|
90
|
-
<Toolbar.IconButton
|
|
91
|
-
iconOnly
|
|
92
|
-
icon={running ? 'ph--pause--regular' : 'ph--play--regular'}
|
|
93
|
-
label={running ? 'Pause' : 'Play'}
|
|
94
|
-
onClick={() => setRunning((running) => !running)}
|
|
95
|
-
/>
|
|
96
|
-
</Toolbar.Root>
|
|
97
|
-
</Panel.Toolbar>
|
|
98
|
-
|
|
99
|
-
<Panel.Content>
|
|
100
|
-
<div className='p-2 grid grid-cols-[repeat(auto-fill,minmax(6rem,1fr))] gap-2'>
|
|
101
|
-
{matchingWords.map((word, index) => (
|
|
102
|
-
<span
|
|
103
|
-
key={index}
|
|
104
|
-
className={mx(
|
|
105
|
-
'grid place-items-center p-2 aspect-square rounded-sm border border-separator',
|
|
106
|
-
word.matched && 'border-red-300',
|
|
107
|
-
)}
|
|
108
|
-
>
|
|
109
|
-
{word.text}
|
|
110
|
-
</span>
|
|
111
|
-
))}
|
|
112
|
-
</div>
|
|
113
|
-
</Panel.Content>
|
|
114
|
-
</Panel.Root>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const meta = {
|
|
119
|
-
title: 'plugins/plugin-transcription/stories/KeyWordDetection',
|
|
120
|
-
render: DefaultStory,
|
|
121
|
-
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
122
|
-
} satisfies Meta<typeof DefaultStory>;
|
|
123
|
-
|
|
124
|
-
export default meta;
|
|
125
|
-
|
|
126
|
-
type Story = StoryObj<typeof meta>;
|
|
127
|
-
|
|
128
|
-
export const SpeechRecognitionAPI: Story = {
|
|
129
|
-
args: {
|
|
130
|
-
keywords: ['kai', 'computer', 'hello', 'dxos'],
|
|
131
|
-
},
|
|
132
|
-
};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
type ExtractionFunction,
|
|
10
|
-
extractionAnthropicFunction,
|
|
11
|
-
extractionNerFunction,
|
|
12
|
-
getNer,
|
|
13
|
-
processTranscriptMessage,
|
|
14
|
-
} from '@dxos/assistant/extraction';
|
|
15
|
-
import { Filter, type Obj } from '@dxos/echo';
|
|
16
|
-
import { invariant } from '@dxos/invariant';
|
|
17
|
-
import { useSpaces } from '@dxos/react-client/echo';
|
|
18
|
-
import { Message, Organization, Person } from '@dxos/types';
|
|
19
|
-
|
|
20
|
-
import { useAudioTrack } from '#hooks';
|
|
21
|
-
|
|
22
|
-
import { type MediaStreamRecorderProps, type TranscriberProps } from '../transcriber';
|
|
23
|
-
import { useIsSpeaking, createStoryDecorators, useStoryMessageModel, useStoryTranscriber } from './common';
|
|
24
|
-
import { TranscriptionStory } from './TranscriptionStory';
|
|
25
|
-
|
|
26
|
-
const DEFAULT_TRANSCRIBER_CONFIG = {
|
|
27
|
-
transcribeAfterChunksAmount: 50,
|
|
28
|
-
prefixBufferChunksAmount: 10,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const DEFAULT_RECORDER_CONFIG = {
|
|
32
|
-
interval: 200,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type DefaultStoryProps = {
|
|
36
|
-
detectSpeaking?: boolean;
|
|
37
|
-
transcriberConfig?: TranscriberProps['config'];
|
|
38
|
-
recorderConfig?: MediaStreamRecorderProps['config'];
|
|
39
|
-
audioConstraints?: MediaTrackConstraints;
|
|
40
|
-
entityExtraction?: 'ner' | 'llm';
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const DefaultStory = ({
|
|
44
|
-
detectSpeaking,
|
|
45
|
-
entityExtraction,
|
|
46
|
-
transcriberConfig = DEFAULT_TRANSCRIBER_CONFIG,
|
|
47
|
-
recorderConfig = DEFAULT_RECORDER_CONFIG,
|
|
48
|
-
audioConstraints,
|
|
49
|
-
}: DefaultStoryProps) => {
|
|
50
|
-
const [running, setRunning] = useState(false);
|
|
51
|
-
const track = useAudioTrack(running, audioConstraints);
|
|
52
|
-
const isSpeaking = detectSpeaking ? useIsSpeaking(track) : true;
|
|
53
|
-
const { model, appendMessage } = useStoryMessageModel();
|
|
54
|
-
const [space] = useSpaces();
|
|
55
|
-
|
|
56
|
-
// Resolve the entity-extraction function + nearby objects once per `entityExtraction` toggle.
|
|
57
|
-
const { extractionFunction, objects } = useMemo(() => {
|
|
58
|
-
if (!space || !entityExtraction) {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let extractionFunction: ExtractionFunction | undefined;
|
|
63
|
-
let objects: Promise<Obj.Unknown[]> | undefined;
|
|
64
|
-
if (entityExtraction === 'ner') {
|
|
65
|
-
void getNer(); // Init model loading. Takes time.
|
|
66
|
-
extractionFunction = extractionNerFunction;
|
|
67
|
-
} else if (entityExtraction === 'llm') {
|
|
68
|
-
extractionFunction = extractionAnthropicFunction;
|
|
69
|
-
objects = space.db.query(Filter.or(Filter.type(Person.Person), Filter.type(Organization.Organization))).run();
|
|
70
|
-
}
|
|
71
|
-
return { extractionFunction, objects };
|
|
72
|
-
}, [entityExtraction, space]);
|
|
73
|
-
|
|
74
|
-
// Build a Message from each transcribed batch; optionally enrich via entity extraction.
|
|
75
|
-
const handleSegments = useCallback<TranscriberProps['onSegments']>(
|
|
76
|
-
async (blocks) => {
|
|
77
|
-
const message = Message.make({
|
|
78
|
-
sender: { name: 'You' },
|
|
79
|
-
created: new Date().toISOString(),
|
|
80
|
-
blocks,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
if (entityExtraction && space) {
|
|
84
|
-
invariant(extractionFunction, 'extractionFunction is required');
|
|
85
|
-
const result = await processTranscriptMessage({
|
|
86
|
-
function: extractionFunction,
|
|
87
|
-
input: { message, objects: await objects },
|
|
88
|
-
options: { fallbackToRaw: true, timeout: 30_000 },
|
|
89
|
-
});
|
|
90
|
-
appendMessage(result.message);
|
|
91
|
-
} else {
|
|
92
|
-
appendMessage(message);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
[appendMessage, space, entityExtraction, extractionFunction, objects],
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
useStoryTranscriber({
|
|
99
|
-
audioStreamTrack: track,
|
|
100
|
-
running,
|
|
101
|
-
isSpeaking,
|
|
102
|
-
transcriberConfig,
|
|
103
|
-
recorderConfig,
|
|
104
|
-
onSegments: handleSegments,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return <TranscriptionStory model={model} running={running} onRunningChange={setRunning} />;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const meta = {
|
|
111
|
-
title: 'plugins/plugin-transcription/stories/LiveTranscription',
|
|
112
|
-
render: DefaultStory,
|
|
113
|
-
decorators: createStoryDecorators({ enableVectorIndex: true }),
|
|
114
|
-
} satisfies Meta<typeof DefaultStory>;
|
|
115
|
-
|
|
116
|
-
export default meta;
|
|
117
|
-
|
|
118
|
-
type Story = StoryObj<typeof meta>;
|
|
119
|
-
|
|
120
|
-
export const Default: Story = {
|
|
121
|
-
args: {
|
|
122
|
-
detectSpeaking: false,
|
|
123
|
-
audioConstraints: {
|
|
124
|
-
echoCancellation: false,
|
|
125
|
-
noiseSuppression: false,
|
|
126
|
-
autoGainControl: false,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export const SpeechDetection: Story = {
|
|
132
|
-
args: {
|
|
133
|
-
detectSpeaking: true,
|
|
134
|
-
audioConstraints: {
|
|
135
|
-
echoCancellation: true,
|
|
136
|
-
noiseSuppression: true,
|
|
137
|
-
autoGainControl: true,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// TODO(mykola): Fix hugging face quota issues.
|
|
143
|
-
// export const EntityExtraction: Story = {
|
|
144
|
-
// args: {
|
|
145
|
-
// detectSpeaking: true,
|
|
146
|
-
// entityExtraction: 'ner',
|
|
147
|
-
// audioConstraints: {
|
|
148
|
-
// echoCancellation: true,
|
|
149
|
-
// noiseSuppression: true,
|
|
150
|
-
// autoGainControl: true,
|
|
151
|
-
// },
|
|
152
|
-
// },
|
|
153
|
-
// };
|