@dxos/plugin-transcription 0.8.4-main.9be5663bfe → 0.8.4-main.abd8ff62ef
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/dist/lib/browser/blueprints/index.mjs +1 -1
- package/dist/lib/browser/blueprints/index.mjs.map +3 -3
- package/dist/lib/browser/{chunk-5LWSJZTZ.mjs → chunk-3L623EVL.mjs} +2 -2
- package/dist/lib/browser/chunk-3L623EVL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-HOOPZ7EM.mjs → chunk-KAEXRX3Y.mjs} +1 -1
- package/dist/lib/browser/{chunk-RIUSFL62.mjs → chunk-L4HW35L6.mjs} +4 -5
- package/dist/lib/browser/chunk-L4HW35L6.mjs.map +7 -0
- package/dist/lib/browser/chunk-MLRJWAQH.mjs +179 -0
- package/dist/lib/browser/chunk-MLRJWAQH.mjs.map +7 -0
- package/dist/lib/browser/chunk-NQQK7UZQ.mjs +244 -0
- package/dist/lib/browser/chunk-NQQK7UZQ.mjs.map +7 -0
- package/dist/lib/browser/components/index.mjs +207 -0
- package/dist/lib/browser/components/index.mjs.map +7 -0
- package/dist/lib/browser/{create-IZPB7VZW.mjs → create-ULR5DPJZ.mjs} +6 -4
- package/dist/lib/browser/create-ULR5DPJZ.mjs.map +7 -0
- package/dist/lib/browser/hooks/index.mjs +17 -0
- package/dist/lib/browser/hooks/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +93 -831
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/open-SFMPLZVW.mjs +27 -0
- package/dist/lib/browser/open-SFMPLZVW.mjs.map +7 -0
- package/dist/lib/browser/operations/index.mjs +3 -3
- package/dist/lib/browser/operations/index.mjs.map +3 -3
- package/dist/lib/browser/{summarize-5MZENAU5.mjs → summarize-BDFX4APN.mjs} +15 -8
- package/dist/lib/browser/summarize-BDFX4APN.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/blueprints/index.mjs +1 -1
- package/dist/lib/node-esm/blueprints/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-3GSFEN4L.mjs → chunk-7UIZWCD4.mjs} +4 -5
- package/dist/lib/node-esm/chunk-7UIZWCD4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-C3AE2NYJ.mjs +181 -0
- package/dist/lib/node-esm/chunk-C3AE2NYJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-X74WYCCE.mjs → chunk-KO3IOD2O.mjs} +2 -2
- package/dist/lib/node-esm/chunk-KO3IOD2O.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MQK4R6GT.mjs +245 -0
- package/dist/lib/node-esm/chunk-MQK4R6GT.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NVM2QUMX.mjs → chunk-O533NBMK.mjs} +1 -1
- package/dist/lib/node-esm/components/index.mjs +208 -0
- package/dist/lib/node-esm/components/index.mjs.map +7 -0
- package/dist/lib/node-esm/{create-TQDGXQBL.mjs → create-A5QHNWRF.mjs} +6 -4
- package/dist/lib/node-esm/create-A5QHNWRF.mjs.map +7 -0
- package/dist/lib/node-esm/hooks/index.mjs +18 -0
- package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +93 -831
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/open-OI24QNTO.mjs +28 -0
- package/dist/lib/node-esm/open-OI24QNTO.mjs.map +7 -0
- package/dist/lib/node-esm/operations/index.mjs +3 -3
- package/dist/lib/node-esm/operations/index.mjs.map +3 -3
- package/dist/lib/node-esm/{summarize-RVOSRHEC.mjs → summarize-3UNN24I2.mjs} +15 -8
- package/dist/lib/node-esm/summarize-3UNN24I2.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +1 -1
- 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/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 +2 -2
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +2 -2
- 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/transcriber.d.ts.map +1 -1
- package/dist/types/src/components/Transcription/Transcription.d.ts +1 -1
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts +7 -7
- 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/containers/TranscriptionContainer/TranscriptionContainer.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/useQueueModelAdapter.d.ts.map +1 -1
- 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/useVoiceInput.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.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/normalization/message-normalizer.d.ts.map +1 -0
- package/dist/types/src/{segments-normalization → normalization}/normalization.d.ts +155 -153
- 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 +1 -1
- package/dist/types/src/operations/create.d.ts.map +1 -1
- package/dist/types/src/operations/definitions.d.ts +394 -382
- package/dist/types/src/operations/definitions.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +1 -1
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/operations/open.d.ts +1 -1
- package/dist/types/src/operations/open.d.ts.map +1 -1
- package/dist/types/src/operations/summarize.d.ts +1 -1
- package/dist/types/src/operations/summarize.d.ts.map +1 -1
- package/dist/types/src/{components/stories → stories}/FileTranscription.stories.d.ts +3 -3
- 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 → stories}/MicrophoneTranscription.stories.d.ts +1 -1
- package/dist/types/src/stories/MicrophoneTranscription.stories.d.ts.map +1 -0
- package/dist/types/src/stories/TranscriptionStory.d.ts +23 -0
- package/dist/types/src/stories/TranscriptionStory.d.ts.map +1 -0
- package/dist/types/src/stories/useIsSpeaking.d.ts.map +1 -0
- 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 +57 -2
- 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.map +1 -1
- package/dist/types/src/translations.d.ts +7 -8
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +2 -1
- package/dist/types/src/types/capabilities.d.ts.map +1 -1
- package/dist/types/src/types/{types.d.ts → defs.d.ts} +1 -1
- package/dist/types/src/types/defs.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- 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 +76 -67
- package/src/TranscriptionPlugin.node.ts +48 -0
- package/src/TranscriptionPlugin.test.ts +31 -0
- package/src/TranscriptionPlugin.tsx +7 -3
- package/src/blueprints/transcription-blueprint.ts +2 -3
- package/src/capabilities/blueprint-definition.ts +2 -0
- package/src/capabilities/index.ts +2 -1
- package/src/capabilities/operation-handler.ts +1 -1
- package/src/capabilities/react-surface.tsx +4 -2
- package/src/capabilities/transcriber.ts +2 -0
- package/src/components/Transcription/Transcription.stories.tsx +3 -5
- package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +4 -2
- package/src/hooks/useTranscriber.ts +3 -1
- package/src/index.ts +9 -4
- package/src/model/model.test.ts +3 -3
- package/src/model/model.ts +3 -3
- package/src/{segments-normalization → normalization}/message-normalizer.ts +1 -5
- package/src/{segments-normalization → normalization}/normalization.ts +5 -5
- package/src/operations/create.ts +4 -2
- package/src/operations/definitions.ts +3 -4
- package/src/operations/index.ts +1 -1
- package/src/operations/open.ts +5 -8
- package/src/operations/summarize.ts +11 -7
- package/src/{components/stories → stories}/FileTranscription.stories.tsx +24 -5
- package/src/{components/stories → stories}/KeyWordRecognition.stories.tsx +30 -28
- package/src/{components/stories → stories}/MicrophoneTranscription.stories.tsx +3 -3
- package/src/stories/TranscriptionStory.tsx +93 -0
- package/src/transcriber/index.ts +1 -1
- package/src/transcriber/transcriber.test.ts +104 -0
- package/src/transcriber/transcriber.ts +92 -51
- package/src/types/capabilities.ts +6 -1
- package/src/types/index.ts +1 -1
- package/dist/lib/browser/chunk-5LWSJZTZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-RIUSFL62.mjs.map +0 -7
- package/dist/lib/browser/create-IZPB7VZW.mjs.map +0 -7
- package/dist/lib/browser/open-SN5O5I6X.mjs +0 -29
- package/dist/lib/browser/open-SN5O5I6X.mjs.map +0 -7
- package/dist/lib/browser/summarize-5MZENAU5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3GSFEN4L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-X74WYCCE.mjs.map +0 -7
- package/dist/lib/node-esm/create-TQDGXQBL.mjs.map +0 -7
- package/dist/lib/node-esm/open-4GAAWWKJ.mjs +0 -30
- package/dist/lib/node-esm/open-4GAAWWKJ.mjs.map +0 -7
- package/dist/lib/node-esm/summarize-RVOSRHEC.mjs.map +0 -7
- 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.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.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/types.d.ts.map +0 -1
- package/src/components/stories/TranscriptionStory.tsx +0 -43
- package/dist/lib/browser/{chunk-HOOPZ7EM.mjs.map → chunk-KAEXRX3Y.mjs.map} +0 -0
- package/dist/lib/node-esm/{chunk-NVM2QUMX.mjs.map → chunk-O533NBMK.mjs.map} +0 -0
- package/dist/types/src/{segments-normalization → normalization}/message-normalizer.d.ts +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/dist/types/src/{components/stories → stories}/useIsSpeaking.d.ts +0 -0
- package/src/{segments-normalization → normalization}/index.ts +1 -1
- /package/src/{segments-normalization → normalization}/normalization.test.ts +0 -0
- /package/src/{segments-normalization → normalization}/utils.ts +0 -0
- /package/src/{components/stories → stories}/useIsSpeaking.tsx +0 -0
- /package/src/types/{types.ts → defs.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../chunk-J5LGTIGS.mjs";
|
|
2
2
|
|
|
3
3
|
// src/blueprints/transcription-blueprint.ts
|
|
4
|
-
import { Blueprint, Template } from "@dxos/
|
|
4
|
+
import { Blueprint, Template } from "@dxos/compute";
|
|
5
5
|
import { trim } from "@dxos/util";
|
|
6
6
|
import { TranscriptOperation } from "#operations";
|
|
7
7
|
var BLUEPRINT_KEY = "org.dxos.blueprint.transcription";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/blueprints/transcription-blueprint.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": ";;;
|
|
6
|
-
"names": ["Blueprint", "Template", "trim", "TranscriptOperation", "BLUEPRINT_KEY", "make", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Blueprint, Template } from '@dxos/compute';\nimport { trim } from '@dxos/util';\n\nimport { TranscriptOperation } from '#operations';\n\nconst BLUEPRINT_KEY = 'org.dxos.blueprint.transcription';\n\nconst make = () =>\n Blueprint.make({\n key: BLUEPRINT_KEY,\n name: 'Transcription',\n tools: Blueprint.toolDefinitions({ operations: [TranscriptOperation.Open, TranscriptOperation.Summarize] }),\n instructions: Template.make({\n source: trim`\n You can open and summarize a meeting transcript.\n `,\n }),\n });\n\nconst blueprint: Blueprint.Definition = {\n key: BLUEPRINT_KEY,\n make,\n};\n\nexport default blueprint;\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,WAAWC,gBAAgB;AACpC,SAASC,YAAY;AAErB,SAASC,2BAA2B;AAEpC,IAAMC,gBAAgB;AAEtB,IAAMC,OAAO,MACXL,UAAUK,KAAK;EACbC,KAAKF;EACLG,MAAM;EACNC,OAAOR,UAAUS,gBAAgB;IAAEC,YAAY;MAACP,oBAAoBQ;MAAMR,oBAAoBS;;EAAW,CAAA;EACzGC,cAAcZ,SAASI,KAAK;IAC1BS,QAAQZ;;;EAGV,CAAA;AACF,CAAA;AAEF,IAAMa,YAAkC;EACtCT,KAAKF;EACLC;AACF;AAEA,IAAA,kCAAeU;",
|
|
6
|
+
"names": ["Blueprint", "Template", "trim", "TranscriptOperation", "BLUEPRINT_KEY", "make", "key", "name", "tools", "toolDefinitions", "operations", "Open", "Summarize", "instructions", "source", "blueprint"]
|
|
7
7
|
}
|
|
@@ -7,11 +7,11 @@ import { meta } from "#meta";
|
|
|
7
7
|
})(TranscriptionCapabilities || (TranscriptionCapabilities = {}));
|
|
8
8
|
var TranscriptionCapabilities;
|
|
9
9
|
|
|
10
|
-
// src/types/
|
|
10
|
+
// src/types/defs.ts
|
|
11
11
|
var TRANSCRIPTION_URL = "https://calls-service.dxos.workers.dev";
|
|
12
12
|
|
|
13
13
|
export {
|
|
14
14
|
TranscriptionCapabilities,
|
|
15
15
|
TRANSCRIPTION_URL
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-3L623EVL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/capabilities.ts", "../../../src/types/defs.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capability } from '@dxos/app-framework';\n\nimport { meta } from '#meta';\n\nimport {\n type MediaStreamRecorderProps,\n type Transcriber,\n type TranscriberProps,\n type TranscriptMessageEnricher,\n type TranscriptionManager,\n} from '../transcriber';\n\nexport namespace TranscriptionCapabilities {\n export type GetTranscriberProps = {\n audioStreamTrack: MediaStreamTrack;\n recorderConfig?: Partial<MediaStreamRecorderProps['config']>;\n transcriberConfig?: Partial<TranscriberProps['config']>;\n onSegments: TranscriberProps['onSegments'];\n transcribe?: TranscriberProps['transcribe'];\n };\n\n export type GetTranscriber = (props: GetTranscriberProps) => Transcriber;\n\n export type GetTranscriptionManagerProps = {\n messageEnricher?: TranscriptMessageEnricher;\n };\n\n export type GetTranscriptionManager = (props: GetTranscriptionManagerProps) => TranscriptionManager;\n\n export const Transcriber = Capability.make<GetTranscriber>(`${meta.id}.capability.transcriber`);\n\n export const TranscriptionManager = Capability.make<GetTranscriptionManager>(\n `${meta.id}.capability.transcription-manager`,\n );\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Endpoint to the calls service.\n */\n// TODO(burdon): Reconfigure/move.\nexport const TRANSCRIPTION_URL = 'https://calls-service.dxos.workers.dev';\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,kBAAkB;AAE3B,SAASC,YAAY;UAUJC,4BAAAA;6BAiBFC,cAAcH,WAAWI,KAAqB,GAAGH,KAAKI,EAAE,yBAAyB;6BAEjFC,uBAAuBN,WAAWI,KAC7C,GAAGH,KAAKI,EAAE,mCAAmC;AAEjD,GAtBiBH,8BAAAA,4BAAAA,CAAAA,EAAAA;;;;ACRV,IAAMK,oBAAoB;",
|
|
6
|
+
"names": ["Capability", "meta", "TranscriptionCapabilities", "Transcriber", "make", "id", "TranscriptionManager", "TRANSCRIPTION_URL"]
|
|
7
|
+
}
|
|
@@ -16,9 +16,8 @@ __export(definitions_exports, {
|
|
|
16
16
|
import * as Schema from "effect/Schema";
|
|
17
17
|
import { AiService } from "@dxos/ai";
|
|
18
18
|
import { SpaceSchema } from "@dxos/client/echo";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { Operation } from "@dxos/operation";
|
|
19
|
+
import { Operation } from "@dxos/compute";
|
|
20
|
+
import { Database, Feed, Ref } from "@dxos/echo";
|
|
22
21
|
import { Message, Transcript } from "@dxos/types";
|
|
23
22
|
import { meta } from "#meta";
|
|
24
23
|
var TRANSCRIPT_OPERATION = `${meta.id}.operation`;
|
|
@@ -56,7 +55,7 @@ var Open = Operation.make({
|
|
|
56
55
|
}),
|
|
57
56
|
services: [
|
|
58
57
|
Database.Service,
|
|
59
|
-
|
|
58
|
+
Feed.FeedService
|
|
60
59
|
]
|
|
61
60
|
});
|
|
62
61
|
var Summarize = Operation.make({
|
|
@@ -109,4 +108,4 @@ export {
|
|
|
109
108
|
Summarize,
|
|
110
109
|
definitions_exports
|
|
111
110
|
};
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
111
|
+
//# sourceMappingURL=chunk-L4HW35L6.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/operations/definitions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { AiService } from '@dxos/ai';\nimport { SpaceSchema } from '@dxos/client/echo';\nimport { Operation } from '@dxos/compute';\nimport { Database, Feed, Ref } from '@dxos/echo';\nimport { Message, Transcript } from '@dxos/types';\n\nimport { meta } from '#meta';\n\nconst TRANSCRIPT_OPERATION = `${meta.id}.operation`;\n\nexport const Create = Operation.make({\n meta: { key: `${TRANSCRIPT_OPERATION}.create`, name: 'Create Transcript' },\n input: Schema.Struct({\n name: Schema.optional(Schema.String),\n space: SpaceSchema,\n }),\n output: Schema.Struct({\n object: Transcript.Transcript,\n }),\n});\n\nexport const MessageWithRangeId = Schema.extend(\n Message.Message,\n Schema.Struct({\n rangeId: Schema.optional(Schema.Array(Schema.String)).annotations({\n description: 'The IDs of the messages that contain the sentences.',\n }),\n }),\n);\n\nexport type MessageWithRangeIdType = Schema.Schema.Type<typeof MessageWithRangeId>;\n\nexport const Open = Operation.make({\n meta: {\n key: 'org.dxos.function.transcription.open',\n name: 'Open',\n description: 'Opens and reads the contents of a transcription object.',\n },\n input: Schema.Struct({\n transcript: Ref.Ref(Transcript.Transcript).annotations({\n description: 'The ID of the transcription object.',\n }),\n }),\n output: Schema.Struct({\n content: Schema.String,\n }),\n services: [Database.Service, Feed.FeedService],\n});\n\nexport const Summarize = Operation.make({\n meta: {\n key: 'org.dxos.function.transcription.summarize',\n name: 'Summarize',\n description: 'Summarize a transcript of a meeting.',\n },\n input: Schema.Struct({\n transcript: Schema.String.annotations({\n description: 'The transcript of the meeting.',\n }),\n notes: Schema.optional(Schema.String).annotations({\n description: 'Additional notes from the participants.',\n }),\n }),\n output: Schema.Struct({\n summary: Schema.String.annotations({\n description: 'The summary of the transcript.',\n }),\n }),\n services: [AiService.AiService],\n});\n\nexport const SentenceNormalizationInput = Schema.Struct({\n messages: Schema.Array(MessageWithRangeId).annotations({\n description: 'Messages to normalize into sentences.',\n }),\n});\n\nexport type SentenceNormalizationInputType = Schema.Schema.Type<typeof SentenceNormalizationInput>;\n\nexport const SentenceNormalizationOutput = Schema.Struct({\n sentences: Schema.Array(MessageWithRangeId.pipe(Schema.mutable)).pipe(Schema.mutable).annotations({\n description: 'The sentences of the transcript.',\n }),\n});\n\nexport const SentenceNormalization = Operation.make({\n meta: {\n key: 'org.dxos.function.transcription.sentence-normalization',\n name: 'Sentence Normalization',\n description: 'Post process of transcription for sentence normalization',\n },\n input: SentenceNormalizationInput,\n output: SentenceNormalizationOutput,\n services: [],\n});\n"],
|
|
5
|
+
"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AAY;MACjCC,aAAa;IACf,CAAA;EACF,CAAA;EACAI,UAAU;IAAC/B,UAAUA;;AACvB,CAAA;AAEO,IAAMqC,6BAAoCrB,cAAO;EACtDsB,UAAiBb,aAAMH,kBAAAA,EAAoBI,YAAY;IACrDC,aAAa;EACf,CAAA;AACF,CAAA;AAIO,IAAMY,8BAAqCvB,cAAO;EACvDwB,WAAkBf,aAAMH,mBAAmBmB,KAAYC,cAAO,CAAA,EAAGD,KAAYC,cAAO,EAAEhB,YAAY;IAChGC,aAAa;EACf,CAAA;AACF,CAAA;AAEO,IAAMgB,wBAAwBzC,UAAUU,KAAK;EAClDJ,MAAM;IACJK,KAAK;IACLC,MAAM;IACNa,aAAa;EACf;EACAZ,OAAOsB;EACPjB,QAAQmB;EACRR,UAAU,CAAA;AACZ,CAAA;",
|
|
6
|
+
"names": ["Schema", "AiService", "SpaceSchema", "Operation", "Database", "Feed", "Ref", "Message", "Transcript", "meta", "TRANSCRIPT_OPERATION", "id", "Create", "make", "key", "name", "input", "Struct", "optional", "String", "space", "output", "object", "MessageWithRangeId", "extend", "rangeId", "Array", "annotations", "description", "Open", "transcript", "content", "services", "Service", "FeedService", "Summarize", "notes", "summary", "SentenceNormalizationInput", "messages", "SentenceNormalizationOutput", "sentences", "pipe", "mutable", "SentenceNormalization"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/model/model.ts
|
|
2
|
+
import { Text } from "@codemirror/state";
|
|
3
|
+
import { Event } from "@dxos/async";
|
|
4
|
+
import { invariant } from "@dxos/invariant";
|
|
5
|
+
import { log } from "@dxos/log";
|
|
6
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/model/model.ts";
|
|
7
|
+
var DocumentAdapter = class {
|
|
8
|
+
_view;
|
|
9
|
+
constructor(_view) {
|
|
10
|
+
this._view = _view;
|
|
11
|
+
}
|
|
12
|
+
/** The document must always have at least one line. */
|
|
13
|
+
lineCount() {
|
|
14
|
+
return this._view.state.doc.lines - 1;
|
|
15
|
+
}
|
|
16
|
+
replaceLines(from, remove, insert) {
|
|
17
|
+
log("replaceLines", {
|
|
18
|
+
count: this._view.state.doc.lines,
|
|
19
|
+
from,
|
|
20
|
+
remove,
|
|
21
|
+
insert
|
|
22
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 19, S: this });
|
|
23
|
+
const numLines = this._view.state.doc.lines;
|
|
24
|
+
const posFrom = this._view.state.doc.line(from).from;
|
|
25
|
+
const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;
|
|
26
|
+
let text = insert.join("\n");
|
|
27
|
+
if (posTo === this._view.state.doc.length) {
|
|
28
|
+
text += "\n";
|
|
29
|
+
}
|
|
30
|
+
this._view.dispatch({
|
|
31
|
+
changes: {
|
|
32
|
+
from: posFrom,
|
|
33
|
+
to: posTo,
|
|
34
|
+
insert: text
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var SerializationModel = class {
|
|
40
|
+
_renderer;
|
|
41
|
+
/** Emits when the document is updated. */
|
|
42
|
+
update = new Event();
|
|
43
|
+
/** Ordered set of chunks. */
|
|
44
|
+
_chunks = [];
|
|
45
|
+
/** Map of chunk IDs to their current line counts. */
|
|
46
|
+
_chunkLineCounts = /* @__PURE__ */ new Map();
|
|
47
|
+
/** Map of line numbers to chunk IDs. */
|
|
48
|
+
_lineToChunk = /* @__PURE__ */ new Map();
|
|
49
|
+
/** Track chunk changes since last sync. */
|
|
50
|
+
_changes = [];
|
|
51
|
+
constructor(_renderer, initialChunks = []) {
|
|
52
|
+
this._renderer = _renderer;
|
|
53
|
+
initialChunks.forEach((chunk) => {
|
|
54
|
+
this.appendChunk(chunk);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
toJSON() {
|
|
58
|
+
return {
|
|
59
|
+
chunks: this._chunks.length,
|
|
60
|
+
changes: this._changes.length
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
get doc() {
|
|
64
|
+
return Text.of([
|
|
65
|
+
...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)),
|
|
66
|
+
""
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
get chunks() {
|
|
70
|
+
return this._chunks;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the block ID at the given line number.
|
|
74
|
+
*/
|
|
75
|
+
getChunkAtLine(line) {
|
|
76
|
+
return this._lineToChunk.get(line);
|
|
77
|
+
}
|
|
78
|
+
reset() {
|
|
79
|
+
this._chunks.length = 0;
|
|
80
|
+
this._chunkLineCounts.clear();
|
|
81
|
+
this._lineToChunk.clear();
|
|
82
|
+
this.update.emit();
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
appendChunk(chunk) {
|
|
86
|
+
const index = this._chunks.length;
|
|
87
|
+
this._chunks.push(chunk);
|
|
88
|
+
this._changes.push({
|
|
89
|
+
type: "append",
|
|
90
|
+
index,
|
|
91
|
+
chunk
|
|
92
|
+
});
|
|
93
|
+
this.update.emit();
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
updateChunk(chunk) {
|
|
97
|
+
const index = this._chunks.findIndex((c) => c.id === chunk.id);
|
|
98
|
+
invariant(index !== -1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 102, S: this, A: ["index !== -1", ""] });
|
|
99
|
+
this._chunks[index] = chunk;
|
|
100
|
+
this._changes.push({
|
|
101
|
+
type: "update",
|
|
102
|
+
index,
|
|
103
|
+
chunk
|
|
104
|
+
});
|
|
105
|
+
this.update.emit();
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
deleteBlock(id) {
|
|
109
|
+
const index = this._chunks.findIndex((c) => c.id === id);
|
|
110
|
+
invariant(index !== -1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 114, S: this, A: ["index !== -1", ""] });
|
|
111
|
+
this._chunks.splice(index, 1);
|
|
112
|
+
this._changes.push({
|
|
113
|
+
type: "delete",
|
|
114
|
+
index,
|
|
115
|
+
id
|
|
116
|
+
});
|
|
117
|
+
this.update.emit();
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Syncs the tracked changes with the ChunkDocument.
|
|
122
|
+
*/
|
|
123
|
+
sync(document) {
|
|
124
|
+
log("sync", {
|
|
125
|
+
changes: this._changes
|
|
126
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 127, S: this });
|
|
127
|
+
for (const change of this._changes) {
|
|
128
|
+
switch (change.type) {
|
|
129
|
+
case "append": {
|
|
130
|
+
const lines = this._renderer(change.chunk, change.index);
|
|
131
|
+
const lastLine = document.lineCount();
|
|
132
|
+
document.replaceLines(lastLine + 1, 0, lines);
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case "update": {
|
|
136
|
+
let lineStart = 1;
|
|
137
|
+
for (let i = 0; i < change.index; i++) {
|
|
138
|
+
lineStart += this._chunkLineCounts.get(this._chunks[i].id);
|
|
139
|
+
}
|
|
140
|
+
const previousLineCount = this._chunkLineCounts.get(change.chunk.id);
|
|
141
|
+
const newLines = this._renderer(change.chunk, change.index);
|
|
142
|
+
document.replaceLines(lineStart, previousLineCount, newLines);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case "delete": {
|
|
146
|
+
let lineStart = 1;
|
|
147
|
+
for (let i = 0; i < change.index; i++) {
|
|
148
|
+
lineStart += this._chunkLineCounts.get(this._chunks[i].id);
|
|
149
|
+
}
|
|
150
|
+
const previousLineCount = this._chunkLineCounts.get(change.id);
|
|
151
|
+
document.replaceLines(lineStart, previousLineCount, []);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
this._lineToChunk.clear();
|
|
157
|
+
let currentLine = 1;
|
|
158
|
+
for (const [index, chunk] of this._chunks.entries()) {
|
|
159
|
+
const lineCount = this._renderer(chunk, index).length;
|
|
160
|
+
this._chunkLineCounts.set(chunk.id, lineCount);
|
|
161
|
+
this._lineToChunk.set(currentLine, chunk);
|
|
162
|
+
currentLine += lineCount;
|
|
163
|
+
}
|
|
164
|
+
const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));
|
|
165
|
+
for (const id of this._chunkLineCounts.keys()) {
|
|
166
|
+
if (!chunkIds.has(id)) {
|
|
167
|
+
this._chunkLineCounts.delete(id);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this._changes.length = 0;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export {
|
|
176
|
+
DocumentAdapter,
|
|
177
|
+
SerializationModel
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=chunk-MLRJWAQH.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/model/model.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Text } from '@codemirror/state';\nimport { type EditorView } from '@codemirror/view';\n\nimport { Event } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Chunk = { id: string };\n\n/**\n * Covert block to a set of markdown lines.\n */\nexport type ChunkRenderer<T extends Chunk> = (chunk: T, index: number, debug?: boolean) => string[];\n\n/**\n * Abstract representation of the document model.\n */\nexport interface ChunkDocument {\n lineCount(): number;\n replaceLines(from: number, remove: number, insert: string[]): void;\n}\n\n/**\n * Codemirror document adapter.\n */\nexport class DocumentAdapter implements ChunkDocument {\n constructor(private readonly _view: EditorView) {}\n\n /** The document must always have at least one line. */\n lineCount(): number {\n return this._view.state.doc.lines - 1;\n }\n\n replaceLines(from: number, remove: number, insert: string[]): void {\n log('replaceLines', { count: this._view.state.doc.lines, from, remove, insert });\n\n const numLines = this._view.state.doc.lines;\n const posFrom = this._view.state.doc.line(from).from;\n const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;\n\n // Don't remove the last line.\n let text = insert.join('\\n');\n if (posTo === this._view.state.doc.length) {\n text += '\\n';\n }\n\n this._view.dispatch({\n changes: { from: posFrom, to: posTo, insert: text },\n });\n }\n}\n\ntype ChunkChange<T extends Chunk> =\n | {\n type: 'append';\n index: number;\n chunk: T;\n }\n | {\n type: 'update';\n index: number;\n chunk: T;\n }\n | {\n type: 'delete';\n index: number;\n id: string;\n };\n\n/**\n * Each Chunk can be converted into a set of lines.\n * Chunks can be added, updated or deleted from the Queue.\n * A Document is an immutable projection that represents a flat list of lines corresponding to the Queue.\n *\n * Ideally we would implement a custom virtual Text model for the View, but this currently isn't possible in Codemirror.\n * Instead this model tracks changes and syncs them with the ChunkDocument.\n */\nexport class SerializationModel<T extends Chunk> {\n /** Emits when the document is updated. */\n public readonly update = new Event<void>();\n\n /** Ordered set of chunks. */\n private readonly _chunks: T[] = [];\n\n /** Map of chunk IDs to their current line counts. */\n private readonly _chunkLineCounts = new Map<string, number>();\n\n /** Map of line numbers to chunk IDs. */\n private readonly _lineToChunk = new Map<number, T>();\n\n /** Track chunk changes since last sync. */\n private readonly _changes: Array<ChunkChange<T>> = [];\n\n constructor(\n private readonly _renderer: ChunkRenderer<T>,\n initialChunks: T[] = [],\n ) {\n initialChunks.forEach((chunk) => {\n this.appendChunk(chunk);\n });\n }\n\n toJSON(): { chunks: number; changes: number } {\n return {\n chunks: this._chunks.length,\n changes: this._changes.length,\n };\n }\n\n get doc() {\n return Text.of([...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)), '']);\n }\n\n get chunks() {\n return this._chunks;\n }\n\n /**\n * Get the block ID at the given line number.\n */\n getChunkAtLine(line: number): T | undefined {\n return this._lineToChunk.get(line);\n }\n\n reset(): this {\n this._chunks.length = 0;\n this._chunkLineCounts.clear();\n this._lineToChunk.clear();\n this.update.emit();\n return this;\n }\n\n appendChunk(chunk: T): this {\n const index = this._chunks.length;\n this._chunks.push(chunk);\n this._changes.push({ type: 'append', index, chunk });\n this.update.emit();\n return this;\n }\n\n updateChunk(chunk: T): this {\n const index = this._chunks.findIndex((c) => c.id === chunk.id);\n invariant(index !== -1);\n this._chunks[index] = chunk;\n this._changes.push({ type: 'update', index, chunk });\n this.update.emit();\n return this;\n }\n\n deleteBlock(id: string): this {\n const index = this._chunks.findIndex((c) => c.id === id);\n invariant(index !== -1);\n this._chunks.splice(index, 1);\n this._changes.push({ type: 'delete', index, id });\n this.update.emit();\n return this;\n }\n\n /**\n * Syncs the tracked changes with the ChunkDocument.\n */\n sync(document: ChunkDocument): this {\n log('sync', { changes: this._changes });\n\n // Process each change in order.\n for (const change of this._changes) {\n switch (change.type) {\n case 'append': {\n // For appends, convert block to lines and add at the end.\n const lines = this._renderer(change.chunk, change.index);\n const lastLine = document.lineCount();\n document.replaceLines(lastLine + 1, 0, lines);\n break;\n }\n\n case 'update': {\n // For updates, find the block's line range and replace with new lines.\n let lineStart = 1;\n for (let i = 0; i < change.index; i++) {\n lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;\n }\n const previousLineCount = this._chunkLineCounts.get(change.chunk.id)!;\n const newLines = this._renderer(change.chunk, change.index);\n document.replaceLines(lineStart, previousLineCount, newLines);\n break;\n }\n\n case 'delete': {\n // For deletes, find the block's line range and remove those lines.\n let lineStart = 1;\n for (let i = 0; i < change.index; i++) {\n lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;\n }\n const previousLineCount = this._chunkLineCounts.get(change.id)!;\n document.replaceLines(lineStart, previousLineCount, []);\n break;\n }\n }\n }\n\n // Clear the line-to-block mapping.\n this._lineToChunk.clear();\n\n // Update all block line counts and line-to-block mapping after processing changes.\n let currentLine = 1;\n for (const [index, chunk] of this._chunks.entries()) {\n const lineCount = this._renderer(chunk, index).length;\n this._chunkLineCounts.set(chunk.id, lineCount);\n this._lineToChunk.set(currentLine, chunk);\n currentLine += lineCount;\n }\n\n // Clean up deleted blocks.\n const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));\n for (const id of this._chunkLineCounts.keys()) {\n if (!chunkIds.has(id)) {\n this._chunkLineCounts.delete(id);\n }\n }\n\n // Clear changes after sync.\n this._changes.length = 0;\n return this;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,YAAY;AAGrB,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AAiBpB,IAAA,eAAA;AAIE,IAA6BC,kBAA7B,MAAgD;;EAAC,YAAA,OAAA;AAEjD,SAAA,QAAA;;;EAGA,YAAA;AAEAC,WAAAA,KAAaC,MAAcC,MAAgBC,IAAAA,QAAwB;;eAC3CC,MAAW,QAAOC,QAAS;QAAQJ,gBAAAA;MAAMC,OAAAA,KAAAA,MAAAA,MAAAA,IAAAA;MAAQC;MAAO;MAE9E;IACA,GAAA,EAAA,YAAMG,YAAeP,GAAMM,cAAUE,GAAKN,IAAAA,GAAAA,KAAMA,CAAI;AACpD,UAAMO,WAAQN,KAAAA,MAAW,MAAII,IAAAA;AAE7B,UAAA,UAAA,KAAA,MAAA,MAA8B,IAAA,KAAA,IAAA,EAAA;AAC9B,UAAIG,QAAON,WAAY,IAAA,UAAA,KAAA,MAAA,MAAA,IAAA,KAAA,KAAA,IAAA,UAAA,OAAA,MAAA,CAAA,EAAA;QAErBM,OAAAA,OAAQ,KAAA,IAAA;AACV,QAAA,UAAA,KAAA,MAAA,MAAA,IAAA,QAAA;AAEI,cAAOC;;eACET,SAAMK;eAAaE;QAAOL,MAAAA;QAAa,IAAA;QACpD,QAAA;MACF;IACF,CAAA;EAmBA;;AASE,IAAA,qBAAA,MAAA;EAGA;;EAGA,SAAmD,IAClCQ,MAAAA;;EAEjB,UAAsC,CACrBC;;EAGAC,mBAAqC,oBAAA,IAAA;;EAI7B,eACvB,oBAAA,IAAA;;EAFiBC,WAAAA,CAAAA;cAGjBC,WAAcC,gBAASC,CAAAA,GAAAA;SACrB,YAAKC;AACP,kB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,IAAA,aAAA,KAAA;AAEA,qBAAA;IACA;UAEE,WAAKE,IAAY,IAACZ,KAAK,QAAA,IAAA,CAAA,UAAA,MAAA,EAAA,CAAA;eACrB,MAAKtB,KAAAA,iBAAwBsB,KAAAA,GAAAA;AAC/B,UAAA,CAAA,SAAA,IAAA,EAAA,GAAA;AACF,aAAA,iBAAA,OAAA,EAAA;MAEA;IACA;AAEF,SAAA,SAAA,SAAA;AACF,WAAA;;;",
|
|
6
|
+
"names": ["Text", "Event", "invariant", "log", "_view", "replaceLines", "from", "remove", "insert", "count", "state", "posFrom", "line", "posTo", "text", "dispatch", "_chunkLineCounts", "_lineToChunk", "_changes", "_renderer", "initialChunks", "forEach", "chunk", "appendChunk", "toJSON", "chunks", "changes", "doc", "reset", "clear", "update", "_chunks", "push", "type", "index", "updateChunk", "deleteBlock", "splice", "id", "change", "document", "lastLine", "lines", "lineStart", "previousLineCount", "get", "newLines", "currentLine", "lineCount", "set", "chunkIds"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SerializationModel
|
|
3
|
+
} from "./chunk-MLRJWAQH.mjs";
|
|
4
|
+
|
|
5
|
+
// src/hooks/useAudioFile.ts
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { scheduleTask } from "@dxos/async";
|
|
8
|
+
import { Context } from "@dxos/context";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useAudioFile.ts";
|
|
11
|
+
var useAudioFile = (audioUrl, constraints) => {
|
|
12
|
+
const [{ audio, stream, track }, setStream] = useState({});
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const ctx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 11 });
|
|
15
|
+
scheduleTask(ctx, async () => {
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch(audioUrl);
|
|
18
|
+
const blob = await response.blob();
|
|
19
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
20
|
+
ctx.onDispose(() => {
|
|
21
|
+
URL.revokeObjectURL(objectUrl);
|
|
22
|
+
});
|
|
23
|
+
const audio2 = new Audio();
|
|
24
|
+
audio2.src = objectUrl;
|
|
25
|
+
await new Promise((resolve, reject) => {
|
|
26
|
+
audio2.addEventListener("error", (err) => {
|
|
27
|
+
log.error("error", {
|
|
28
|
+
err
|
|
29
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 25, S: void 0 });
|
|
30
|
+
reject(err);
|
|
31
|
+
}, {
|
|
32
|
+
once: true
|
|
33
|
+
});
|
|
34
|
+
audio2.addEventListener("canplay", async () => {
|
|
35
|
+
resolve();
|
|
36
|
+
}, {
|
|
37
|
+
once: true
|
|
38
|
+
});
|
|
39
|
+
audio2.load();
|
|
40
|
+
});
|
|
41
|
+
const audioCtx = new AudioContext();
|
|
42
|
+
if (audioCtx.state === "suspended") {
|
|
43
|
+
await audioCtx.resume();
|
|
44
|
+
}
|
|
45
|
+
const destination = audioCtx.createMediaStreamDestination();
|
|
46
|
+
destination.channelCount = 1;
|
|
47
|
+
const source = audioCtx.createMediaElementSource(audio2);
|
|
48
|
+
source.connect(destination);
|
|
49
|
+
const track2 = destination.stream.getAudioTracks()[0];
|
|
50
|
+
if (constraints) {
|
|
51
|
+
await track2.applyConstraints(constraints).catch((err) => log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 50, S: void 0 }));
|
|
52
|
+
}
|
|
53
|
+
setStream({
|
|
54
|
+
audio: audio2,
|
|
55
|
+
stream: destination.stream,
|
|
56
|
+
track: destination.stream.getAudioTracks()[0]
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 59, S: void 0 });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return () => {
|
|
63
|
+
void ctx.dispose();
|
|
64
|
+
};
|
|
65
|
+
}, [
|
|
66
|
+
audioUrl
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
audio,
|
|
70
|
+
stream,
|
|
71
|
+
track
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/hooks/useAudioTrack.ts
|
|
76
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
77
|
+
var useAudioTrack = (active, constraints) => {
|
|
78
|
+
const [track, setTrack] = useState2();
|
|
79
|
+
useEffect2(() => {
|
|
80
|
+
if (!active) {
|
|
81
|
+
track?.stop();
|
|
82
|
+
setTrack(void 0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const initAudio = async () => {
|
|
86
|
+
const audio = new Audio();
|
|
87
|
+
audio.srcObject = await navigator.mediaDevices.getUserMedia({
|
|
88
|
+
audio: constraints ?? true
|
|
89
|
+
});
|
|
90
|
+
const [track2] = audio.srcObject.getAudioTracks();
|
|
91
|
+
if (track2) {
|
|
92
|
+
setTrack(track2);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
if (active) {
|
|
96
|
+
void initAudio();
|
|
97
|
+
}
|
|
98
|
+
}, [
|
|
99
|
+
active
|
|
100
|
+
]);
|
|
101
|
+
return track;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/hooks/useQueueModelAdapter.ts
|
|
105
|
+
import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
|
|
106
|
+
var useQueueModelAdapter = (renderer, queue, initialChunks = []) => {
|
|
107
|
+
const model = useMemo(() => new SerializationModel(renderer, initialChunks), [
|
|
108
|
+
queue
|
|
109
|
+
]);
|
|
110
|
+
const [loaded, setLoaded] = useState3(false);
|
|
111
|
+
useEffect3(() => {
|
|
112
|
+
if (!queue) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const update = () => {
|
|
116
|
+
for (const block of queue?.objects ?? []) {
|
|
117
|
+
model.appendChunk(block);
|
|
118
|
+
}
|
|
119
|
+
setLoaded(true);
|
|
120
|
+
};
|
|
121
|
+
let i;
|
|
122
|
+
if (queue.isLoading) {
|
|
123
|
+
i = setInterval(() => {
|
|
124
|
+
if (!queue?.isLoading) {
|
|
125
|
+
clearInterval(i);
|
|
126
|
+
update();
|
|
127
|
+
}
|
|
128
|
+
}, 1e3);
|
|
129
|
+
} else {
|
|
130
|
+
update();
|
|
131
|
+
}
|
|
132
|
+
return () => clearTimeout(i);
|
|
133
|
+
}, [
|
|
134
|
+
model,
|
|
135
|
+
queue
|
|
136
|
+
]);
|
|
137
|
+
useEffect3(() => {
|
|
138
|
+
if (!loaded || !queue || model.chunks.length === queue.objects.length) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const chunk = queue.objects.at(-1);
|
|
142
|
+
if (chunk) {
|
|
143
|
+
model.appendChunk(chunk);
|
|
144
|
+
}
|
|
145
|
+
}, [
|
|
146
|
+
model,
|
|
147
|
+
loaded,
|
|
148
|
+
queue?.objects.length
|
|
149
|
+
]);
|
|
150
|
+
return model;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/hooks/useTranscriber.ts
|
|
154
|
+
import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
|
|
155
|
+
import { useCapabilities } from "@dxos/app-framework/ui";
|
|
156
|
+
import { TranscriptionCapabilities } from "#types";
|
|
157
|
+
var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments, transcribe }) => {
|
|
158
|
+
const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);
|
|
159
|
+
const transcriber = useMemo2(() => {
|
|
160
|
+
if (!getTranscriber || !audioStreamTrack || !onSegments) {
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
return getTranscriber({
|
|
164
|
+
audioStreamTrack,
|
|
165
|
+
recorderConfig,
|
|
166
|
+
transcriberConfig,
|
|
167
|
+
onSegments,
|
|
168
|
+
transcribe
|
|
169
|
+
});
|
|
170
|
+
}, [
|
|
171
|
+
getTranscriber,
|
|
172
|
+
audioStreamTrack,
|
|
173
|
+
recorderConfig,
|
|
174
|
+
transcriberConfig,
|
|
175
|
+
onSegments,
|
|
176
|
+
transcribe
|
|
177
|
+
]);
|
|
178
|
+
useEffect4(() => {
|
|
179
|
+
return () => {
|
|
180
|
+
void transcriber?.close();
|
|
181
|
+
};
|
|
182
|
+
}, [
|
|
183
|
+
transcriber
|
|
184
|
+
]);
|
|
185
|
+
return transcriber;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/hooks/useVoiceInput.ts
|
|
189
|
+
import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
|
|
190
|
+
import { scheduleMicroTask } from "@dxos/async";
|
|
191
|
+
import { Context as Context2 } from "@dxos/context";
|
|
192
|
+
import { log as log2 } from "@dxos/log";
|
|
193
|
+
import { useSoundEffect } from "@dxos/react-ui-sfx";
|
|
194
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
|
|
195
|
+
var useVoiceInput = ({ active, onUpdate }) => {
|
|
196
|
+
const soundStart = useSoundEffect("StartRecording");
|
|
197
|
+
const soundStop = useSoundEffect("StopRecording");
|
|
198
|
+
const handleSegments = useCallback(async (segments) => {
|
|
199
|
+
const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
|
|
200
|
+
onUpdate(text);
|
|
201
|
+
}, []);
|
|
202
|
+
const [recording, setRecording] = useState4(false);
|
|
203
|
+
const track = useAudioTrack(active);
|
|
204
|
+
const transcriber = useTranscriber({
|
|
205
|
+
audioStreamTrack: track,
|
|
206
|
+
onSegments: handleSegments
|
|
207
|
+
});
|
|
208
|
+
useEffect5(() => {
|
|
209
|
+
const ctx = new Context2(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 29 });
|
|
210
|
+
scheduleMicroTask(ctx, async () => {
|
|
211
|
+
if (active && transcriber) {
|
|
212
|
+
await transcriber.open();
|
|
213
|
+
log2.info("starting...", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 33, S: void 0 });
|
|
214
|
+
setRecording(true);
|
|
215
|
+
void soundStart.play();
|
|
216
|
+
transcriber.startChunksRecording();
|
|
217
|
+
} else if (!active && transcriber?.isOpen) {
|
|
218
|
+
transcriber?.stopChunksRecording();
|
|
219
|
+
await transcriber?.close();
|
|
220
|
+
log2.info("stopped", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 40, S: void 0 });
|
|
221
|
+
setRecording(false);
|
|
222
|
+
void soundStop.play();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return () => {
|
|
226
|
+
void ctx.dispose();
|
|
227
|
+
};
|
|
228
|
+
}, [
|
|
229
|
+
active,
|
|
230
|
+
transcriber
|
|
231
|
+
]);
|
|
232
|
+
return {
|
|
233
|
+
recording
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
useAudioFile,
|
|
239
|
+
useAudioTrack,
|
|
240
|
+
useQueueModelAdapter,
|
|
241
|
+
useTranscriber,
|
|
242
|
+
useVoiceInput
|
|
243
|
+
};
|
|
244
|
+
//# sourceMappingURL=chunk-NQQK7UZQ.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useAudioFile.ts", "../../../src/hooks/useAudioTrack.ts", "../../../src/hooks/useQueueModelAdapter.ts", "../../../src/hooks/useTranscriber.ts", "../../../src/hooks/useVoiceInput.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { scheduleTask } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nexport type UseAudioState = {\n audio?: HTMLAudioElement;\n stream?: MediaStream;\n track?: MediaStreamTrack;\n};\n\nexport const useAudioFile = (audioUrl: string, constraints?: MediaTrackConstraints): UseAudioState => {\n const [{ audio, stream, track }, setStream] = useState<UseAudioState>({});\n useEffect(() => {\n const ctx = new Context();\n\n scheduleTask(ctx, async () => {\n // TODO(wittjosiah): Fetch to external url fails in headless storybook test.\n try {\n const response = await fetch(audioUrl);\n const blob = await response.blob();\n const objectUrl = URL.createObjectURL(blob);\n ctx.onDispose(() => {\n URL.revokeObjectURL(objectUrl);\n });\n\n const audio = new Audio();\n audio.src = objectUrl;\n\n await new Promise<void>((resolve, reject) => {\n audio.addEventListener(\n 'error',\n (err) => {\n log.error('error', { err });\n reject(err);\n },\n { once: true },\n );\n audio.addEventListener(\n 'canplay',\n async () => {\n resolve();\n },\n { once: true },\n );\n audio.load();\n });\n\n const audioCtx = new AudioContext();\n\n // Resume AudioContext if it's suspended.\n if (audioCtx.state === 'suspended') {\n await audioCtx.resume();\n }\n\n const destination = audioCtx.createMediaStreamDestination();\n destination.channelCount = 1;\n\n const source = audioCtx.createMediaElementSource(audio);\n source.connect(destination);\n const track = destination.stream.getAudioTracks()[0];\n if (constraints) {\n await track.applyConstraints(constraints).catch((err) => log.catch(err));\n }\n\n // Also connect to speakers so audio is audible.\n setStream({\n audio,\n stream: destination.stream,\n track: destination.stream.getAudioTracks()[0],\n });\n } catch (err) {\n log.catch(err);\n }\n });\n\n return () => {\n void ctx.dispose();\n };\n }, [audioUrl]);\n\n return { audio, stream, track };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\n/**\n *\n */\n// TODO(burdon): Reconcile with react-ui-sfx and plugin-calls.\nexport const useAudioTrack = (active?: boolean, constraints?: MediaTrackConstraints): MediaStreamTrack | undefined => {\n const [track, setTrack] = useState<MediaStreamTrack>();\n useEffect(() => {\n if (!active) {\n track?.stop();\n setTrack(undefined);\n return;\n }\n\n const initAudio = async () => {\n const audio = new Audio();\n audio.srcObject = await navigator.mediaDevices.getUserMedia({ audio: constraints ?? true });\n const [track] = audio.srcObject.getAudioTracks();\n if (track) {\n setTrack(track);\n }\n };\n\n if (active) {\n void initAudio();\n }\n }, [active]);\n\n return track;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo, useState } from 'react';\n\nimport type { Obj } from '@dxos/echo';\nimport { type Queue } from '@dxos/react-client/echo';\n\nimport { type ChunkRenderer, SerializationModel } from '../model';\n\n/**\n * Model adapter for a queue.\n */\nexport const useQueueModelAdapter = <T extends Obj.Unknown>(\n renderer: ChunkRenderer<T>,\n queue: Queue<T> | undefined,\n initialChunks: T[] = [],\n): SerializationModel<T> => {\n const model = useMemo(() => new SerializationModel<T>(renderer, initialChunks), [queue]);\n const [loaded, setLoaded] = useState(false);\n\n // Set initial blocks.\n useEffect(() => {\n if (!queue) {\n return;\n }\n\n const update = () => {\n for (const block of queue?.objects ?? []) {\n model.appendChunk(block);\n }\n\n setLoaded(true);\n };\n\n // TODO(burdon): This is a hack to ensure the queue is loaded.\n let i: NodeJS.Timeout | undefined;\n if (queue.isLoading) {\n i = setInterval(() => {\n if (!queue?.isLoading) {\n clearInterval(i);\n update();\n }\n }, 1_000);\n } else {\n update();\n }\n\n return () => clearTimeout(i);\n }, [model, queue]);\n\n // TODO(burdon): Can we listen for queue events?\n useEffect(() => {\n if (!loaded || !queue || model.chunks.length === queue.objects.length) {\n return;\n }\n\n const chunk = queue.objects.at(-1);\n if (chunk) {\n model.appendChunk(chunk);\n }\n }, [model, loaded, queue?.objects.length]);\n\n return model;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useMemo } from 'react';\n\nimport { useCapabilities } from '@dxos/app-framework/ui';\n\nimport { TranscriptionCapabilities } from '#types';\n\nimport { type Transcriber } from '../transcriber';\n\n/**\n * Records audio while user is speaking and transcribes it after user is done speaking.\n */\nexport const useTranscriber = ({\n audioStreamTrack,\n recorderConfig,\n transcriberConfig,\n onSegments,\n transcribe,\n}: Partial<TranscriptionCapabilities.GetTranscriberProps>) => {\n const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);\n\n // Initialize audio transcription.\n const transcriber = useMemo<Transcriber | undefined>(() => {\n if (!getTranscriber || !audioStreamTrack || !onSegments) {\n return undefined;\n }\n\n return getTranscriber({\n audioStreamTrack,\n recorderConfig,\n transcriberConfig,\n onSegments,\n transcribe,\n });\n }, [getTranscriber, audioStreamTrack, recorderConfig, transcriberConfig, onSegments, transcribe]);\n\n useEffect(() => {\n return () => {\n void transcriber?.close();\n };\n }, [transcriber]);\n\n return transcriber;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { scheduleMicroTask } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { log } from '@dxos/log';\nimport { useSoundEffect } from '@dxos/react-ui-sfx';\n\nimport { type TranscriberProps } from '../transcriber';\nimport { useAudioTrack } from './useAudioTrack';\nimport { useTranscriber } from './useTranscriber';\n\nexport type UseVoiceInputProps = {\n active?: boolean;\n onUpdate: (text: string) => void;\n};\n\n/**\n * Hook for voice input.\n */\nexport const useVoiceInput = ({ active, onUpdate }: UseVoiceInputProps) => {\n const soundStart = useSoundEffect('StartRecording');\n const soundStop = useSoundEffect('StopRecording');\n\n const handleSegments = useCallback<TranscriberProps['onSegments']>(async (segments) => {\n const text = segments.map((str) => str.text.trim().replace(/[^\\w\\s]/g, '')).join(' ');\n onUpdate(text);\n }, []);\n\n // Audio/transcription.\n const [recording, setRecording] = useState(false);\n const track = useAudioTrack(active);\n const transcriber = useTranscriber({\n audioStreamTrack: track,\n onSegments: handleSegments,\n });\n\n // Start/stop transcription.\n useEffect(() => {\n const ctx = new Context();\n scheduleMicroTask(ctx, async () => {\n if (active && transcriber) {\n await transcriber.open();\n log.info('starting...');\n setRecording(true);\n void soundStart.play();\n transcriber.startChunksRecording();\n } else if (!active && transcriber?.isOpen) {\n transcriber?.stopChunksRecording();\n await transcriber?.close();\n log.info('stopped');\n setRecording(false);\n void soundStop.play();\n }\n });\n\n return () => {\n void ct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ACb,QAAAD,KAAA,KAAKjB,WAAc,QAAA,EAAA,YAAA,YAAA,GAAAD,eAAA,GAAA,IAAA,GAAA,OAAA,CAAA;AACrB,qBAAA,KAAA;AACF,aAAA,UAAA,KAAA;MAEA;;AAEA,WAAA,MAAA;AACC,WAAA,IAAA,QAAA;IAACiB;;IAAoB;IAExB;;AAAmB,SAAA;IACnB;;;",
|
|
6
|
+
"names": ["useEffect", "useState", "scheduleTask", "Context", "log", "useAudioFile", "objectUrl", "createObjectURL", "ctx", "onDispose", "URL", "revokeObjectURL", "audio", "Audio", "Promise", "resolve", "addEventListener", "err", "reject", "once", "audioCtx", "state", "destination", "source", "createMediaElementSource", "connect", "track", "constraints", "applyConstraints", "catch", "setStream", "stream", "audioUrl", "useEffect", "useState", "useAudioTrack", "active", "constraints", "track", "setTrack", "stop", "undefined", "initAudio", "audio", "Audio", "srcObject", "navigator", "mediaDevices", "getUserMedia", "getAudioTracks", "useEffect", "useMemo", "useState", "useQueueModelAdapter", "renderer", "queue", "initialChunks", "model", "useMemo", "SerializationModel", "loaded", "setLoaded", "useState", "useEffect", "update", "block", "objects", "appendChunk", "i", "isLoading", "setInterval", "clearInterval", "clearTimeout", "chunks", "length", "chunk", "at", "useEffect", "useMemo", "useCapabilities", "TranscriptionCapabilities", "useTranscriber", "audioStreamTrack", "recorderConfig", "transcriberConfig", "onSegments", "transcribe", "getTranscriber", "Transcriber", "transcriber", "undefined", "close", "useCallback", "useEffect", "useState", "scheduleMicroTask", "Context", "log", "useSoundEffect", "__dxlog_file", "soundStop", "useSoundEffect", "handleSegments", "useCallback", "segments", "str", "trim", "onUpdate", "text", "transcriber", "useTranscriber", "audioStreamTrack", "track", "onSegments", "useEffect", "scheduleMicroTask", "active", "log", "setRecording", "soundStart", "startChunksRecording", "stopChunksRecording", "close"]
|
|
7
|
+
}
|