@twoimpulse/langbox-voice-widget 0.1.5 → 0.1.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twoimpulse/langbox-voice-widget",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Embeddable voice agent widget for Langbox",
6
6
  "main": "dist/langbox-widget.js",
@@ -1,27 +0,0 @@
1
- class PCMProcessor extends AudioWorkletProcessor {
2
- constructor() {
3
- super();
4
- }
5
-
6
- process(inputs, outputs, parameters) {
7
- const input = inputs[0];
8
- if (input.length > 0) {
9
- const float32Buffer = input[0];
10
- const int16Buffer = this.convertFloat32ToInt16(float32Buffer);
11
- this.port.postMessage(int16Buffer);
12
- }
13
- return true;
14
- }
15
-
16
- convertFloat32ToInt16(float32Array) {
17
- const int16Array = new Int16Array(float32Array.length);
18
- for (let i = 0; i < float32Array.length; i++) {
19
- let val = Math.floor(float32Array[i] * 0x7fff);
20
- val = Math.max(-0x8000, Math.min(0x7fff, val));
21
- int16Array[i] = val;
22
- }
23
- return int16Array;
24
- }
25
- }
26
-
27
- registerProcessor("audio-worklet-processor", PCMProcessor);
@@ -1,36 +0,0 @@
1
- class PlaybackWorklet extends AudioWorkletProcessor {
2
- constructor() {
3
- super();
4
- this.port.onmessage = this.handleMessage.bind(this);
5
- this.buffer = [];
6
- }
7
-
8
- handleMessage(event) {
9
- if (event.data === null) {
10
- this.buffer = [];
11
- return;
12
- }
13
- this.buffer.push(...event.data);
14
- }
15
-
16
- process(inputs, outputs, parameters) {
17
- const output = outputs[0];
18
- const channel = output[0];
19
-
20
- if (this.buffer.length > channel.length) {
21
- const toProcess = this.buffer.splice(0, channel.length);
22
- channel.set(toProcess.map((v) => v / 32768));
23
- } else {
24
- channel.set(this.buffer.map((v) => v / 32768));
25
- this.buffer = [];
26
- }
27
-
28
- if (this.buffer.length === 0) {
29
- this.port.postMessage({ empty: true });
30
- }
31
-
32
- return true;
33
- }
34
- }
35
-
36
- registerProcessor("playback-worklet", PlaybackWorklet);