Spaces:
Running
Running
Download worker.js from Cis-Labs/forced-aligner: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/Cis-Labs/forced-aligner/resolve/main/worker.js
- Command line
-
hf download hf://spaces/Cis-Labs/forced-aligner/worker.js
-
curl -L -o worker.js https://huggingface.co/spaces/Cis-Labs/forced-aligner/resolve/main/worker.js
1.3 kB
| // Runs the aligner off the main thread so the page stays responsive while the model loads and | |
| // while long recordings are processed window by window. | |
| import { AlignmentError, ForcedAligner } from "./aligner.js"; | |
| let aligner = null; | |
| self.addEventListener("message", async ({ data }) => { | |
| const { id, type } = data; | |
| try { | |
| if (type === "load") { | |
| aligner = await ForcedAligner.load(data.model, { | |
| device: data.device, | |
| dtype: data.dtype, | |
| progress_callback: (p) => self.postMessage({ type: "progress", p }), | |
| }); | |
| // Warm-up: the first run allocates buffers and picks kernels, so the first alignment is fast. | |
| await aligner._logits(new Float32Array(16000)); | |
| self.postMessage({ id, type: "loaded", info: aligner.info }); | |
| } else if (type === "align") { | |
| if (!aligner) throw new Error("The model is not loaded yet."); | |
| const res = await aligner.align(data.wav, data.text, { | |
| ...data.options, | |
| onProgress: (p) => self.postMessage({ id, type: "window", p }), | |
| }); | |
| self.postMessage({ id, type: "result", res: { ...res, unknown: [...res.unknown.entries()] } }); | |
| } | |
| } catch (err) { | |
| self.postMessage({ id, type: "error", message: String(err?.message ?? err), user: err instanceof AlignmentError }); | |
| } | |
| }); | |