@dxos/plugin-transformer 0.8.4-main.ead640a → 0.8.4-main.effb148878

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/neutral/TransformerPlugin.mjs +25 -0
  4. package/dist/lib/neutral/TransformerPlugin.mjs.map +7 -0
  5. package/dist/lib/neutral/chunk-YTFCIBAZ.mjs +34 -0
  6. package/dist/lib/neutral/chunk-YTFCIBAZ.mjs.map +7 -0
  7. package/dist/lib/neutral/components/index.mjs +136 -0
  8. package/dist/lib/neutral/components/index.mjs.map +7 -0
  9. package/dist/lib/neutral/hooks/index.mjs +339 -0
  10. package/dist/lib/neutral/hooks/index.mjs.map +7 -0
  11. package/dist/lib/neutral/index.mjs +7 -0
  12. package/dist/lib/neutral/meta.json +1 -0
  13. package/dist/lib/neutral/meta.mjs +7 -0
  14. package/dist/lib/neutral/plugin.mjs +11 -0
  15. package/dist/lib/neutral/plugin.mjs.map +7 -0
  16. package/dist/lib/neutral/translations.mjs +15 -0
  17. package/dist/lib/neutral/translations.mjs.map +7 -0
  18. package/dist/types/src/TransformerPlugin.d.ts +3 -1
  19. package/dist/types/src/TransformerPlugin.d.ts.map +1 -1
  20. package/dist/types/src/TransformerPlugin.test.d.ts +2 -0
  21. package/dist/types/src/TransformerPlugin.test.d.ts.map +1 -0
  22. package/dist/types/src/components/Voice/DebugInfo.d.ts.map +1 -0
  23. package/dist/types/src/components/Voice/Voice.d.ts.map +1 -0
  24. package/dist/types/src/components/Voice/Voice.stories.d.ts.map +1 -0
  25. package/dist/types/src/components/Voice/index.d.ts +3 -0
  26. package/dist/types/src/components/Voice/index.d.ts.map +1 -0
  27. package/dist/types/src/components/index.d.ts +2 -0
  28. package/dist/types/src/components/index.d.ts.map +1 -0
  29. package/dist/types/src/hooks/useAudioStream.d.ts.map +1 -1
  30. package/dist/types/src/hooks/usePipeline.d.ts +1 -16
  31. package/dist/types/src/hooks/usePipeline.d.ts.map +1 -1
  32. package/dist/types/src/index.d.ts +0 -1
  33. package/dist/types/src/index.d.ts.map +1 -1
  34. package/dist/types/src/meta.d.ts +2 -2
  35. package/dist/types/src/meta.d.ts.map +1 -1
  36. package/dist/types/src/plugin.d.ts +3 -0
  37. package/dist/types/src/plugin.d.ts.map +1 -0
  38. package/dist/types/src/testing/node-pipeline.d.ts +1 -1
  39. package/dist/types/src/testing/node-pipeline.d.ts.map +1 -1
  40. package/dist/types/src/testing/pipeline.d.ts.map +1 -1
  41. package/dist/types/src/testing/web-pipeline.d.ts +1 -1
  42. package/dist/types/src/testing/web-pipeline.d.ts.map +1 -1
  43. package/dist/types/src/translations.d.ts +2 -3
  44. package/dist/types/src/translations.d.ts.map +1 -1
  45. package/dist/types/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +77 -50
  47. package/src/TransformerPlugin.test.ts +25 -0
  48. package/src/TransformerPlugin.tsx +13 -23
  49. package/src/components/{DebugInfo.tsx → Voice/DebugInfo.tsx} +3 -3
  50. package/src/components/{Voice.stories.tsx → Voice/Voice.stories.tsx} +2 -2
  51. package/src/components/{Voice.tsx → Voice/Voice.tsx} +1 -1
  52. package/src/components/Voice/index.ts +6 -0
  53. package/src/{capabilities → components}/index.ts +2 -0
  54. package/src/hooks/usePipeline.ts +9 -33
  55. package/src/index.ts +0 -2
  56. package/src/meta.ts +22 -4
  57. package/src/plugin.ts +9 -0
  58. package/src/translations.ts +2 -2
  59. package/dist/lib/browser/index.mjs +0 -50
  60. package/dist/lib/browser/index.mjs.map +0 -7
  61. package/dist/lib/browser/meta.json +0 -1
  62. package/dist/lib/browser/types/index.mjs +0 -1
  63. package/dist/lib/node-esm/index.mjs +0 -52
  64. package/dist/lib/node-esm/index.mjs.map +0 -7
  65. package/dist/lib/node-esm/meta.json +0 -1
  66. package/dist/lib/node-esm/types/index.mjs +0 -2
  67. package/dist/types/src/capabilities/index.d.ts +0 -1
  68. package/dist/types/src/capabilities/index.d.ts.map +0 -1
  69. package/dist/types/src/components/DebugInfo.d.ts.map +0 -1
  70. package/dist/types/src/components/Voice.d.ts.map +0 -1
  71. package/dist/types/src/components/Voice.stories.d.ts.map +0 -1
  72. /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
  73. /package/dist/lib/{node-esm/types/index.mjs.map → neutral/meta.mjs.map} +0 -0
  74. /package/dist/types/src/components/{DebugInfo.d.ts → Voice/DebugInfo.d.ts} +0 -0
  75. /package/dist/types/src/components/{Voice.d.ts → Voice/Voice.d.ts} +0 -0
  76. /package/dist/types/src/components/{Voice.stories.d.ts → Voice/Voice.stories.d.ts} +0 -0
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -12,4 +12,4 @@ Run local transformers.
12
12
 
