@twoimpulse/langbox-voice-widget 0.1.1

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.
@@ -0,0 +1,27 @@
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);
@@ -0,0 +1,36 @@
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);
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@twoimpulse/langbox-voice-widget",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Embeddable voice agent widget for Langbox",
6
+ "main": "dist/langbox-widget.js",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "dev": "vite",
12
+ "build": "tsc --noEmit && vite build",
13
+ "preview": "vite preview",
14
+ "lint": "eslint src/",
15
+ "lint:fix": "eslint src/ --fix",
16
+ "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "keywords": [
20
+ "langbox",
21
+ "voice-agent",
22
+ "widget",
23
+ "embeddable",
24
+ "web-component"
25
+ ],
26
+ "author": "TwoImpulse",
27
+ "license": "MIT",
28
+ "devDependencies": {
29
+ "@types/react": "^19.2.7",
30
+ "@types/react-dom": "^19.2.3",
31
+ "@typescript-eslint/eslint-plugin": "^8.49.0",
32
+ "@typescript-eslint/parser": "^8.49.0",
33
+ "@vitejs/plugin-react": "^4.4.1",
34
+ "eslint": "^9.39.1",
35
+ "eslint-config-prettier": "^10.1.8",
36
+ "eslint-plugin-react": "^7.37.5",
37
+ "eslint-plugin-react-hooks": "^7.0.1",
38
+ "prettier": "^3.5.3",
39
+ "sass": "^1.87.0",
40
+ "terser": "^5.44.1",
41
+ "typescript": "^5.9.3",
42
+ "vite": "^6.3.4",
43
+ "vite-plugin-css-injected-by-js": "^3.5.2"
44
+ },
45
+ "dependencies": {
46
+ "openai": "^4.77.0",
47
+ "react": "^19.1.0",
48
+ "react-dom": "^19.1.0"
49
+ }
50
+ }