@omnimedia/omnitool 1.1.0-3 → 1.1.0-30
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/package.json +15 -10
- package/s/context.ts +0 -7
- package/s/demo/demo.bundle.ts +39 -5
- package/s/demo/demo.css +5 -0
- package/s/demo/routines/filmstrip-test.ts +2 -2
- package/s/demo/routines/transcode-test.ts +8 -4
- package/s/demo/routines/transcriber-test.ts +34 -0
- package/s/demo/routines/transitions-test.ts +43 -0
- package/s/demo/routines/waveform-test.ts +3 -2
- package/s/driver/driver.ts +19 -11
- package/s/driver/fns/host.ts +7 -6
- package/s/driver/fns/schematic.ts +47 -24
- package/s/driver/fns/work.ts +165 -156
- package/s/driver/utils/load-decoder-source.ts +3 -4
- package/s/features/speech/transcribe/default-spec.ts +11 -0
- package/s/features/speech/transcribe/parts/load-pipe.ts +19 -0
- package/s/features/speech/transcribe/parts/prep-audio.ts +23 -0
- package/s/features/speech/transcribe/parts/transcribe.ts +70 -0
- package/s/features/speech/transcribe/transcriber.ts +46 -0
- package/s/features/speech/transcribe/types.ts +82 -0
- package/s/features/speech/transcribe/worker.bundle.ts +40 -0
- package/s/features/transition/parts/fragment.ts +24 -0
- package/s/features/transition/parts/types.ts +94 -0
- package/s/features/transition/parts/uniforms.ts +29 -0
- package/s/features/transition/parts/vertex.ts +31 -0
- package/s/features/transition/transition.ts +60 -0
- package/s/index.html.ts +6 -1
- package/s/timeline/index.ts +1 -0
- package/s/timeline/parts/basics.ts +1 -1
- package/s/timeline/parts/compositor/export.ts +77 -0
- package/s/timeline/parts/compositor/parts/html-tree.ts +37 -0
- package/s/timeline/parts/compositor/parts/schedulers.ts +94 -0
- package/s/timeline/parts/compositor/parts/tree-builder.ts +196 -0
- package/s/timeline/parts/compositor/parts/webcodecs-tree.ts +30 -0
- package/s/timeline/parts/compositor/playback.ts +94 -0
- package/s/timeline/parts/compositor/samplers/html.ts +115 -0
- package/s/timeline/parts/compositor/samplers/webcodecs.ts +61 -0
- package/s/timeline/parts/item.ts +48 -6
- package/s/timeline/parts/media.ts +21 -0
- package/s/timeline/parts/waveform.ts +3 -4
- package/s/timeline/sugar/builders.ts +102 -0
- package/s/timeline/sugar/o.ts +162 -36
- package/s/timeline/sugar/omni-test.ts +5 -3
- package/s/timeline/sugar/omni.ts +26 -11
- package/s/timeline/types.ts +29 -0
- package/s/timeline/utils/audio-stream.ts +15 -0
- package/s/timeline/utils/checksum.ts +2 -1
- package/s/timeline/utils/matrix.ts +33 -0
- package/s/timeline/utils/video-cursor.ts +40 -0
- package/x/context.d.ts +1 -4
- package/x/context.js +1 -5
- package/x/context.js.map +1 -1
- package/x/demo/demo.bundle.js +26 -5
- package/x/demo/demo.bundle.js.map +1 -1
- package/x/demo/demo.bundle.min.js +606 -36
- package/x/demo/demo.bundle.min.js.map +4 -4
- package/x/demo/demo.css +5 -0
- package/x/demo/routines/filmstrip-test.d.ts +1 -1
- package/x/demo/routines/filmstrip-test.js +2 -2
- package/x/demo/routines/filmstrip-test.js.map +1 -1
- package/x/demo/routines/transcode-test.js +8 -4
- package/x/demo/routines/transcode-test.js.map +1 -1
- package/x/demo/routines/transcriber-test.d.ts +4 -0
- package/x/demo/routines/transcriber-test.js +33 -0
- package/x/demo/routines/transcriber-test.js.map +1 -0
- package/x/demo/routines/transitions-test.d.ts +5 -0
- package/x/demo/routines/transitions-test.js +35 -0
- package/x/demo/routines/transitions-test.js.map +1 -0
- package/x/demo/routines/waveform-test.d.ts +2 -1
- package/x/demo/routines/waveform-test.js +2 -2
- package/x/demo/routines/waveform-test.js.map +1 -1
- package/x/driver/driver.d.ts +4 -6
- package/x/driver/driver.js +17 -10
- package/x/driver/driver.js.map +1 -1
- package/x/driver/driver.worker.bundle.min.js +2537 -148
- package/x/driver/driver.worker.bundle.min.js.map +4 -4
- package/x/driver/fns/host.d.ts +9 -2
- package/x/driver/fns/host.js +3 -3
- package/x/driver/fns/host.js.map +1 -1
- package/x/driver/fns/schematic.d.ts +41 -23
- package/x/driver/fns/work.d.ts +11 -4
- package/x/driver/fns/work.js +113 -107
- package/x/driver/fns/work.js.map +1 -1
- package/x/driver/utils/load-decoder-source.d.ts +2 -1
- package/x/driver/utils/load-decoder-source.js +2 -3
- package/x/driver/utils/load-decoder-source.js.map +1 -1
- package/x/features/speech/transcribe/default-spec.d.ts +2 -0
- package/x/features/speech/transcribe/default-spec.js +8 -0
- package/x/features/speech/transcribe/default-spec.js.map +1 -0
- package/x/features/speech/transcribe/parts/load-pipe.d.ts +2 -0
- package/x/features/speech/transcribe/parts/load-pipe.js +13 -0
- package/x/features/speech/transcribe/parts/load-pipe.js.map +1 -0
- package/x/features/speech/transcribe/parts/prep-audio.d.ts +5 -0
- package/x/features/speech/transcribe/parts/prep-audio.js +21 -0
- package/x/features/speech/transcribe/parts/prep-audio.js.map +1 -0
- package/x/features/speech/transcribe/parts/transcribe.d.ts +5 -0
- package/x/features/speech/transcribe/parts/transcribe.js +56 -0
- package/x/features/speech/transcribe/parts/transcribe.js.map +1 -0
- package/x/features/speech/transcribe/transcriber.d.ts +5 -0
- package/x/features/speech/transcribe/transcriber.js +33 -0
- package/x/features/speech/transcribe/transcriber.js.map +1 -0
- package/x/features/speech/transcribe/types.d.ts +66 -0
- package/x/features/speech/transcribe/types.js +2 -0
- package/x/features/speech/transcribe/types.js.map +1 -0
- package/x/features/speech/transcribe/worker.bundle.d.ts +1 -0
- package/x/features/speech/transcribe/worker.bundle.js +33 -0
- package/x/features/speech/transcribe/worker.bundle.js.map +1 -0
- package/x/features/speech/transcribe/worker.bundle.min.js +2916 -0
- package/x/features/speech/transcribe/worker.bundle.min.js.map +7 -0
- package/x/features/transition/parts/fragment.d.ts +1 -0
- package/x/features/transition/parts/fragment.js +25 -0
- package/x/features/transition/parts/fragment.js.map +1 -0
- package/x/features/transition/parts/types.d.ts +23 -0
- package/x/features/transition/parts/types.js +2 -0
- package/x/features/transition/parts/types.js.map +1 -0
- package/x/features/transition/parts/uniforms.d.ts +31 -0
- package/x/features/transition/parts/uniforms.js +27 -0
- package/x/features/transition/parts/uniforms.js.map +1 -0
- package/x/features/transition/parts/vertex.d.ts +1 -0
- package/x/features/transition/parts/vertex.js +32 -0
- package/x/features/transition/parts/vertex.js.map +1 -0
- package/x/features/transition/transition.d.ts +5 -0
- package/x/features/transition/transition.js +50 -0
- package/x/features/transition/transition.js.map +1 -0
- package/x/index.html +13 -3
- package/x/index.html.js +6 -1
- package/x/index.html.js.map +1 -1
- package/x/timeline/index.d.ts +1 -0
- package/x/timeline/index.js +1 -0
- package/x/timeline/index.js.map +1 -1
- package/x/timeline/parts/basics.d.ts +1 -1
- package/x/timeline/parts/compositor/export.d.ts +11 -0
- package/x/timeline/parts/compositor/export.js +64 -0
- package/x/timeline/parts/compositor/export.js.map +1 -0
- package/x/timeline/parts/compositor/parts/html-tree.d.ts +3 -0
- package/x/timeline/parts/compositor/parts/html-tree.js +40 -0
- package/x/timeline/parts/compositor/parts/html-tree.js.map +1 -0
- package/x/timeline/parts/compositor/parts/schedulers.d.ts +15 -0
- package/x/timeline/parts/compositor/parts/schedulers.js +69 -0
- package/x/timeline/parts/compositor/parts/schedulers.js.map +1 -0
- package/x/timeline/parts/compositor/parts/tree-builder.d.ts +37 -0
- package/x/timeline/parts/compositor/parts/tree-builder.js +160 -0
- package/x/timeline/parts/compositor/parts/tree-builder.js.map +1 -0
- package/x/timeline/parts/compositor/parts/webcodecs-tree.d.ts +3 -0
- package/x/timeline/parts/compositor/parts/webcodecs-tree.js +28 -0
- package/x/timeline/parts/compositor/parts/webcodecs-tree.js.map +1 -0
- package/x/timeline/parts/compositor/playback.d.ts +26 -0
- package/x/timeline/parts/compositor/playback.js +79 -0
- package/x/timeline/parts/compositor/playback.js.map +1 -0
- package/x/timeline/parts/compositor/samplers/html.d.ts +3 -0
- package/x/timeline/parts/compositor/samplers/html.js +106 -0
- package/x/timeline/parts/compositor/samplers/html.js.map +1 -0
- package/x/timeline/parts/compositor/samplers/webcodecs.d.ts +3 -0
- package/x/timeline/parts/compositor/samplers/webcodecs.js +52 -0
- package/x/timeline/parts/compositor/samplers/webcodecs.js.map +1 -0
- package/x/timeline/parts/item.d.ts +42 -8
- package/x/timeline/parts/item.js +7 -3
- package/x/timeline/parts/item.js.map +1 -1
- package/x/timeline/parts/media.d.ts +3 -0
- package/x/timeline/parts/media.js +17 -0
- package/x/timeline/parts/media.js.map +1 -1
- package/x/timeline/parts/waveform.d.ts +2 -1
- package/x/timeline/parts/waveform.js +2 -4
- package/x/timeline/parts/waveform.js.map +1 -1
- package/x/timeline/sugar/builders.d.ts +1 -0
- package/x/timeline/sugar/builders.js +104 -0
- package/x/timeline/sugar/builders.js.map +1 -0
- package/x/timeline/sugar/o.d.ts +27 -5
- package/x/timeline/sugar/o.js +135 -36
- package/x/timeline/sugar/o.js.map +1 -1
- package/x/timeline/sugar/omni-test.js +4 -2
- package/x/timeline/sugar/omni-test.js.map +1 -1
- package/x/timeline/sugar/omni.d.ts +8 -2
- package/x/timeline/sugar/omni.js +22 -9
- package/x/timeline/sugar/omni.js.map +1 -1
- package/x/timeline/types.d.ts +24 -0
- package/x/timeline/types.js +2 -0
- package/x/timeline/types.js.map +1 -0
- package/x/timeline/utils/audio-stream.d.ts +6 -0
- package/x/timeline/utils/audio-stream.js +17 -0
- package/x/timeline/utils/audio-stream.js.map +1 -0
- package/x/timeline/utils/checksum.js +2 -1
- package/x/timeline/utils/checksum.js.map +1 -1
- package/x/timeline/utils/matrix.d.ts +8 -0
- package/x/timeline/utils/matrix.js +26 -0
- package/x/timeline/utils/matrix.js.map +1 -0
- package/x/timeline/utils/video-cursor.d.ts +10 -0
- package/x/timeline/utils/video-cursor.js +36 -0
- package/x/timeline/utils/video-cursor.js.map +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { WhisperTextStreamer } from "@huggingface/transformers";
|
|
2
|
+
export async function transcribe(options) {
|
|
3
|
+
const { pipe, spec, request, callbacks } = options;
|
|
4
|
+
if (!pipe.processor.feature_extractor)
|
|
5
|
+
throw new Error("no feature_extractor");
|
|
6
|
+
const timePrecision = (pipe.processor.feature_extractor?.config.chunk_length /
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
pipe.model.config.max_source_positions);
|
|
9
|
+
let chunkCount = 0;
|
|
10
|
+
let startTime = null;
|
|
11
|
+
let tokenCount = 0;
|
|
12
|
+
let tokensPerSecond = 0;
|
|
13
|
+
const chunkDuration = spec.chunkLength - spec.strideLength;
|
|
14
|
+
const calculateProgress = () => {
|
|
15
|
+
const audioProgressSeconds = chunkCount * chunkDuration;
|
|
16
|
+
return Math.min(audioProgressSeconds / request.duration, 1);
|
|
17
|
+
};
|
|
18
|
+
// TODO type error on pipe.tokenizer
|
|
19
|
+
const tokenizer = pipe.tokenizer;
|
|
20
|
+
const streamer = new WhisperTextStreamer(tokenizer, {
|
|
21
|
+
time_precision: timePrecision,
|
|
22
|
+
token_callback_function: () => {
|
|
23
|
+
startTime ??= performance.now();
|
|
24
|
+
if (++tokenCount > 1) {
|
|
25
|
+
tokensPerSecond = (tokenCount / (performance.now() - startTime)) * 1000;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
callback_function: (textChunk) => {
|
|
29
|
+
// TODO
|
|
30
|
+
callbacks.onTranscription(textChunk);
|
|
31
|
+
callbacks.onReport({ tokensPerSecond, progress: calculateProgress() });
|
|
32
|
+
},
|
|
33
|
+
on_finalize: () => {
|
|
34
|
+
startTime = null;
|
|
35
|
+
tokenCount = 0;
|
|
36
|
+
chunkCount++;
|
|
37
|
+
callbacks.onReport({ tokensPerSecond, progress: calculateProgress() });
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const result = await pipe(new Float32Array(request.audio), {
|
|
41
|
+
top_k: 0,
|
|
42
|
+
do_sample: false,
|
|
43
|
+
chunk_length_s: spec.chunkLength,
|
|
44
|
+
stride_length_s: spec.strideLength,
|
|
45
|
+
language: request.language,
|
|
46
|
+
task: "transcribe",
|
|
47
|
+
return_timestamps: "word", // if using "word" the on_chunk_start & end is not called thus we cant retrieve timestamps, only after whole thing finishes
|
|
48
|
+
force_full_sequences: false,
|
|
49
|
+
streamer,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
text: result.text,
|
|
53
|
+
chunks: result.chunks
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=transcribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcribe.js","sourceRoot":"","sources":["../../../../../s/features/speech/transcribe/parts/transcribe.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,2BAA2B,CAAA;AAG7D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAA0B;IAC1D,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAC,GAAG,OAAO,CAAA;IAEhD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB;QACpC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;IAExC,MAAM,aAAa,GAAG,CACrB,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC,YAAY;QACrD,aAAa;QACb,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CACtC,CAAA;IAED,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,SAAS,GAAkB,IAAI,CAAA;IACnC,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,eAAe,GAAG,CAAC,CAAA;IAEvB,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAA;IAE1D,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC9B,MAAM,oBAAoB,GAAG,UAAU,GAAG,aAAa,CAAA;QACvD,OAAO,IAAI,CAAC,GAAG,CAAC,oBAAoB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;IAC5D,CAAC,CAA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IAEF,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAM,CAAC,MAAM;KACrB,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TranscriberOptions, TranscriptionOptions } from "./types.js";
|
|
2
|
+
export declare function makeTranscriber({ driver, spec, workerUrl, onLoading }: TranscriberOptions): Promise<{
|
|
3
|
+
transcribe: (info: TranscriptionOptions) => Promise<import("./types.js").Transcription>;
|
|
4
|
+
dispose: void;
|
|
5
|
+
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Comrade } from "@e280/comrade";
|
|
2
|
+
import { coalesce, queue, sub } from "@e280/stz";
|
|
3
|
+
import { prepAudio } from "./parts/prep-audio.js";
|
|
4
|
+
export async function makeTranscriber({ driver, spec, workerUrl, onLoading }) {
|
|
5
|
+
const onReport = sub();
|
|
6
|
+
const onTranscription = sub();
|
|
7
|
+
const thread = await Comrade.thread({
|
|
8
|
+
label: "OmnitoolSpeechTranscriber",
|
|
9
|
+
workerUrl,
|
|
10
|
+
setupHost: () => ({
|
|
11
|
+
loading: async (loading) => onLoading(loading),
|
|
12
|
+
deliverReport: async (report) => onReport.pub(report),
|
|
13
|
+
deliverTranscription: async (transcription) => onTranscription.pub(transcription),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
await thread.work.prepare(spec);
|
|
17
|
+
return {
|
|
18
|
+
transcribe: queue(async (info) => {
|
|
19
|
+
const { source, language } = info;
|
|
20
|
+
const { audio, duration } = await prepAudio(driver, source);
|
|
21
|
+
const detachCallbacks = coalesce(onReport(info.onReport), onTranscription(info.onTranscription));
|
|
22
|
+
const result = await thread.work.transcribe({
|
|
23
|
+
duration,
|
|
24
|
+
language,
|
|
25
|
+
audio: audio.buffer,
|
|
26
|
+
});
|
|
27
|
+
detachCallbacks();
|
|
28
|
+
return result;
|
|
29
|
+
}),
|
|
30
|
+
dispose: thread.terminate()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=transcriber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcriber.js","sourceRoot":"","sources":["../../../../s/features/speech/transcribe/transcriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AAE9C,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAA;AAG/C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAqB;IAC7F,MAAM,QAAQ,GAAG,GAAG,EAAiC,CAAA;IACrD,MAAM,eAAe,GAAG,GAAG,EAA2B,CAAA;IAEtD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAuB;QACzD,KAAK,EAAE,2BAA2B;QAClC,SAAS;QACT,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;YACjB,OAAO,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;YAC5C,aAAa,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;YACnD,oBAAoB,EAAE,KAAK,EAAC,aAAa,EAAC,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,aAAa,CAAC;SAC/E,CAAC;KACF,CAAC,CAAA;IAEF,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/B,OAAO;QACN,UAAU,EAAE,KAAK,CAAC,KAAK,EAAC,IAA0B,EAAE,EAAE;YACrD,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAA;YAC/B,MAAM,EAAC,KAAK,EAAE,QAAQ,EAAC,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAEzD,MAAM,eAAe,GAAG,QAAQ,CAC/B,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EACvB,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,CACrC,CAAA;YAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;gBAC3C,QAAQ;gBACR,QAAQ;gBACR,KAAK,EAAE,KAAK,CAAC,MAAM;aACnB,CAAC,CAAA;YAEF,eAAe,EAAE,CAAA;YACjB,OAAO,MAAM,CAAA;QACd,CAAC,CAAC;QACF,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE;KAC3B,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AsSchematic } from "@e280/comrade";
|
|
2
|
+
import { DataType, DeviceType, Pipeline } from "@huggingface/transformers";
|
|
3
|
+
import { Driver } from "../../../driver/driver.js";
|
|
4
|
+
export type TranscriberSchematic = AsSchematic<{
|
|
5
|
+
work: {
|
|
6
|
+
prepare(spec: TranscriberSpec): Promise<void>;
|
|
7
|
+
transcribe(request: TranscriptionRequest): Promise<Transcription>;
|
|
8
|
+
};
|
|
9
|
+
host: {
|
|
10
|
+
loading(load: Loading): Promise<void>;
|
|
11
|
+
deliverReport(report: TranscriptionReport): Promise<void>;
|
|
12
|
+
deliverTranscription(transcription: string): Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export type Loading = {
|
|
16
|
+
total: number;
|
|
17
|
+
progress: number;
|
|
18
|
+
};
|
|
19
|
+
export type TranscribeOptions = {
|
|
20
|
+
pipe: Pipeline;
|
|
21
|
+
spec: TranscriberSpec;
|
|
22
|
+
request: TranscriptionRequest;
|
|
23
|
+
callbacks: TranscriptionCallbacks;
|
|
24
|
+
};
|
|
25
|
+
export type TranscriberPipeOptions = {
|
|
26
|
+
spec: TranscriberSpec;
|
|
27
|
+
onLoading: (loading: Loading) => void;
|
|
28
|
+
};
|
|
29
|
+
export type SpeechTime = [start: number, end: number];
|
|
30
|
+
export type Transcription = {
|
|
31
|
+
text: string;
|
|
32
|
+
chunks: {
|
|
33
|
+
text: string;
|
|
34
|
+
timestamp: SpeechTime;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
export type TranscriberSpec = {
|
|
38
|
+
model: string;
|
|
39
|
+
dtype: DataType;
|
|
40
|
+
device: DeviceType;
|
|
41
|
+
chunkLength: number;
|
|
42
|
+
strideLength: number;
|
|
43
|
+
};
|
|
44
|
+
export type TranscriptionOptions = {
|
|
45
|
+
source: Blob;
|
|
46
|
+
language: string | null;
|
|
47
|
+
} & TranscriptionCallbacks;
|
|
48
|
+
export type TranscriptionRequest = {
|
|
49
|
+
audio: ArrayBufferLike;
|
|
50
|
+
language: string | null;
|
|
51
|
+
duration: number;
|
|
52
|
+
};
|
|
53
|
+
export type TranscriptionReport = {
|
|
54
|
+
progress: number;
|
|
55
|
+
tokensPerSecond: number;
|
|
56
|
+
};
|
|
57
|
+
export type TranscriptionCallbacks = {
|
|
58
|
+
onReport: (report: TranscriptionReport) => void;
|
|
59
|
+
onTranscription: (transcription: string) => void;
|
|
60
|
+
};
|
|
61
|
+
export type TranscriberOptions = {
|
|
62
|
+
driver: Driver;
|
|
63
|
+
spec: TranscriberSpec;
|
|
64
|
+
workerUrl: URL | string;
|
|
65
|
+
onLoading: (loading: Loading) => void;
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../s/features/speech/transcribe/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defer, once } from "@e280/stz";
|
|
2
|
+
import { Comrade } from "@e280/comrade";
|
|
3
|
+
import { loadPipe } from "./parts/load-pipe.js";
|
|
4
|
+
import { transcribe } from "./parts/transcribe.js";
|
|
5
|
+
const deferred = defer();
|
|
6
|
+
const makePrepare = (host) => once(async (spec) => {
|
|
7
|
+
deferred.resolve({
|
|
8
|
+
spec,
|
|
9
|
+
pipe: await loadPipe({
|
|
10
|
+
spec,
|
|
11
|
+
onLoading: loading => host.loading(loading),
|
|
12
|
+
}),
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
await Comrade.worker(shell => {
|
|
16
|
+
const prepare = makePrepare(shell.host);
|
|
17
|
+
return {
|
|
18
|
+
prepare,
|
|
19
|
+
async transcribe(request) {
|
|
20
|
+
const { pipe, spec } = await deferred.promise;
|
|
21
|
+
return transcribe({
|
|
22
|
+
pipe,
|
|
23
|
+
spec,
|
|
24
|
+
request,
|
|
25
|
+
callbacks: {
|
|
26
|
+
onReport: report => shell.host.deliverReport(report),
|
|
27
|
+
onTranscription: transcription => shell.host.deliverTranscription(transcription),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=worker.bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.bundle.js","sourceRoot":"","sources":["../../../../s/features/speech/transcribe/worker.bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,WAAW,CAAA;AACrC,OAAO,EAAC,OAAO,EAAO,MAAM,eAAe,CAAA;AAG3C,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAA;AAGhD,MAAM,QAAQ,GAAG,KAAK,EAA2C,CAAA;AAEjE,MAAM,WAAW,GAAG,CAAC,IAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAC,IAAqB,EAAE,EAAE;IAC7F,QAAQ,CAAC,OAAO,CAAC;QAChB,IAAI;QACJ,IAAI,EAAE,MAAM,QAAQ,CAAC;YACpB,IAAI;YACJ,SAAS,EAAE,OAA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