@oonacode/darwin-x64 0.3.400 → 0.3.406
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/oona +2 -2
- package/package.json +1 -1
- package/web-ui/artifact-vendor/favicon.svg +1 -0
- package/web-ui/artifact-vendor/react-runtime.js +34 -0
- package/web-ui/artifact-vendor/voice-worklets.js +84 -0
- package/web-ui/assets/index-DE7Ltnpz.js +931 -0
- package/web-ui/assets/index-SyB_E4Wm.css +2 -0
- package/web-ui/index.html +2 -2
- package/web-ui/assets/index-emRQCMYP.css +0 -2
- package/web-ui/assets/index-sJ81ZN4S.js +0 -559
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Talk to a chat — the two audio worklets (docs/voice-assistant.md §3). A plain script of the app's own
|
|
3
|
+
* origin: the desktop window's content policy is `script-src 'self'`, and a worklet module is a script.
|
|
4
|
+
*
|
|
5
|
+
* Each runs in an AudioContext made at the rate the wire uses, so nothing is resampled here: the browser
|
|
6
|
+
* brings the microphone to 16 kHz and plays 24 kHz itself.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** The microphone → 16-bit PCM chunks of 40 ms, each with its level (RMS, 0–1). */
|
|
10
|
+
class OonaCapture extends AudioWorkletProcessor {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.size = Math.round(sampleRate * 0.04);
|
|
14
|
+
this.buf = new Int16Array(this.size);
|
|
15
|
+
this.n = 0;
|
|
16
|
+
this.sum = 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
process(inputs) {
|
|
20
|
+
const ch = inputs[0] && inputs[0][0];
|
|
21
|
+
if (!ch) return true;
|
|
22
|
+
for (let i = 0; i < ch.length; i++) {
|
|
23
|
+
const s = Math.max(-1, Math.min(1, ch[i]));
|
|
24
|
+
this.buf[this.n++] = s < 0 ? s * 0x8000 : s * 0x7fff;
|
|
25
|
+
this.sum += s * s;
|
|
26
|
+
if (this.n === this.size) {
|
|
27
|
+
const out = this.buf.slice(0);
|
|
28
|
+
this.port.postMessage({ pcm: out.buffer, level: Math.sqrt(this.sum / this.n) }, [
|
|
29
|
+
out.buffer,
|
|
30
|
+
]);
|
|
31
|
+
this.n = 0;
|
|
32
|
+
this.sum = 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
registerProcessor('oona-capture', OonaCapture);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 16-bit PCM chunks → the speaker. A queue: "flush" empties it at once (the person spoke over the
|
|
42
|
+
* assistant); it says when it starts and when it runs dry, so the window knows the assistant is silent.
|
|
43
|
+
*/
|
|
44
|
+
class OonaPlayer extends AudioWorkletProcessor {
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
this.queue = [];
|
|
48
|
+
this.offset = 0;
|
|
49
|
+
this.playing = false;
|
|
50
|
+
this.port.onmessage = (e) => {
|
|
51
|
+
if (e.data === 'flush') {
|
|
52
|
+
this.queue = [];
|
|
53
|
+
this.offset = 0;
|
|
54
|
+
} else if (e.data && e.data.pcm) {
|
|
55
|
+
this.queue.push(new Int16Array(e.data.pcm));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
process(_inputs, outputs) {
|
|
61
|
+
const out = outputs[0][0];
|
|
62
|
+
if (!out) return true;
|
|
63
|
+
let i = 0;
|
|
64
|
+
while (i < out.length && this.queue.length > 0) {
|
|
65
|
+
const head = this.queue[0];
|
|
66
|
+
const take = Math.min(out.length - i, head.length - this.offset);
|
|
67
|
+
for (let k = 0; k < take; k++) out[i + k] = head[this.offset + k] / 0x8000;
|
|
68
|
+
i += take;
|
|
69
|
+
this.offset += take;
|
|
70
|
+
if (this.offset >= head.length) {
|
|
71
|
+
this.queue.shift();
|
|
72
|
+
this.offset = 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (; i < out.length; i++) out[i] = 0;
|
|
76
|
+
const playing = this.queue.length > 0;
|
|
77
|
+
if (playing !== this.playing) {
|
|
78
|
+
this.playing = playing;
|
|
79
|
+
this.port.postMessage({ playing });
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
registerProcessor('oona-player', OonaPlayer);
|