Download runtime/src/mic-worklet.js from cdismus4/chimera-jev-full-duplex: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/cdismus4/chimera-jev-full-duplex/resolve/main/runtime/src/mic-worklet.js
- Command line
-
hf download hf://cdismus4/chimera-jev-full-duplex/runtime/src/mic-worklet.js
-
curl -L -o mic-worklet.js https://huggingface.co/cdismus4/chimera-jev-full-duplex/resolve/main/runtime/src/mic-worklet.js
1.2 kB
| // マイク入力専用の軽量 AudioWorkletProcessor(destination へ一切接続しない)。 | |
| // ScriptProcessorNode のようにメインスレッド停止で AudioContext 再生を巻き込んで | |
| // 音途切れ・無音を起こす問題を避けるため、オーディオ入力タップを独立させる。 | |
| class MicTapProcessor extends AudioWorkletProcessor { | |
| constructor() { | |
| super(); | |
| this.chunkSize = 1024; // 48kHz で約 21.3ms ごとに送出 | |
| this.buf = new Float32Array(this.chunkSize); | |
| this.fill = 0; | |
| } | |
| process(inputs) { | |
| const ch = inputs && inputs[0] && inputs[0][0]; | |
| if (!ch || ch.length === 0) return true; | |
| let off = 0; | |
| while (off < ch.length) { | |
| const take = Math.min(ch.length - off, this.chunkSize - this.fill); | |
| this.buf.set(ch.subarray(off, off + take), this.fill); | |
| this.fill += take; | |
| off += take; | |
| if (this.fill >= this.chunkSize) { | |
| const out = this.buf; | |
| this.port.postMessage({ type: 'pcm', samples: out.buffer }, [out.buffer]); | |
| this.buf = new Float32Array(this.chunkSize); | |
| this.fill = 0; | |
| } | |
| } | |
| return true; | |
| } | |
| } | |
| registerProcessor('mic-tap', MicTapProcessor); | |