@dxos/plugin-transcription 0.8.4-main.fcfe5033a5 → 0.8.4-staging.60fe92afc8
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/LICENSE +102 -5
- package/PLUGIN.mdl +401 -0
- package/README.md +1 -1
- package/dist/lib/neutral/TranscriptionArticle-L6XANBH5.mjs +54 -0
- package/dist/lib/neutral/TranscriptionArticle-L6XANBH5.mjs.map +7 -0
- package/dist/lib/neutral/TranscriptionPlugin.mjs +46 -0
- package/dist/lib/neutral/TranscriptionPlugin.mjs.map +7 -0
- package/dist/lib/neutral/TranscriptionPlugin.node.mjs +25 -0
- package/dist/lib/neutral/TranscriptionPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/TranscriptionPlugin.workerd.mjs +21 -0
- package/dist/lib/neutral/TranscriptionPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/blueprint-definition-DA4QFRYJ.mjs +15 -0
- package/dist/lib/neutral/blueprint-definition-DA4QFRYJ.mjs.map +7 -0
- package/dist/lib/neutral/blueprints/index.mjs +8 -0
- package/dist/lib/neutral/capabilities/index.mjs +17 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FHNI26QW.mjs +45 -0
- package/dist/lib/neutral/chunk-FHNI26QW.mjs.map +7 -0
- package/dist/lib/{browser/chunk-HOOPZ7EM.mjs → neutral/chunk-KAEXRX3Y.mjs} +1 -1
- package/dist/lib/{browser/chunk-KOX4WNAR.mjs → neutral/chunk-KMT3BMMQ.mjs} +35 -22
- package/dist/lib/neutral/chunk-KMT3BMMQ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-KXJZEYS7.mjs +8 -0
- package/dist/lib/neutral/chunk-KXJZEYS7.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MLRJWAQH.mjs +179 -0
- package/dist/lib/neutral/chunk-MLRJWAQH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-TO77KAQK.mjs +298 -0
- package/dist/lib/neutral/chunk-TO77KAQK.mjs.map +7 -0
- package/dist/lib/neutral/chunk-TX3NQISZ.mjs +435 -0
- package/dist/lib/neutral/chunk-TX3NQISZ.mjs.map +7 -0
- package/dist/lib/{browser/blueprints/index.mjs → neutral/chunk-ZR4BH4QQ.mjs} +5 -6
- package/dist/lib/neutral/chunk-ZR4BH4QQ.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +269 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +9 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/{browser/create-BTWYQ6IM.mjs → neutral/create-RVR7VC33.mjs} +5 -5
- package/dist/lib/neutral/create-RVR7VC33.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +19 -0
- package/dist/lib/neutral/index.mjs +44 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/{browser/open-CYRYIEZI.mjs → neutral/open-A5KXKRH4.mjs} +7 -7
- package/dist/lib/neutral/open-A5KXKRH4.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-NXMOAXFP.mjs +13 -0
- package/dist/lib/neutral/operation-handler-NXMOAXFP.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-YMZRO242.mjs +26 -0
- package/dist/lib/neutral/react-surface-YMZRO242.mjs.map +7 -0
- package/dist/lib/{browser/summarize-X2ZYTN7S.mjs → neutral/summarize-5XPPMVTE.mjs} +9 -11
- package/dist/lib/neutral/summarize-5XPPMVTE.mjs.map +7 -0
- package/dist/lib/neutral/text-content-KBB37HSM.mjs +30 -0
- package/dist/lib/neutral/text-content-KBB37HSM.mjs.map +7 -0
- package/dist/lib/neutral/transcriber-OGSF3XO5.mjs +59 -0
- package/dist/lib/neutral/transcriber-OGSF3XO5.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +24 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +10 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/TranscriptionPlugin.d.ts +1 -0
- package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
- package/dist/types/src/TranscriptionPlugin.node.d.ts +4 -0
- package/dist/types/src/TranscriptionPlugin.node.d.ts.map +1 -0
- package/dist/types/src/TranscriptionPlugin.test.d.ts +2 -0
- package/dist/types/src/TranscriptionPlugin.test.d.ts.map +1 -0
- package/dist/types/src/TranscriptionPlugin.workerd.d.ts +4 -0
- package/dist/types/src/TranscriptionPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/blueprints/transcription-blueprint.d.ts +2 -2
- package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +8 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/text-content.d.ts +8 -0
- package/dist/types/src/capabilities/text-content.d.ts.map +1 -0
- package/dist/types/src/capabilities/transcriber.d.ts +1 -1
- package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
- package/dist/types/src/components/Oracle/Oracle.d.ts +24 -0
- package/dist/types/src/components/Oracle/Oracle.d.ts.map +1 -0
- package/dist/types/src/components/Oracle/Oracle.stories.d.ts +32 -0
- package/dist/types/src/components/Oracle/Oracle.stories.d.ts.map +1 -0
- package/dist/types/src/components/Oracle/index.d.ts +2 -0
- package/dist/types/src/components/Oracle/index.d.ts.map +1 -0
- package/dist/types/src/components/Transcription/Transcription.d.ts +1 -8
- package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -1
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts +20 -23
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -1
- package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.d.ts +6 -0
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.d.ts.map +1 -0
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.stories.d.ts +28 -0
- package/dist/types/src/containers/TranscriptionArticle/TranscriptionArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/TranscriptionArticle/index.d.ts +2 -0
- package/dist/types/src/containers/TranscriptionArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +1 -1
- package/dist/types/src/containers/index.d.ts.map +1 -1
- package/dist/types/src/enrichment/conversation.test.d.ts +2 -0
- package/dist/types/src/enrichment/conversation.test.d.ts.map +1 -0
- package/dist/types/src/enrichment/operations.d.ts +200 -0
- package/dist/types/src/enrichment/operations.d.ts.map +1 -0
- package/dist/types/src/enrichment/parser.d.ts +26 -0
- package/dist/types/src/enrichment/parser.d.ts.map +1 -0
- package/dist/types/src/enrichment/stream-simulator.d.ts +38 -0
- package/dist/types/src/enrichment/stream-simulator.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
- package/dist/types/src/hooks/useAudioTrack.d.ts.map +1 -1
- package/dist/types/src/hooks/useFeedModelAdapter.d.ts +12 -0
- package/dist/types/src/hooks/useFeedModelAdapter.d.ts.map +1 -0
- package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
- package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
- package/dist/types/src/hooks/useTranscriptionRecording.d.ts +12 -0
- package/dist/types/src/hooks/useTranscriptionRecording.d.ts.map +1 -0
- package/dist/types/src/hooks/useVoiceInput.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/model.d.ts +2 -2
- package/dist/types/src/model/model.d.ts.map +1 -1
- package/dist/types/src/{segments-normalization → normalization}/index.d.ts +1 -1
- package/dist/types/src/normalization/index.d.ts.map +1 -0
- package/dist/types/src/{segments-normalization → normalization}/message-normalizer.d.ts +7 -5
- package/dist/types/src/normalization/message-normalizer.d.ts.map +1 -0
- package/dist/types/src/{operations/definitions.d.ts → normalization/normalization.d.ts} +464 -547
- package/dist/types/src/normalization/normalization.d.ts.map +1 -0
- package/dist/types/src/normalization/normalization.test.d.ts.map +1 -0
- package/dist/types/src/normalization/utils.d.ts.map +1 -0
- package/dist/types/src/operations/create.d.ts +3 -3
- package/dist/types/src/operations/create.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +1 -2
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/operations/open.d.ts +3 -3
- package/dist/types/src/operations/open.d.ts.map +1 -1
- package/dist/types/src/operations/summarize.d.ts +3 -3
- package/dist/types/src/operations/summarize.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/stories/FileTranscription.stories.d.ts +20 -0
- package/dist/types/src/stories/FileTranscription.stories.d.ts.map +1 -0
- package/dist/types/src/stories/KeyWordRecognition.stories.d.ts.map +1 -0
- package/dist/types/src/{components/stories/MicrophoneTranscription.stories.d.ts → stories/LiveTranscription.stories.d.ts} +5 -5
- package/dist/types/src/stories/LiveTranscription.stories.d.ts.map +1 -0
- package/dist/types/src/stories/TranscriptionStory.d.ts +21 -0
- package/dist/types/src/stories/TranscriptionStory.d.ts.map +1 -0
- package/dist/types/src/stories/common.d.ts +248 -0
- package/dist/types/src/stories/common.d.ts.map +1 -0
- package/dist/types/src/testing/testing.d.ts +5 -6
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/transcriber/index.d.ts +1 -1
- package/dist/types/src/transcriber/index.d.ts.map +1 -1
- package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcriber.d.ts +58 -3
- package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcriber.test.d.ts +2 -0
- package/dist/types/src/transcriber/transcriber.test.d.ts.map +1 -0
- package/dist/types/src/transcriber/transcription-manager.d.ts +6 -4
- package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +9 -8
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/TranscriptOperation.d.ts +1670 -0
- package/dist/types/src/types/TranscriptOperation.d.ts.map +1 -0
- package/dist/types/src/types/TranscriptionCapabilities.d.ts +17 -0
- package/dist/types/src/types/TranscriptionCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/array.d.ts.map +1 -1
- package/dist/types/src/util/get-time-str.d.ts.map +1 -1
- package/dist/types/src/util/monitor-audio-level.d.ts.map +1 -1
- package/dist/types/src/util/render-byline.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +136 -102
- package/src/TranscriptionPlugin.node.ts +20 -0
- package/src/TranscriptionPlugin.test.ts +31 -0
- package/src/TranscriptionPlugin.tsx +11 -31
- package/src/TranscriptionPlugin.workerd.ts +18 -0
- package/src/blueprints/transcription-blueprint.ts +3 -4
- package/src/capabilities/blueprint-definition.ts +6 -4
- package/src/capabilities/index.ts +9 -2
- package/src/capabilities/operation-handler.ts +1 -1
- package/src/capabilities/react-surface.tsx +2 -2
- package/src/capabilities/text-content.ts +33 -0
- package/src/capabilities/transcriber.ts +9 -5
- package/src/components/Oracle/Oracle.stories.tsx +147 -0
- package/src/components/Oracle/Oracle.tsx +142 -0
- package/src/components/Oracle/index.ts +5 -0
- package/src/components/Transcription/Transcription.stories.tsx +117 -153
- package/src/components/Transcription/Transcription.tsx +8 -17
- package/src/components/index.ts +1 -0
- package/src/containers/TranscriptionArticle/TranscriptionArticle.stories.tsx +61 -0
- package/src/containers/TranscriptionArticle/TranscriptionArticle.tsx +62 -0
- package/src/containers/TranscriptionArticle/index.ts +5 -0
- package/src/containers/index.ts +1 -1
- package/src/enrichment/conversation.test.ts +162 -0
- package/src/enrichment/conversation.txt +23 -0
- package/src/enrichment/operations.ts +271 -0
- package/src/enrichment/parser.ts +101 -0
- package/src/enrichment/stream-simulator.ts +125 -0
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAudioTrack.ts +1 -1
- package/src/hooks/useFeedModelAdapter.ts +46 -0
- package/src/hooks/useTranscriber.ts +7 -5
- package/src/hooks/useTranscriptionRecording.ts +87 -0
- package/src/hooks/useVoiceInput.ts +1 -1
- package/src/index.ts +4 -5
- package/src/meta.ts +28 -6
- package/src/model/model.test.ts +5 -5
- package/src/model/model.ts +3 -3
- package/src/{segments-normalization → normalization}/message-normalizer.ts +25 -17
- package/src/{segments-normalization → normalization}/normalization.test.ts +4 -38
- package/src/{segments-normalization → normalization}/normalization.ts +8 -9
- package/src/operations/create.ts +3 -3
- package/src/operations/index.ts +1 -3
- package/src/operations/open.ts +3 -3
- package/src/operations/summarize.ts +7 -7
- package/src/plugin.ts +11 -0
- package/src/stories/FileTranscription.stories.tsx +143 -0
- package/src/{components/stories → stories}/KeyWordRecognition.stories.tsx +36 -36
- package/src/stories/LiveTranscription.stories.tsx +153 -0
- package/src/stories/TranscriptionStory.tsx +101 -0
- package/src/stories/common.ts +233 -0
- package/src/testing/testing.ts +22 -34
- package/src/transcriber/index.ts +1 -1
- package/src/transcriber/transcriber.test.ts +104 -0
- package/src/transcriber/transcriber.ts +100 -55
- package/src/transcriber/transcription-manager.ts +14 -9
- package/src/translations.ts +3 -0
- package/src/{operations/definitions.ts → types/TranscriptOperation.ts} +14 -9
- package/src/types/TranscriptionCapabilities.ts +39 -0
- package/src/types/index.ts +2 -2
- package/src/vite-env.d.ts +10 -0
- package/dist/lib/browser/blueprints/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-5LWSJZTZ.mjs +0 -17
- package/dist/lib/browser/chunk-5LWSJZTZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-KOX4WNAR.mjs.map +0 -7
- package/dist/lib/browser/create-BTWYQ6IM.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1213
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/open-CYRYIEZI.mjs.map +0 -7
- package/dist/lib/browser/operations/index.mjs +0 -13
- package/dist/lib/browser/operations/index.mjs.map +0 -7
- package/dist/lib/browser/summarize-X2ZYTN7S.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -10
- package/dist/lib/node-esm/blueprints/index.mjs +0 -32
- package/dist/lib/node-esm/blueprints/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-MT5I4NH5.mjs +0 -112
- package/dist/lib/node-esm/chunk-MT5I4NH5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NVM2QUMX.mjs +0 -37
- package/dist/lib/node-esm/chunk-NVM2QUMX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-X74WYCCE.mjs +0 -19
- package/dist/lib/node-esm/chunk-X74WYCCE.mjs.map +0 -7
- package/dist/lib/node-esm/create-MLUFPST2.mjs +0 -22
- package/dist/lib/node-esm/create-MLUFPST2.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1214
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/open-5IOC2U4Z.mjs +0 -28
- package/dist/lib/node-esm/open-5IOC2U4Z.mjs.map +0 -7
- package/dist/lib/node-esm/operations/index.mjs +0 -14
- package/dist/lib/node-esm/operations/index.mjs.map +0 -7
- package/dist/lib/node-esm/summarize-IORITU7T.mjs +0 -80
- package/dist/lib/node-esm/summarize-IORITU7T.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -11
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts +0 -18
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +0 -1
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +0 -1
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +0 -1
- package/dist/types/src/components/stories/TranscriptionStory.d.ts +0 -12
- package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +0 -1
- package/dist/types/src/components/stories/useIsSpeaking.d.ts +0 -3
- package/dist/types/src/components/stories/useIsSpeaking.d.ts.map +0 -1
- package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts +0 -6
- package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +0 -1
- package/dist/types/src/containers/TranscriptionContainer/index.d.ts +0 -2
- package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueueModelAdapter.d.ts +0 -8
- package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +0 -1
- package/dist/types/src/operations/definitions.d.ts.map +0 -1
- package/dist/types/src/segments-normalization/index.d.ts.map +0 -1
- package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +0 -1
- package/dist/types/src/segments-normalization/normalization.d.ts +0 -364
- package/dist/types/src/segments-normalization/normalization.d.ts.map +0 -1
- package/dist/types/src/segments-normalization/normalization.test.d.ts.map +0 -1
- package/dist/types/src/segments-normalization/utils.d.ts.map +0 -1
- package/dist/types/src/types/capabilities.d.ts +0 -18
- package/dist/types/src/types/capabilities.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -5
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/components/stories/FileTranscription.stories.tsx +0 -250
- package/src/components/stories/MicrophoneTranscription.stories.tsx +0 -264
- package/src/components/stories/TranscriptionStory.tsx +0 -43
- package/src/components/stories/useIsSpeaking.tsx +0 -40
- package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +0 -35
- package/src/containers/TranscriptionContainer/index.ts +0 -5
- package/src/hooks/useQueueModelAdapter.ts +0 -66
- package/src/types/capabilities.ts +0 -34
- package/src/types/types.ts +0 -9
- package/dist/lib/{browser/types → neutral/blueprints}/index.mjs.map +0 -0
- package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
- package/dist/lib/{browser/chunk-HOOPZ7EM.mjs.map → neutral/chunk-KAEXRX3Y.mjs.map} +0 -0
- package/dist/lib/{node-esm/types → neutral/hooks}/index.mjs.map +0 -0
- package/dist/lib/{node-esm/chunk-HSLMI22Q.mjs.map → neutral/index.mjs.map} +0 -0
- package/dist/types/src/{segments-normalization → normalization}/normalization.test.d.ts +0 -0
- package/dist/types/src/{segments-normalization → normalization}/utils.d.ts +0 -0
- package/dist/types/src/{components/stories → stories}/KeyWordRecognition.stories.d.ts +0 -0
- package/src/{segments-normalization → normalization}/index.ts +1 -1
- /package/src/{segments-normalization → normalization}/utils.ts +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, {
|
|
6
|
+
type ChangeEvent,
|
|
7
|
+
type Dispatch,
|
|
8
|
+
type RefObject,
|
|
9
|
+
type SetStateAction,
|
|
10
|
+
useCallback,
|
|
11
|
+
useRef,
|
|
12
|
+
} from 'react';
|
|
13
|
+
|
|
14
|
+
import { IconButton, ScrollContainer, Toolbar } from '@dxos/react-ui';
|
|
15
|
+
import { type Message } from '@dxos/types';
|
|
16
|
+
|
|
17
|
+
import { Transcription } from '../components';
|
|
18
|
+
import { type SerializationModel } from '../model';
|
|
19
|
+
|
|
20
|
+
export type TranscriptionStoryProps = {
|
|
21
|
+
audioRef?: RefObject<HTMLAudioElement | null>;
|
|
22
|
+
model: SerializationModel<Message.Message>;
|
|
23
|
+
running: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
uploadAccept?: string;
|
|
26
|
+
onRunningChange: Dispatch<SetStateAction<boolean>>;
|
|
27
|
+
onUpload?: (file: File) => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Story wrapper that renders a transcript with playback controls, an optional audio file
|
|
32
|
+
* upload affordance, and a toolbar slot for additional controls.
|
|
33
|
+
*
|
|
34
|
+
* @param onUpload - Callback fired when the user picks a local audio file via the upload button.
|
|
35
|
+
* @param uploadAccept - HTML `accept` filter for the hidden file input. Defaults to `audio/*`.
|
|
36
|
+
*/
|
|
37
|
+
export const TranscriptionStory = ({
|
|
38
|
+
audioRef,
|
|
39
|
+
model,
|
|
40
|
+
running,
|
|
41
|
+
disabled,
|
|
42
|
+
uploadAccept = 'audio/*',
|
|
43
|
+
onRunningChange,
|
|
44
|
+
onUpload,
|
|
45
|
+
}: TranscriptionStoryProps) => {
|
|
46
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
47
|
+
|
|
48
|
+
const handleFileChange = useCallback(
|
|
49
|
+
(event: ChangeEvent<HTMLInputElement>) => {
|
|
50
|
+
const file = event.target.files?.[0];
|
|
51
|
+
if (file && onUpload) {
|
|
52
|
+
onUpload(file);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Reset so the same file can be re-selected.
|
|
56
|
+
event.target.value = '';
|
|
57
|
+
},
|
|
58
|
+
[onUpload],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{audioRef && <audio ref={audioRef} autoPlay />}
|
|
64
|
+
<Toolbar.Root>
|
|
65
|
+
<IconButton
|
|
66
|
+
iconOnly
|
|
67
|
+
disabled={disabled}
|
|
68
|
+
icon={running ? 'ph--pause--regular' : 'ph--play--regular'}
|
|
69
|
+
label={running ? 'Pause' : 'Play'}
|
|
70
|
+
onClick={() => onRunningChange((running) => !running)}
|
|
71
|
+
/>
|
|
72
|
+
{onUpload && (
|
|
73
|
+
<>
|
|
74
|
+
<input
|
|
75
|
+
ref={fileInputRef}
|
|
76
|
+
type='file'
|
|
77
|
+
accept={uploadAccept}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
className='hidden'
|
|
80
|
+
onChange={handleFileChange}
|
|
81
|
+
/>
|
|
82
|
+
<IconButton
|
|
83
|
+
iconOnly
|
|
84
|
+
disabled={disabled}
|
|
85
|
+
icon='ph--upload--regular'
|
|
86
|
+
label='Upload audio'
|
|
87
|
+
onClick={() => fileInputRef.current?.click()}
|
|
88
|
+
/>
|
|
89
|
+
</>
|
|
90
|
+
)}
|
|
91
|
+
</Toolbar.Root>
|
|
92
|
+
<ScrollContainer.Root pin>
|
|
93
|
+
<ScrollContainer.Content>
|
|
94
|
+
<ScrollContainer.Viewport>
|
|
95
|
+
<Transcription model={model} />
|
|
96
|
+
</ScrollContainer.Viewport>
|
|
97
|
+
</ScrollContainer.Content>
|
|
98
|
+
</ScrollContainer.Root>
|
|
99
|
+
</>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// Helpers shared between LiveTranscription / FileTranscription stories.
|
|
6
|
+
// Each "live" story differs only in its *audio source* (mic vs file); everything else —
|
|
7
|
+
// the local in-memory message buffer, the transcriber lifecycle, and the plugin-manager
|
|
8
|
+
// decorator stack — is identical and lives here.
|
|
9
|
+
|
|
10
|
+
import { type Decorator } from '@storybook/react-vite';
|
|
11
|
+
import * as Effect from 'effect/Effect';
|
|
12
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
|
+
|
|
14
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
15
|
+
import { AppActivationEvents } from '@dxos/app-toolkit';
|
|
16
|
+
import { scheduleTask } from '@dxos/async';
|
|
17
|
+
import { Context } from '@dxos/context';
|
|
18
|
+
import { Obj } from '@dxos/echo';
|
|
19
|
+
import { SpeakingMonitor } from '@dxos/plugin-calls';
|
|
20
|
+
import { ClientPlugin, initializeIdentity } from '@dxos/plugin-client/testing';
|
|
21
|
+
import { PreviewPlugin } from '@dxos/plugin-preview/testing';
|
|
22
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
23
|
+
import { IndexKind } from '@dxos/react-client/echo';
|
|
24
|
+
import { withLayout } from '@dxos/react-ui/testing';
|
|
25
|
+
import { Message, Organization, Person } from '@dxos/types';
|
|
26
|
+
import { seedTestData } from '@dxos/types/testing';
|
|
27
|
+
|
|
28
|
+
import { useFeedModelAdapter, useTranscriber } from '#hooks';
|
|
29
|
+
import { TestItem } from '#testing';
|
|
30
|
+
import { type TranscriptionCapabilities } from '#types';
|
|
31
|
+
|
|
32
|
+
import { type Transcriber, type TranscriberProps } from '../transcriber';
|
|
33
|
+
import { TranscriptionPlugin } from '../TranscriptionPlugin';
|
|
34
|
+
import { renderByline } from '../util';
|
|
35
|
+
|
|
36
|
+
export const useIsSpeaking = (track?: MediaStreamTrack) => {
|
|
37
|
+
const [isSpeaking, setIsSpeaking] = useState(false);
|
|
38
|
+
const speakingMonitor = useMemo(() => {
|
|
39
|
+
if (!track) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return new SpeakingMonitor(track);
|
|
44
|
+
}, [track]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!speakingMonitor) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const ctx = new Context();
|
|
52
|
+
scheduleTask(ctx, async () => {
|
|
53
|
+
speakingMonitor.speakingChanged.on(ctx, () => setIsSpeaking(speakingMonitor.isSpeaking));
|
|
54
|
+
await speakingMonitor.open();
|
|
55
|
+
ctx.onDispose(() => speakingMonitor.close());
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
void ctx.dispose();
|
|
60
|
+
};
|
|
61
|
+
}, [speakingMonitor]);
|
|
62
|
+
|
|
63
|
+
return isSpeaking;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//
|
|
67
|
+
// Message model.
|
|
68
|
+
//
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* In-memory message buffer + model adapter for storybook use (production wires up a real
|
|
72
|
+
* space-backed `Feed`). Returns the renderable `model` plus an `appendMessage` callback.
|
|
73
|
+
*/
|
|
74
|
+
export const useStoryMessageModel = () => {
|
|
75
|
+
const [messages, setMessages] = useState<Message.Message[]>([]);
|
|
76
|
+
const appendMessage = useCallback((message: Message.Message) => setMessages((prev) => [...prev, message]), []);
|
|
77
|
+
const model = useFeedModelAdapter(renderByline([]), messages);
|
|
78
|
+
return { model, appendMessage };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Wraps blocks in a `Message.Message` with the given sender and appends it to the local buffer.
|
|
83
|
+
* Provided as a convenience for stories that don't need entity-extraction or custom enrichment.
|
|
84
|
+
*/
|
|
85
|
+
export const useStoryAppendSegments = (
|
|
86
|
+
appendMessage: (message: Message.Message) => void,
|
|
87
|
+
sender: Message.Message['sender'] = {},
|
|
88
|
+
): TranscriberProps['onSegments'] =>
|
|
89
|
+
useCallback<TranscriberProps['onSegments']>(
|
|
90
|
+
async (blocks) => {
|
|
91
|
+
appendMessage(
|
|
92
|
+
Obj.make(Message.Message, {
|
|
93
|
+
created: new Date().toISOString(),
|
|
94
|
+
sender,
|
|
95
|
+
blocks,
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
[appendMessage, sender],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
//
|
|
103
|
+
// Transcriber lifecycle.
|
|
104
|
+
//
|
|
105
|
+
|
|
106
|
+
export type UseStoryTranscriberOptions = Pick<
|
|
107
|
+
TranscriptionCapabilities.TranscriberProviderProps,
|
|
108
|
+
'transcriberConfig' | 'recorderConfig' | 'onSegments'
|
|
109
|
+
> & {
|
|
110
|
+
audioStreamTrack?: MediaStreamTrack;
|
|
111
|
+
/** Whether the user has the toolbar toggle on. */
|
|
112
|
+
running: boolean;
|
|
113
|
+
/** Voice-activity flag — chunks recording only fires while `true`. */
|
|
114
|
+
isSpeaking: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Drives the transcriber's open/close + chunk-recording lifecycle off `running`,
|
|
119
|
+
* the open flag, and an `isSpeaking` voice-activity gate. Returns the transcriber instance
|
|
120
|
+
* (`undefined` until the capability resolves and an audio track is available).
|
|
121
|
+
*/
|
|
122
|
+
export const useStoryTranscriber = ({
|
|
123
|
+
audioStreamTrack,
|
|
124
|
+
running,
|
|
125
|
+
isSpeaking,
|
|
126
|
+
transcriberConfig,
|
|
127
|
+
recorderConfig,
|
|
128
|
+
onSegments,
|
|
129
|
+
}: UseStoryTranscriberOptions): Transcriber | undefined => {
|
|
130
|
+
const transcriber = useTranscriber({
|
|
131
|
+
audioStreamTrack,
|
|
132
|
+
onSegments,
|
|
133
|
+
transcriberConfig,
|
|
134
|
+
recorderConfig,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Open the transcriber when it becomes available; close on teardown.
|
|
138
|
+
// `tokenRef` is a per-effect identity so a late `close()` completion from a stale
|
|
139
|
+
// transcriber instance can't clobber `isOpen` after a newer instance has opened.
|
|
140
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
141
|
+
const tokenRef = useRef<symbol | null>(null);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!transcriber) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const token = Symbol();
|
|
147
|
+
tokenRef.current = token;
|
|
148
|
+
void transcriber.open().then(
|
|
149
|
+
() => tokenRef.current === token && setIsOpen(true),
|
|
150
|
+
() => tokenRef.current === token && setIsOpen(false),
|
|
151
|
+
);
|
|
152
|
+
return () => {
|
|
153
|
+
void transcriber.close().then(() => {
|
|
154
|
+
if (tokenRef.current === token) {
|
|
155
|
+
setIsOpen(false);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
}, [transcriber]);
|
|
160
|
+
|
|
161
|
+
// Start/stop chunk recording based on running + open + isSpeaking.
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!transcriber || !isOpen) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (running && isSpeaking) {
|
|
167
|
+
transcriber.startChunksRecording();
|
|
168
|
+
} else {
|
|
169
|
+
transcriber.stopChunksRecording();
|
|
170
|
+
}
|
|
171
|
+
}, [transcriber, isOpen, running, isSpeaking]);
|
|
172
|
+
|
|
173
|
+
return transcriber;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//
|
|
177
|
+
// Plugin manager decorator.
|
|
178
|
+
//
|
|
179
|
+
|
|
180
|
+
export type StoryDecoratorsOptions = {
|
|
181
|
+
/**
|
|
182
|
+
* Enable schema/graph/vector indexes after the client boots; needed for entity-extraction
|
|
183
|
+
* queries over seeded `Person` / `Organization` objects.
|
|
184
|
+
* @default false
|
|
185
|
+
*/
|
|
186
|
+
enableVectorIndex?: boolean;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Standard plugin-manager decorator for transcription stories: core plugins,
|
|
191
|
+
* `ClientPlugin` with `Person`/`Organization`/`TestItem` schemas + seeded test data, plus
|
|
192
|
+
* the `PreviewPlugin` and `TranscriptionPlugin`. Toggle `enableVectorIndex` for entity-extraction.
|
|
193
|
+
*/
|
|
194
|
+
export const createStoryDecorators = ({ enableVectorIndex = false }: StoryDecoratorsOptions = {}): Decorator[] => [
|
|
195
|
+
withLayout({ layout: 'column' }),
|
|
196
|
+
withPluginManager({
|
|
197
|
+
plugins: [
|
|
198
|
+
...corePlugins(),
|
|
199
|
+
StorybookPlugin({}),
|
|
200
|
+
ClientPlugin({
|
|
201
|
+
types: [TestItem, Person.Person, Organization.Organization],
|
|
202
|
+
onClientInitialized: ({ client }) =>
|
|
203
|
+
Effect.gen(function* () {
|
|
204
|
+
const { personalSpace } = yield* initializeIdentity(client);
|
|
205
|
+
if (enableVectorIndex) {
|
|
206
|
+
yield* enableQueryIndexes(client.services.services);
|
|
207
|
+
}
|
|
208
|
+
yield* Effect.promise(() => seedTestData(personalSpace));
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
PreviewPlugin(),
|
|
212
|
+
TranscriptionPlugin(),
|
|
213
|
+
],
|
|
214
|
+
fireEvents: [AppActivationEvents.SetupAppGraph],
|
|
215
|
+
}),
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
// TODO(mykola): Make API easier to use.
|
|
219
|
+
// TODO(mykola): Delete after enabling vector indexing by default.
|
|
220
|
+
const enableQueryIndexes = (services: { QueryService?: any }) =>
|
|
221
|
+
Effect.gen(function* () {
|
|
222
|
+
yield* Effect.promise(() =>
|
|
223
|
+
services.QueryService!.setConfig({
|
|
224
|
+
enabled: true,
|
|
225
|
+
indexes: [
|
|
226
|
+
{ kind: IndexKind.Kind.SCHEMA_MATCH },
|
|
227
|
+
{ kind: IndexKind.Kind.GRAPH },
|
|
228
|
+
{ kind: IndexKind.Kind.VECTOR },
|
|
229
|
+
],
|
|
230
|
+
}),
|
|
231
|
+
);
|
|
232
|
+
yield* Effect.promise(() => services.QueryService!.reindex());
|
|
233
|
+
});
|
package/src/testing/testing.ts
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
5
6
|
import * as Schema from 'effect/Schema';
|
|
6
7
|
import { useEffect, useMemo, useState } from 'react';
|
|
7
8
|
|
|
8
9
|
import { extractionAnthropicFunction, processTranscriptMessage } from '@dxos/assistant/extraction';
|
|
9
10
|
import { scheduleTaskInterval } from '@dxos/async';
|
|
10
|
-
import {
|
|
11
|
+
import { createFeedServiceLayer, type Space } from '@dxos/client/echo';
|
|
11
12
|
import { Context } from '@dxos/context';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { DXN, Feed, Filter, Obj, Ref, Type } from '@dxos/echo';
|
|
14
|
+
import { EffectEx } from '@dxos/effect';
|
|
14
15
|
import { IdentityDid } from '@dxos/keys';
|
|
15
16
|
import { log } from '@dxos/log';
|
|
16
17
|
import { random } from '@dxos/random';
|
|
17
|
-
import { type Space, useQueue } from '@dxos/react-client/echo';
|
|
18
18
|
import { TestSchema } from '@dxos/schema/testing';
|
|
19
19
|
import { type ContentBlock, Message, Organization, Person } from '@dxos/types';
|
|
20
20
|
import { seedTestData } from '@dxos/types/testing';
|
|
@@ -29,12 +29,7 @@ export const TestItem = Schema.Struct({
|
|
|
29
29
|
title: 'Description',
|
|
30
30
|
description: 'Product description',
|
|
31
31
|
}),
|
|
32
|
-
}).pipe(
|
|
33
|
-
Type.object({
|
|
34
|
-
typename: 'org.dxos.type.test',
|
|
35
|
-
version: '0.1.0',
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
32
|
+
}).pipe(Type.makeObject(DXN.make('org.dxos.type.test', '0.1.0')));
|
|
38
33
|
|
|
39
34
|
// TODO(wittjosiah): Make builder generic and reuse for all message types.
|
|
40
35
|
abstract class AbstractMessageBuilder {
|
|
@@ -77,7 +72,7 @@ export class MessageBuilder extends AbstractMessageBuilder {
|
|
|
77
72
|
description: random.lorem.paragraph(),
|
|
78
73
|
}),
|
|
79
74
|
);
|
|
80
|
-
const dxn = Ref.make(obj).
|
|
75
|
+
const dxn = Ref.make(obj).uri;
|
|
81
76
|
const words = text.split(' ');
|
|
82
77
|
words.splice(Math.floor(Math.random() * words.length), 0, `[${label}](${dxn})`);
|
|
83
78
|
text = words.join(' ');
|
|
@@ -139,71 +134,64 @@ class EntityExtractionMessageBuilder extends AbstractMessageBuilder {
|
|
|
139
134
|
|
|
140
135
|
type UseTestTranscriptionQueue = (
|
|
141
136
|
space: Space | undefined,
|
|
142
|
-
queueId?: Key.ObjectId,
|
|
143
137
|
running?: boolean,
|
|
144
138
|
interval?: number,
|
|
145
|
-
) =>
|
|
139
|
+
) => Feed.Feed | undefined;
|
|
146
140
|
|
|
147
141
|
/**
|
|
148
|
-
* Test
|
|
142
|
+
* Test transcription feed.
|
|
149
143
|
*/
|
|
150
144
|
export const useTestTranscriptionQueue: UseTestTranscriptionQueue = (
|
|
151
145
|
space: Space | undefined,
|
|
152
|
-
queueId?: Key.ObjectId,
|
|
153
146
|
running = true,
|
|
154
147
|
interval = 1_000,
|
|
155
148
|
) => {
|
|
156
|
-
|
|
157
|
-
const queueDxn = useMemo(() => (space ? createQueueDXN(space.id, queueId) : undefined), [space, queueId]);
|
|
158
|
-
const queue = useQueue<Message.Message>(queueDxn);
|
|
149
|
+
const feed = useMemo(() => (space ? space.db.add(Feed.make({ name: 'transcription' })) : undefined), [space]);
|
|
159
150
|
const builder = useMemo(() => new MessageBuilder(space), [space]);
|
|
160
151
|
|
|
161
152
|
useEffect(() => {
|
|
162
|
-
if (!
|
|
153
|
+
if (!space || !feed || !running) {
|
|
163
154
|
return;
|
|
164
155
|
}
|
|
156
|
+
const feedServiceLayer = createFeedServiceLayer(space.queues);
|
|
165
157
|
|
|
166
158
|
const i = setInterval(() => {
|
|
167
159
|
void builder.createMessage(Math.ceil(Math.random() * 3)).then(async (message) => {
|
|
168
|
-
await
|
|
160
|
+
await Feed.append(feed, [message]).pipe(Effect.provide(feedServiceLayer), EffectEx.runAndForwardErrors);
|
|
169
161
|
});
|
|
170
162
|
}, interval);
|
|
171
163
|
return () => clearInterval(i);
|
|
172
|
-
}, [
|
|
164
|
+
}, [space, feed, running, interval]);
|
|
173
165
|
|
|
174
|
-
return
|
|
166
|
+
return feed;
|
|
175
167
|
};
|
|
176
168
|
|
|
177
169
|
/**
|
|
178
|
-
* Test transcription
|
|
170
|
+
* Test transcription feed with entity extraction.
|
|
179
171
|
*/
|
|
180
172
|
// TODO(burdon): Reconcile with useTestTranscriptionQueue.
|
|
181
173
|
export const useTestTranscriptionQueueWithEntityExtraction: UseTestTranscriptionQueue = (
|
|
182
174
|
space: Space | undefined,
|
|
183
|
-
queueId?: Key.ObjectId,
|
|
184
175
|
running = true,
|
|
185
176
|
interval = 1_000,
|
|
186
177
|
) => {
|
|
187
|
-
|
|
188
|
-
const queueDxn = useMemo(() => (space ? createQueueDXN(space.id, queueId) : undefined), [space, queueId]);
|
|
189
|
-
const queue = useQueue<Message.Message>(queueDxn);
|
|
178
|
+
const feed = useMemo(() => (space ? space.db.add(Feed.make({ name: 'transcription' })) : undefined), [space]);
|
|
190
179
|
const [builder] = useState(() => new EntityExtractionMessageBuilder());
|
|
191
180
|
|
|
192
181
|
useEffect(() => {
|
|
193
|
-
if (!
|
|
182
|
+
if (!space || !feed || !running) {
|
|
194
183
|
return;
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
|
|
198
|
-
void builder.connect(space);
|
|
199
|
-
}
|
|
186
|
+
void builder.connect(space);
|
|
200
187
|
|
|
188
|
+
const feedServiceLayer = createFeedServiceLayer(space.queues);
|
|
201
189
|
const ctx = new Context();
|
|
202
190
|
scheduleTaskInterval(
|
|
203
191
|
ctx,
|
|
204
192
|
async () => {
|
|
205
193
|
const message = await builder.createMessage();
|
|
206
|
-
|
|
194
|
+
await Feed.append(feed, [message]).pipe(Effect.provide(feedServiceLayer), EffectEx.runAndForwardErrors);
|
|
207
195
|
},
|
|
208
196
|
interval,
|
|
209
197
|
);
|
|
@@ -211,7 +199,7 @@ export const useTestTranscriptionQueueWithEntityExtraction: UseTestTranscription
|
|
|
211
199
|
return () => {
|
|
212
200
|
void ctx.dispose();
|
|
213
201
|
};
|
|
214
|
-
}, [space,
|
|
202
|
+
}, [space, feed, running, interval]);
|
|
215
203
|
|
|
216
|
-
return
|
|
204
|
+
return feed;
|
|
217
205
|
};
|
package/src/transcriber/index.ts
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { type AudioChunk } from './audio-recorder';
|
|
8
|
+
import { alignWhisperSegments, type WhisperSegment } from './transcriber';
|
|
9
|
+
|
|
10
|
+
const T0 = Date.parse('2026-01-01T00:00:00.000Z');
|
|
11
|
+
|
|
12
|
+
const chunk = (offsetMs = 0, samples = 16): AudioChunk => ({
|
|
13
|
+
timestamp: T0 + offsetMs,
|
|
14
|
+
data: new Float64Array(samples),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const segment = (overrides: Partial<WhisperSegment>): WhisperSegment => ({
|
|
18
|
+
text: '',
|
|
19
|
+
start: 0,
|
|
20
|
+
end: 0,
|
|
21
|
+
no_speech_prob: 0,
|
|
22
|
+
words: [],
|
|
23
|
+
...overrides,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('alignWhisperSegments', () => {
|
|
27
|
+
test('returns empty when no chunks were transcribed', ({ expect }) => {
|
|
28
|
+
const result = alignWhisperSegments(
|
|
29
|
+
[segment({ text: 'x', end: 1, words: [{ word: 'x', start: 0, end: 1 }] })],
|
|
30
|
+
[],
|
|
31
|
+
0,
|
|
32
|
+
);
|
|
33
|
+
expect(result.transcripts).toEqual([]);
|
|
34
|
+
expect(result.lastTimestamp).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('absolute-timestamps and deduplicates segments against lastTimestamp', ({ expect }) => {
|
|
38
|
+
const segments: WhisperSegment[] = [
|
|
39
|
+
segment({
|
|
40
|
+
text: 'hello world',
|
|
41
|
+
start: 0,
|
|
42
|
+
end: 1,
|
|
43
|
+
words: [
|
|
44
|
+
{ word: 'hello ', start: 0, end: 0.5 },
|
|
45
|
+
{ word: 'world', start: 0.5, end: 1 },
|
|
46
|
+
],
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
const first = alignWhisperSegments(segments, [chunk(0)], 0);
|
|
51
|
+
expect(first.transcripts).toHaveLength(1);
|
|
52
|
+
expect(first.transcripts[0]._tag).toBe('transcript');
|
|
53
|
+
expect(first.transcripts[0].text).toBe('hello world');
|
|
54
|
+
expect(new Date(first.transcripts[0].started).getTime()).toBe(T0);
|
|
55
|
+
expect(first.lastTimestamp).toBe(T0 + 1_000);
|
|
56
|
+
|
|
57
|
+
// Same segments, same chunk start: every word's absolute start is < lastTimestamp -> filtered out.
|
|
58
|
+
const second = alignWhisperSegments(segments, [chunk(0)], first.lastTimestamp!);
|
|
59
|
+
expect(second.transcripts).toEqual([]);
|
|
60
|
+
expect(second.lastTimestamp).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('keeps later words when earlier words fall before lastTimestamp', ({ expect }) => {
|
|
64
|
+
const segments: WhisperSegment[] = [
|
|
65
|
+
segment({
|
|
66
|
+
text: 'old new',
|
|
67
|
+
start: 0,
|
|
68
|
+
end: 2,
|
|
69
|
+
words: [
|
|
70
|
+
{ word: 'old ', start: 0, end: 1 },
|
|
71
|
+
{ word: 'new', start: 1.5, end: 2 },
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
// First word starts at T0, second at T0+1500 — only the second survives a cursor at T0+1000.
|
|
77
|
+
const result = alignWhisperSegments(segments, [chunk(0)], T0 + 1_000);
|
|
78
|
+
expect(result.transcripts).toHaveLength(1);
|
|
79
|
+
expect(result.transcripts[0].text).toBe('new');
|
|
80
|
+
expect(new Date(result.transcripts[0].started).getTime()).toBe(T0 + 1_500);
|
|
81
|
+
expect(result.lastTimestamp).toBe(T0 + 2_000);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('drops segments that end before lastTimestamp', ({ expect }) => {
|
|
85
|
+
const segments: WhisperSegment[] = [
|
|
86
|
+
segment({
|
|
87
|
+
text: 'stale',
|
|
88
|
+
start: 0,
|
|
89
|
+
end: 0.5,
|
|
90
|
+
words: [{ word: 'stale', start: 0, end: 0.5 }],
|
|
91
|
+
}),
|
|
92
|
+
segment({
|
|
93
|
+
text: 'fresh',
|
|
94
|
+
start: 1,
|
|
95
|
+
end: 2,
|
|
96
|
+
words: [{ word: 'fresh', start: 1.5, end: 2 }],
|
|
97
|
+
}),
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
const result = alignWhisperSegments(segments, [chunk(0)], T0 + 1_000);
|
|
101
|
+
expect(result.transcripts).toHaveLength(1);
|
|
102
|
+
expect(result.transcripts[0].text).toBe('fresh');
|
|
103
|
+
});
|
|
104
|
+
});
|