13
13
  Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
14
14
 
15
- License: [MIT](./LICENSE) Copyright 2023 © DXOS
15
+ License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2023 © DXOS
@@ -0,0 +1,25 @@
1
+ // src/TransformerPlugin.tsx
2
+ import { Plugin } from "@dxos/app-framework";
3
+ import { AppPlugin } from "@dxos/app-toolkit";
4
+ import { meta } from "#meta";
5
+ import { translations } from "#translations";
6
+ var TransformerPlugin = Plugin.define(meta).pipe(
7
+ AppPlugin.addSchemaModule({
8
+ schema: []
9
+ }),
10
+ AppPlugin.addTranslationsModule({
11
+ translations
12
+ }),
13
+ // Plugin.addModule({
14
+ // id: 'intent-resolver',
15
+ // activatesOn: Events.SetupIntentResolver,
16
+ // activate: IntentResolver,
17
+ // }),
18
+ Plugin.make
19
+ );
20
+ var TransformerPlugin_default = TransformerPlugin;
21
+ export {
22
+ TransformerPlugin,
23
+ TransformerPlugin_default as default
24
+ };
25
+ //# sourceMappingURL=TransformerPlugin.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/TransformerPlugin.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Plugin } from '@dxos/app-framework';\nimport { AppPlugin } from '@dxos/app-toolkit';\n\n// import { IntentResolver } from './capabilities';\nimport { meta } from '#meta';\nimport { translations } from '#translations';\n\nexport const TransformerPlugin = Plugin.define(meta).pipe(\n AppPlugin.addSchemaModule({ schema: [] }),\n AppPlugin.addTranslationsModule({ translations }),\n // Plugin.addModule({\n // id: 'intent-resolver',\n // activatesOn: Events.SetupIntentResolver,\n // activate: IntentResolver,\n // }),\n Plugin.make,\n);\n\nexport default TransformerPlugin;\n"],
5
+ "mappings": ";AAIA,SAASA,cAAc;AACvB,SAASC,iBAAiB;AAG1B,SAASC,YAAY;AACrB,SAASC,oBAAoB;AAEtB,IAAMC,oBAAoBJ,OAAOK,OAAOH,IAAAA,EAAMI;EACnDL,UAAUM,gBAAgB;IAAEC,QAAQ,CAAA;EAAG,CAAA;EACvCP,UAAUQ,sBAAsB;IAAEN;EAAa,CAAA;;;;;;EAM/CH,OAAOU;AAAI;AAGb,IAAA,4BAAeN;",
6
+ "names": ["Plugin", "AppPlugin", "meta", "translations", "TransformerPlugin", "define", "pipe", "addSchemaModule", "schema", "addTranslationsModule", "make"]
7
+ }
@@ -0,0 +1,34 @@
1
+ // src/meta.ts
2
+ import { trim } from "@dxos/util";
3
+ var meta = {
4
+ id: "org.dxos.plugin.transformer",
5
+ name: "Transformer",
6
+ author: "DXOS",
7
+ spec: "PLUGIN.mdl",
8
+ description: trim`
9
+ Browser-based machine learning plugin that runs Hugging Face Transformers.js models
10
+ entirely in-browser via WebAssembly and WebGPU — no server-side inference required.
11
+
12
+ Provides automatic speech recognition through a Whisper pipeline hook (usePipeline)
13
+ and a microphone capture hook (useAudioStream) that buffers 16 kHz mono audio into
14
+ 2-second chunks before forwarding them to the model.
15
+
16
+ Exposes a Voice component that wires the two hooks together to deliver live
17
+ transcription, accumulating the running transcript in local state and rendering
18
+ a debug panel with model status, GPU info, and audio level visualisation.
19
+
20
+ Includes a RAG embedding pipeline base class for retrieval-augmented generation
21
+ experiments, with cosine similarity ranking for selecting the most relevant
22
+ knowledge-base contexts before text generation.
23
+ `,
24
+ icon: "ph--cpu--regular",
25
+ source: "https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-transformer",
26
+ tags: [
27
+ "labs"
28
+ ]
29
+ };
30
+
31
+ export {
32
+ meta
33
+ };
34
+ //# sourceMappingURL=chunk-YTFCIBAZ.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Plugin } from '@dxos/app-framework';\nimport { trim } from '@dxos/util';\n\nexport const meta: Plugin.Meta = {\n id: 'org.dxos.plugin.transformer',\n name: 'Transformer',\n author: 'DXOS',\n spec: 'PLUGIN.mdl',\n description: trim`\n Browser-based machine learning plugin that runs Hugging Face Transformers.js models\n entirely in-browser via WebAssembly and WebGPU — no server-side inference required.\n\n Provides automatic speech recognition through a Whisper pipeline hook (usePipeline)\n and a microphone capture hook (useAudioStream) that buffers 16 kHz mono audio into\n 2-second chunks before forwarding them to the model.\n\n Exposes a Voice component that wires the two hooks together to deliver live\n transcription, accumulating the running transcript in local state and rendering\n a debug panel with model status, GPU info, and audio level visualisation.\n\n Includes a RAG embedding pipeline base class for retrieval-augmented generation\n experiments, with cosine similarity ranking for selecting the most relevant\n knowledge-base contexts before text generation.\n `,\n icon: 'ph--cpu--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-transformer',\n tags: ['labs'],\n};\n"],
5
+ "mappings": ";AAKA,SAASA,YAAY;AAEd,IAAMC,OAAoB;EAC/BC,IAAI;EACJC,MAAM;EACNC,QAAQ;EACRC,MAAM;EACNC,aAAaN;;;;;;;;;;;;;;;;EAgBbO,MAAM;EACNC,QAAQ;EACRC,MAAM;IAAC;;AACT;",
6
+ "names": ["trim", "meta", "id", "name", "author", "spec", "description", "icon", "source", "tags"]
7
+ }
@@ -0,0 +1,136 @@
1
+ // src/components/Voice/DebugInfo.tsx
2
+ import React from "react";
3
+ var DebugInfo = ({ error, isModelLoading, stream, isTranscribing, transcription, audioLevel, gpuInfo, model, debug = false }) => {
4
+ return /* @__PURE__ */ React.createElement("div", {
5
+ className: "p-4"
6
+ }, error && /* @__PURE__ */ React.createElement("div", {
7
+ className: "mb-4 text-red-600"
8
+ }, /* @__PURE__ */ React.createElement("strong", null, "Error:"), " ", error), isModelLoading && /* @__PURE__ */ React.createElement("div", {
9
+ className: "mb-4"
10
+ }, /* @__PURE__ */ React.createElement("div", null, "Loading model..."), /* @__PURE__ */ React.createElement("div", {
11
+ className: "text-sm text-gray-500"
12
+ }, "This may take a few moments")), stream ? /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", {
13
+ className: "mb-2 text-green-600"
14
+ }, /* @__PURE__ */ React.createElement("strong", null, "Status:"), " Microphone is active", debug && audioLevel && /* @__PURE__ */ React.createElement("div", {
15
+ className: "mt-2 w-48 h-5 bg-gray-200 rounded-sm relative"
16
+ }, /* @__PURE__ */ React.createElement("div", {
17
+ className: "h-full bg-green-500 transition-all duration-100 rounded-sm",
18
+ style: {
19
+ width: `${audioLevel / 255 * 100}%`
20
+ }
21
+ }))), isTranscribing && /* @__PURE__ */ React.createElement("div", {
22
+ className: "mb-2 text-gray-500"
23
+ }, "Processing audio..."), debug && /* @__PURE__ */ React.createElement("div", {
24
+ className: "mb-4 text-sm text-gray-500 space-y-1"
25
+ }, /* @__PURE__ */ React.createElement("div", null, "Model: ", model), /* @__PURE__ */ React.createElement("div", null, "Sample Rate: 16000 Hz"), /* @__PURE__ */ React.createElement("div", null, "Format: audio/wav"), /* @__PURE__ */ React.createElement("div", null, "Chunk Size: 10 seconds"), /* @__PURE__ */ React.createElement("div", null, "GPU: ", gpuInfo || "Not available"), /* @__PURE__ */ React.createElement("div", null, "Backend: WebGPU")), transcription && /* @__PURE__ */ React.createElement("div", {
26
+ className: "mt-4"
27
+ }, /* @__PURE__ */ React.createElement("strong", null, "Transcription:"), /* @__PURE__ */ React.createElement("p", {
28
+ className: "mt-2 p-4 bg-gray-100 rounded-sm whitespace-pre-wrap"
29
+ }, transcription))) : /* @__PURE__ */ React.createElement("div", null, !isModelLoading && !error && /* @__PURE__ */ React.createElement("div", {
30
+ className: "text-gray-500"
31
+ }, "Microphone is inactive")));
32
+ };
33
+
34
+ // src/components/Voice/Voice.tsx
35
+ import React2, { useCallback, useEffect, useState } from "react";
36
+ import { log } from "@dxos/log";
37
+ import { useAudioStream, usePipeline } from "#hooks";
38
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transformer/src/components/Voice/Voice.tsx";
39
+ var Voice = ({ active, debug, model = "Xenova/whisper-base" }) => {
40
+ const [isTranscribing, setIsTranscribing] = useState(false);
41
+ const [transcription, setTranscription] = useState("");
42
+ const { transcribe, gpuInfo, isLoaded: isModelLoaded, isLoading: isModelLoading, error: pipelineError } = usePipeline({
43
+ active,
44
+ debug,
45
+ model
46
+ });
47
+ const { stream, error: audioError, audioLevel } = useAudioStream({
48
+ active,
49
+ debug
50
+ });
51
+ const handleAudioData = useCallback(async (audioData) => {
52
+ if (!isModelLoaded) {
53
+ return;
54
+ }
55
+ if (isTranscribing) {
56
+ return;
57
+ }
58
+ setIsTranscribing(true);
59
+ try {
60
+ const result = await transcribe(audioData, {
61
+ sampling_rate: 16e3,
62
+ chunk_length_s: 5,
63
+ stride_length_s: 1,
64
+ return_timestamps: false,
65
+ language: "english"
66
+ });
67
+ if (result?.text?.trim()) {
68
+ setTranscription((prev) => prev + " " + result.text);
69
+ }
70
+ } catch (err) {
71
+ log.error("transcription error", {
72
+ err
73
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 40, S: void 0 });
74
+ throw err;
75
+ } finally {
76
+ setIsTranscribing(false);
77
+ }
78
+ }, [
79
+ transcribe,
80
+ isTranscribing
81
+ ]);
82
+ log.info("handleAudioData", {
83
+ handleAudioData
84
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 51, S: void 0 });
85
+ useEffect(() => {
86
+ if (debug) {
87
+ log.info("audio state", {
88
+ hasStream: !!stream,
89
+ audioError,
90
+ audioLevel,
91
+ shouldBeActive: active && isModelLoaded
92
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 56, S: void 0 });
93
+ }
94
+ }, [
95
+ debug,
96
+ stream,
97
+ audioError,
98
+ audioLevel,
99
+ active,
100
+ isModelLoaded
101
+ ]);
102
+ useEffect(() => {
103
+ if (debug) {
104
+ log.info("transcription state", {
105
+ active,
106
+ isModelLoaded,
107
+ isModelLoading,
108
+ isTranscribing,
109
+ pipelineError
110
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 73, S: void 0 });
111
+ }
112
+ }, [
113
+ active,
114
+ debug,
115
+ isModelLoaded,
116
+ isModelLoading,
117
+ pipelineError,
118
+ isTranscribing
119
+ ]);
120
+ return /* @__PURE__ */ React2.createElement(DebugInfo, {
121
+ error: audioError || pipelineError || void 0,
122
+ isModelLoading,
123
+ stream,
124
+ isTranscribing,
125
+ transcription,
126
+ audioLevel,
127
+ gpuInfo,
128
+ model,
129
+ debug
130
+ });
131
+ };
132
+ export {
133
+ DebugInfo,
134
+ Voice
135
+ };
136
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/Voice/DebugInfo.tsx", "../../../../src/components/Voice/Voice.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport React, { type FC } from 'react';\n\nexport type DebugInfoProps = {\n error: string;\n isModelLoading: boolean;\n stream: MediaStream | null;\n isTranscribing: boolean;\n transcription: string;\n audioLevel: number;\n gpuInfo: string;\n model: string;\n debug: boolean;\n};\n\nexport const DebugInfo: FC<Partial<DebugInfoProps>> = ({\n error,\n isModelLoading,\n stream,\n isTranscribing,\n transcription,\n audioLevel,\n gpuInfo,\n model,\n debug = false,\n}) => {\n return (\n <div className='p-4'>\n {error && (\n <div className='mb-4 text-red-600'>\n <strong>Error:</strong> {error}\n </div>\n )}\n {isModelLoading && (\n <div className='mb-4'>\n <div>Loading model...</div>\n <div className='text-sm text-gray-500'>This may take a few moments</div>\n </div>\n )}\n {stream ? (\n <div>\n <div className='mb-2 text-green-600'>\n <strong>Status:</strong> Microphone is active\n {debug && audioLevel && (\n <div className='mt-2 w-48 h-5 bg-gray-200 rounded-sm relative'>\n <div\n className='h-full bg-green-500 transition-all duration-100 rounded-sm'\n style={{ width: `${(audioLevel / 255) * 100}%` }}\n />\n </div>\n )}\n </div>\n {isTranscribing && <div className='mb-2 text-gray-500'>Processing audio...</div>}\n {debug && (\n <div className='mb-4 text-sm text-gray-500 space-y-1'>\n <div>Model: {model}</div>\n <div>Sample Rate: 16000 Hz</div>\n <div>Format: audio/wav</div>\n <div>Chunk Size: 10 seconds</div>\n <div>GPU: {gpuInfo || 'Not available'}</div>\n <div>Backend: WebGPU</div>\n </div>\n )}\n {transcription && (\n <div className='mt-4'>\n <strong>Transcription:</strong>\n <p className='mt-2 p-4 bg-gray-100 rounded-sm whitespace-pre-wrap'>{transcription}</p>\n </div>\n )}\n </div>\n ) : (\n <div>{!isModelLoading && !error && <div className='text-gray-500'>Microphone is inactive</div>}</div>\n )}\n </div>\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport React, { useCallback, useEffect, useState } from 'react';\n\nimport { log } from '@dxos/log';\n\nimport { useAudioStream, usePipeline } from '#hooks';\n\nimport { DebugInfo } from './DebugInfo';\n\nexport type VoiceProps = {\n active?: boolean;\n debug?: boolean;\n model?: string;\n};\n\nexport const Voice = ({ active, debug, model = 'Xenova/whisper-base' }: VoiceProps) => {\n const [isTranscribing, setIsTranscribing] = useState(false);\n const [transcription, setTranscription] = useState<string>('');\n\n const {\n transcribe,\n gpuInfo,\n isLoaded: isModelLoaded,\n isLoading: isModelLoading,\n error: pipelineError,\n } = usePipeline({ active, debug, model });\n\n const {\n stream,\n error: audioError,\n audioLevel,\n } = useAudioStream({\n active,\n debug,\n // onAudioData: handleAudioData\n });\n\n const handleAudioData = useCallback(\n async (audioData: Float32Array) => {\n if (!isModelLoaded) {\n return;\n }\n\n if (isTranscribing) {\n return;\n }\n\n setIsTranscribing(true);\n try {\n const result = await transcribe(audioData, {\n sampling_rate: 16000,\n chunk_length_s: 5,\n stride_length_s: 1,\n return_timestamps: false,\n language: 'english',\n });\n\n if (result?.text?.trim()) {\n setTranscription((prev) => prev + ' ' + result.text);\n }\n } catch (err) {\n log.error('transcription error', { err });\n throw err;\n } finally {\n setIsTranscribing(false);\n }\n },\n [transcribe, isTranscribing],\n );\n log.info('handleAudioData', { handleAudioData });\n\n useEffect(() => {\n if (debug) {\n log.info('audio state', {\n hasStream: !!stream,\n audioError,\n audioLevel,\n shouldBeActive: active && isModelLoaded,\n });\n }\n }, [debug, stream, audioError, audioLevel, active, isModelLoaded]);\n\n useEffect(() => {\n if (debug) {\n log.info('transcription state', {\n active,\n isModelLoaded,\n isModelLoading,\n isTranscribing,\n pipelineError,\n });\n }\n }, [active, debug, isModelLoaded, isModelLoading, pipelineError, isTranscribing]);\n\n return (\n <DebugInfo\n error={audioError || pipelineError || undefined}\n isModelLoading={isModelLoading}\n stream={stream}\n isTranscribing={isTranscribing}\n transcription={transcription}\n audioLevel={audioLevel}\n gpuInfo={gpuInfo}\n model={model}\n debug={debug}\n />\n );\n};\n"],
5
+ "mappings": "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",
6
+ "names": ["React", "DebugInfo", "error", "isModelLoading", "stream", "isTranscribing", "transcription", "audioLevel", "gpuInfo", "model", "debug", "div", "className", "strong", "style", "width", "p", "React", "useCallback", "useEffect", "useState", "log", "useAudioStream", "usePipeline", "Voice", "transcription", "setTranscription", "useState", "gpuInfo", "isModelLoaded", "isLoading", "active", "debug", "model", "isTranscribing", "setIsTranscribing", "result", "chunk_length_s", "stride_length_s", "return_timestamps", "language", "text", "log", "err", "transcribe", "info", "useEffect", "hasStream", "audioError", "audioLevel", "shouldBeActive", "isModelLoading", "pipelineError", "stream"]
7
+ }