Spaces:
Running
Running
Download worklet.js from datmt24/tiny-voca-vi: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/datmt24/tiny-voca-vi/resolve/main/worklet.js
- Command line
-
hf download hf://spaces/datmt24/tiny-voca-vi/worklet.js
-
curl -L -o worklet.js https://huggingface.co/spaces/datmt24/tiny-voca-vi/resolve/main/worklet.js
1.34 kB
| // Gapless AudioWorklet playback queue for 24 kHz Float32 PCM chunks. | |
| class PcmQueueProcessor extends AudioWorkletProcessor { | |
| constructor() { | |
| super(); | |
| this.queue = []; | |
| this.offset = 0; | |
| this.playing = false; | |
| this.port.onmessage = ({ data }) => { | |
| if (data.type === "push") { | |
| this.queue.push(data.samples); | |
| this.playing = true; | |
| } else if (data.type === "clear") { | |
| this.queue = []; | |
| this.offset = 0; | |
| this.playing = false; | |
| } | |
| }; | |
| } | |
| process(_inputs, outputs) { | |
| const out = outputs[0][0]; | |
| if (!out) return true; | |
| let written = 0; | |
| while (written < out.length && this.queue.length > 0) { | |
| const cur = this.queue[0]; | |
| const avail = cur.length - this.offset; | |
| const take = Math.min(avail, out.length - written); | |
| out.set(cur.subarray(this.offset, this.offset + take), written); | |
| written += take; | |
| this.offset += take; | |
| if (this.offset >= cur.length) { | |
| this.queue.shift(); | |
| this.offset = 0; | |
| } | |
| } | |
| if (written < out.length) { | |
| out.fill(0, written); | |
| if (this.playing && this.queue.length === 0) { | |
| this.playing = false; | |
| this.port.postMessage({ type: "drained" }); | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| registerProcessor("pcm-queue-processor", PcmQueueProcessor); | |