brilliantsole 0.0.29 → 0.0.30
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/build/brilliantsole.cjs +5630 -494
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +21293 -3088
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +23153 -6240
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.d.ts +1158 -74
- package/build/brilliantsole.module.js +21259 -3089
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +1158 -74
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +869 -70
- package/build/brilliantsole.node.module.js +5608 -495
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS.d.ts +20 -1
- package/build/dts/Device.d.ts +135 -13
- package/build/dts/DeviceManager.d.ts +3 -3
- package/build/dts/DisplayManager.d.ts +320 -0
- package/build/dts/FileTransferManager.d.ts +10 -4
- package/build/dts/connection/BaseConnectionManager.d.ts +2 -2
- package/build/dts/connection/bluetooth/BluetoothUUID.d.ts +12 -0
- package/build/dts/devicePair/DevicePair.d.ts +5 -5
- package/build/dts/sensor/SensorConfigurationManager.d.ts +2 -1
- package/build/dts/server/BaseClient.d.ts +4 -4
- package/build/dts/server/udp/UDPUtils.d.ts +1 -1
- package/build/dts/utils/ArrayBufferUtils.d.ts +1 -0
- package/build/dts/utils/BitmapUtils.d.ts +17 -0
- package/build/dts/utils/ColorUtils.d.ts +5 -0
- package/build/dts/utils/DisplayBitmapUtils.d.ts +47 -0
- package/build/dts/utils/DisplayCanvasHelper.d.ts +270 -0
- package/build/dts/utils/DisplayContextCommand.d.ts +300 -0
- package/build/dts/utils/DisplayContextState.d.ts +51 -0
- package/build/dts/utils/DisplayContextStateHelper.d.ts +9 -0
- package/build/dts/utils/DisplayManagerInterface.d.ts +173 -0
- package/build/dts/utils/DisplaySpriteSheetUtils.d.ts +72 -0
- package/build/dts/utils/DisplayUtils.d.ts +70 -0
- package/build/dts/utils/MathUtils.d.ts +16 -0
- package/build/dts/utils/PathUtils.d.ts +4 -0
- package/build/dts/utils/RangeHelper.d.ts +7 -0
- package/build/dts/utils/SpriteSheetUtils.d.ts +20 -0
- package/build/index.d.ts +1156 -72
- package/build/index.node.d.ts +867 -68
- package/examples/3d-generic/index.html +5 -0
- package/examples/3d-generic/script.js +1 -0
- package/examples/basic/index.html +335 -0
- package/examples/basic/script.js +1303 -3
- package/examples/camera/utils.js +1 -1
- package/examples/display-3d/index.html +195 -0
- package/examples/display-3d/script.js +1235 -0
- package/examples/display-canvas/aframe.js +42950 -0
- package/examples/display-canvas/index.html +245 -0
- package/examples/display-canvas/script.js +2312 -0
- package/examples/display-image/index.html +189 -0
- package/examples/display-image/script.js +1093 -0
- package/examples/display-spritesheet/index.html +960 -0
- package/examples/display-spritesheet/script.js +4243 -0
- package/examples/display-text/index.html +195 -0
- package/examples/display-text/script.js +1418 -0
- package/examples/display-wireframe/index.html +204 -0
- package/examples/display-wireframe/script.js +1167 -0
- package/examples/glasses-gestures/index.html +6 -1
- package/examples/glasses-gestures/script.js +10 -8
- package/examples/microphone/index.html +3 -1
- package/examples/punch/index.html +4 -1
- package/examples/server/script.js +0 -1
- package/package.json +10 -2
- package/src/BS.ts +92 -1
- package/src/CameraManager.ts +6 -2
- package/src/Device.ts +544 -13
- package/src/DisplayManager.ts +2989 -0
- package/src/FileTransferManager.ts +79 -26
- package/src/InformationManager.ts +8 -7
- package/src/MicrophoneManager.ts +10 -3
- package/src/TfliteManager.ts +4 -2
- package/src/WifiManager.ts +4 -1
- package/src/connection/BaseConnectionManager.ts +2 -0
- package/src/connection/bluetooth/bluetoothUUIDs.ts +36 -1
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +1 -1
- package/src/scanner/NobleScanner.ts +1 -1
- package/src/sensor/SensorConfigurationManager.ts +16 -8
- package/src/server/udp/UDPServer.ts +4 -4
- package/src/server/udp/UDPUtils.ts +1 -1
- package/src/server/websocket/WebSocketClient.ts +50 -1
- package/src/utils/ArrayBufferUtils.ts +23 -5
- package/src/utils/AudioUtils.ts +1 -1
- package/src/utils/ColorUtils.ts +66 -0
- package/src/utils/DisplayBitmapUtils.ts +695 -0
- package/src/utils/DisplayCanvasHelper.ts +4222 -0
- package/src/utils/DisplayContextCommand.ts +1566 -0
- package/src/utils/DisplayContextState.ts +138 -0
- package/src/utils/DisplayContextStateHelper.ts +48 -0
- package/src/utils/DisplayManagerInterface.ts +1356 -0
- package/src/utils/DisplaySpriteSheetUtils.ts +782 -0
- package/src/utils/DisplayUtils.ts +529 -0
- package/src/utils/EventDispatcher.ts +59 -14
- package/src/utils/MathUtils.ts +88 -2
- package/src/utils/ObjectUtils.ts +6 -1
- package/src/utils/PathUtils.ts +192 -0
- package/src/utils/RangeHelper.ts +15 -3
- package/src/utils/Timer.ts +1 -1
- package/src/utils/environment.ts +15 -6
- package/examples/microphone/gender.js +0 -54
package/src/utils/MathUtils.ts
CHANGED
|
@@ -3,7 +3,12 @@ import { createConsole } from "./Console.ts";
|
|
|
3
3
|
|
|
4
4
|
const _console = createConsole("MathUtils", { log: false });
|
|
5
5
|
|
|
6
|
-
export function getInterpolation(
|
|
6
|
+
export function getInterpolation(
|
|
7
|
+
value: number,
|
|
8
|
+
min: number,
|
|
9
|
+
max: number,
|
|
10
|
+
span: number
|
|
11
|
+
) {
|
|
7
12
|
if (span == undefined) {
|
|
8
13
|
span = max - min;
|
|
9
14
|
}
|
|
@@ -11,6 +16,8 @@ export function getInterpolation(value: number, min: number, max: number, span:
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export const Uint16Max = 2 ** 16;
|
|
19
|
+
export const Int16Max = 2 ** 15;
|
|
20
|
+
export const Int16Min = -(2 ** 15) - 1;
|
|
14
21
|
|
|
15
22
|
function removeLower2Bytes(number: number) {
|
|
16
23
|
const lower2Bytes = number % Uint16Max;
|
|
@@ -36,6 +43,44 @@ export interface Vector2 {
|
|
|
36
43
|
y: number;
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
export function getVector2Length(vector: Vector2) {
|
|
47
|
+
const { x, y } = vector;
|
|
48
|
+
return Math.sqrt(x ** 2 + y ** 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getVector2Distance(a: Vector2, b: Vector2) {
|
|
52
|
+
return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function getVector2DistanceSquared(a: Vector2, b: Vector2) {
|
|
56
|
+
return (b.x - a.x) ** 2 + (b.y - a.y) ** 2;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getVector2Angle(vector: Vector2) {
|
|
60
|
+
const { x, y } = vector;
|
|
61
|
+
return Math.atan2(y, x);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function getVector2Midpoint(a: Vector2, b: Vector2): Vector2 {
|
|
65
|
+
return {
|
|
66
|
+
x: (a.x + b.x) / 2,
|
|
67
|
+
y: (a.y + b.y) / 2,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function multiplyVector2ByScalar(
|
|
72
|
+
vector: Vector2,
|
|
73
|
+
scalar: number
|
|
74
|
+
): Vector2 {
|
|
75
|
+
let { x, y } = vector;
|
|
76
|
+
x *= scalar;
|
|
77
|
+
y *= scalar;
|
|
78
|
+
return { x, y };
|
|
79
|
+
}
|
|
80
|
+
export function normalizedVector2(vector: Vector2): Vector2 {
|
|
81
|
+
return multiplyVector2ByScalar(vector, 1 / getVector2Length(vector));
|
|
82
|
+
}
|
|
83
|
+
|
|
39
84
|
export interface Vector3 extends Vector2 {
|
|
40
85
|
z: number;
|
|
41
86
|
}
|
|
@@ -53,7 +98,10 @@ export interface Euler {
|
|
|
53
98
|
roll: number;
|
|
54
99
|
}
|
|
55
100
|
|
|
56
|
-
export function computeVoronoiWeights(
|
|
101
|
+
export function computeVoronoiWeights(
|
|
102
|
+
points: PressureSensorPosition[],
|
|
103
|
+
sampleCount = 100000
|
|
104
|
+
) {
|
|
57
105
|
const n = points.length;
|
|
58
106
|
const counts = new Array(n).fill(0);
|
|
59
107
|
|
|
@@ -81,3 +129,41 @@ export function computeVoronoiWeights(points: PressureSensorPosition[], sampleCo
|
|
|
81
129
|
// Convert counts to weights (sum to 1)
|
|
82
130
|
return counts.map((c) => c / sampleCount);
|
|
83
131
|
}
|
|
132
|
+
|
|
133
|
+
export function getVector3Length(vector: Vector3) {
|
|
134
|
+
const { x, y, z } = vector;
|
|
135
|
+
return Math.sqrt(x ** 2 + y ** 2 + z ** 2);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function clamp(value: number, min: number = 0, max: number = 1) {
|
|
139
|
+
return Math.min(Math.max(value, min), max);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function degToRad(deg: number) {
|
|
143
|
+
return deg * (Math.PI / 180);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function radToDeg(rad: number) {
|
|
147
|
+
return rad * (180 / Math.PI);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const twoPi = Math.PI * 2;
|
|
151
|
+
export function normalizeRadians(rad: number): number {
|
|
152
|
+
return ((rad % twoPi) + twoPi) % twoPi;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function pointInPolygon(pt: Vector2, polygon: Vector2[]): boolean {
|
|
156
|
+
let inside = false;
|
|
157
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
158
|
+
const xi = polygon[i].x,
|
|
159
|
+
yi = polygon[i].y;
|
|
160
|
+
const xj = polygon[j].x,
|
|
161
|
+
yj = polygon[j].y;
|
|
162
|
+
|
|
163
|
+
const intersect =
|
|
164
|
+
yi > pt.y !== yj > pt.y &&
|
|
165
|
+
pt.x < ((xj - xi) * (pt.y - yi)) / (yj - yi) + xi;
|
|
166
|
+
if (intersect) inside = !inside;
|
|
167
|
+
}
|
|
168
|
+
return inside;
|
|
169
|
+
}
|
package/src/utils/ObjectUtils.ts
CHANGED
|
@@ -3,7 +3,12 @@ export function deepEqual(obj1: any, obj2: any): boolean {
|
|
|
3
3
|
return true;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
if (
|
|
6
|
+
if (
|
|
7
|
+
typeof obj1 !== "object" ||
|
|
8
|
+
obj1 === null ||
|
|
9
|
+
typeof obj2 !== "object" ||
|
|
10
|
+
obj2 === null
|
|
11
|
+
) {
|
|
7
12
|
return false;
|
|
8
13
|
}
|
|
9
14
|
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { createConsole } from "./Console.ts";
|
|
2
|
+
import opentype from "opentype.js";
|
|
3
|
+
import { Vector2 } from "./MathUtils.ts";
|
|
4
|
+
|
|
5
|
+
const _console = createConsole("PathUtils", { log: false });
|
|
6
|
+
|
|
7
|
+
type PathCommand = opentype.PathCommand;
|
|
8
|
+
|
|
9
|
+
function perpendicularDistance(p: Vector2, p1: Vector2, p2: Vector2): number {
|
|
10
|
+
const dx = p2.x - p1.x;
|
|
11
|
+
const dy = p2.y - p1.y;
|
|
12
|
+
if (dx === 0 && dy === 0) return Math.hypot(p.x - p1.x, p.y - p1.y);
|
|
13
|
+
const t = ((p.x - p1.x) * dx + (p.y - p1.y) * dy) / (dx * dx + dy * dy);
|
|
14
|
+
const projX = p1.x + t * dx;
|
|
15
|
+
const projY = p1.y + t * dy;
|
|
16
|
+
return Math.hypot(p.x - projX, p.y - projY);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function rdp(points: Vector2[], epsilon: number): Vector2[] {
|
|
20
|
+
if (points.length < 3) return points;
|
|
21
|
+
let maxDist = 0;
|
|
22
|
+
let index = 0;
|
|
23
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
24
|
+
const d = perpendicularDistance(
|
|
25
|
+
points[i],
|
|
26
|
+
points[0],
|
|
27
|
+
points[points.length - 1]
|
|
28
|
+
);
|
|
29
|
+
if (d > maxDist) {
|
|
30
|
+
maxDist = d;
|
|
31
|
+
index = i;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (maxDist > epsilon) {
|
|
35
|
+
const left = rdp(points.slice(0, index + 1), epsilon);
|
|
36
|
+
const right = rdp(points.slice(index), epsilon);
|
|
37
|
+
return left.slice(0, -1).concat(right);
|
|
38
|
+
}
|
|
39
|
+
return [points[0], points[points.length - 1]];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Linear interpolation
|
|
43
|
+
function lerp(a: number, b: number, t: number) {
|
|
44
|
+
return a + (b - a) * t;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Sample quadratic Bezier
|
|
48
|
+
function sampleQuadratic(
|
|
49
|
+
p0: Vector2,
|
|
50
|
+
p1: Vector2,
|
|
51
|
+
p2: Vector2,
|
|
52
|
+
steps: number = 5
|
|
53
|
+
): Vector2[] {
|
|
54
|
+
const points: Vector2[] = [];
|
|
55
|
+
for (let i = 0; i <= steps; i++) {
|
|
56
|
+
const t = i / steps;
|
|
57
|
+
const x = (1 - t) ** 2 * p0.x + 2 * (1 - t) * t * p1.x + t ** 2 * p2.x;
|
|
58
|
+
const y = (1 - t) ** 2 * p0.y + 2 * (1 - t) * t * p1.y + t ** 2 * p2.y;
|
|
59
|
+
points.push({ x, y });
|
|
60
|
+
}
|
|
61
|
+
return points;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Sample cubic Bezier
|
|
65
|
+
function sampleCubic(
|
|
66
|
+
p0: Vector2,
|
|
67
|
+
p1: Vector2,
|
|
68
|
+
p2: Vector2,
|
|
69
|
+
p3: Vector2,
|
|
70
|
+
steps: number = 5
|
|
71
|
+
): Vector2[] {
|
|
72
|
+
const points: Vector2[] = [];
|
|
73
|
+
for (let i = 0; i <= steps; i++) {
|
|
74
|
+
const t = i / steps;
|
|
75
|
+
const mt = 1 - t;
|
|
76
|
+
const x =
|
|
77
|
+
mt ** 3 * p0.x +
|
|
78
|
+
3 * mt ** 2 * t * p1.x +
|
|
79
|
+
3 * mt * t ** 2 * p2.x +
|
|
80
|
+
t ** 3 * p3.x;
|
|
81
|
+
const y =
|
|
82
|
+
mt ** 3 * p0.y +
|
|
83
|
+
3 * mt ** 2 * t * p1.y +
|
|
84
|
+
3 * mt * t ** 2 * p2.y +
|
|
85
|
+
t ** 3 * p3.y;
|
|
86
|
+
points.push({ x, y });
|
|
87
|
+
}
|
|
88
|
+
return points;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function areCollinear(
|
|
92
|
+
p1: Vector2,
|
|
93
|
+
p2: Vector2,
|
|
94
|
+
p3: Vector2,
|
|
95
|
+
epsilon = 1e-6
|
|
96
|
+
): boolean {
|
|
97
|
+
// Vector p1->p2
|
|
98
|
+
const dx1 = p2.x - p1.x;
|
|
99
|
+
const dy1 = p2.y - p1.y;
|
|
100
|
+
|
|
101
|
+
// Vector p2->p3
|
|
102
|
+
const dx2 = p3.x - p2.x;
|
|
103
|
+
const dy2 = p3.y - p2.y;
|
|
104
|
+
|
|
105
|
+
// Cross product
|
|
106
|
+
const cross = dx1 * dy2 - dy1 * dx2;
|
|
107
|
+
return Math.abs(cross) < epsilon;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function simplifyPath(
|
|
111
|
+
commands: PathCommand[],
|
|
112
|
+
epsilon = 1
|
|
113
|
+
): PathCommand[] {
|
|
114
|
+
const simplified: PathCommand[] = [];
|
|
115
|
+
let cursor: Vector2 = { x: 0, y: 0 };
|
|
116
|
+
|
|
117
|
+
for (let i = 0; i < commands.length; i++) {
|
|
118
|
+
const cmd = commands[i];
|
|
119
|
+
|
|
120
|
+
switch (cmd.type) {
|
|
121
|
+
case "M":
|
|
122
|
+
simplified.push({ ...cmd });
|
|
123
|
+
cursor = { x: cmd.x, y: cmd.y };
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case "L": {
|
|
127
|
+
// Merge collinear lines
|
|
128
|
+
const nextPoint = { x: cmd.x, y: cmd.y };
|
|
129
|
+
const lastCmd = simplified[simplified.length - 1];
|
|
130
|
+
if (
|
|
131
|
+
lastCmd &&
|
|
132
|
+
lastCmd.type === "L" &&
|
|
133
|
+
simplified.length >= 2 &&
|
|
134
|
+
areCollinear(
|
|
135
|
+
simplified[simplified.length - 2] as Vector2,
|
|
136
|
+
lastCmd as Vector2,
|
|
137
|
+
nextPoint
|
|
138
|
+
)
|
|
139
|
+
) {
|
|
140
|
+
// Remove middle collinear point
|
|
141
|
+
simplified.pop();
|
|
142
|
+
}
|
|
143
|
+
simplified.push({ ...cmd });
|
|
144
|
+
cursor = nextPoint;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
case "Q": {
|
|
149
|
+
const p0 = cursor;
|
|
150
|
+
const p1 = { x: cmd.x1, y: cmd.y1 };
|
|
151
|
+
const p2 = { x: cmd.x, y: cmd.y };
|
|
152
|
+
|
|
153
|
+
// Sample points along the curve
|
|
154
|
+
const sampled = sampleQuadratic(p0, p1, p2, 5);
|
|
155
|
+
const simplifiedPoints = rdp(sampled, epsilon);
|
|
156
|
+
|
|
157
|
+
// If curve is almost straight, convert to a line
|
|
158
|
+
if (simplifiedPoints.length === 2) {
|
|
159
|
+
simplified.push({ type: "L", x: p2.x, y: p2.y });
|
|
160
|
+
} else {
|
|
161
|
+
simplified.push({ ...cmd }); // Keep the curve
|
|
162
|
+
}
|
|
163
|
+
cursor = p2;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
case "C": {
|
|
168
|
+
const p0 = cursor;
|
|
169
|
+
const p1 = { x: cmd.x1, y: cmd.y1 };
|
|
170
|
+
const p2 = { x: cmd.x2, y: cmd.y2 };
|
|
171
|
+
const p3 = { x: cmd.x, y: cmd.y };
|
|
172
|
+
|
|
173
|
+
const sampled = sampleCubic(p0, p1, p2, p3, 5);
|
|
174
|
+
const simplifiedPoints = rdp(sampled, epsilon);
|
|
175
|
+
|
|
176
|
+
if (simplifiedPoints.length === 2) {
|
|
177
|
+
simplified.push({ type: "L", x: p3.x, y: p3.y });
|
|
178
|
+
} else {
|
|
179
|
+
simplified.push({ ...cmd }); // Keep the curve
|
|
180
|
+
}
|
|
181
|
+
cursor = p3;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
case "Z":
|
|
186
|
+
simplified.push({ ...cmd });
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return simplified;
|
|
192
|
+
}
|
package/src/utils/RangeHelper.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getInterpolation } from "./MathUtils.ts";
|
|
2
2
|
|
|
3
|
-
interface Range {
|
|
3
|
+
export interface Range {
|
|
4
4
|
min: number;
|
|
5
5
|
max: number;
|
|
6
6
|
span: number;
|
|
@@ -9,13 +9,20 @@ interface Range {
|
|
|
9
9
|
const initialRange: Range = { min: Infinity, max: -Infinity, span: 0 };
|
|
10
10
|
|
|
11
11
|
class RangeHelper {
|
|
12
|
-
#range: Range =
|
|
12
|
+
#range: Range = structuredClone(initialRange);
|
|
13
13
|
get min() {
|
|
14
14
|
return this.#range.min;
|
|
15
15
|
}
|
|
16
16
|
get max() {
|
|
17
17
|
return this.#range.max;
|
|
18
18
|
}
|
|
19
|
+
get span() {
|
|
20
|
+
return this.#range.span;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get range() {
|
|
24
|
+
return structuredClone(this.#range);
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
set min(newMin) {
|
|
21
28
|
this.#range.min = newMin;
|
|
@@ -43,7 +50,12 @@ class RangeHelper {
|
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
getNormalization(value: number, weightByRange: boolean) {
|
|
46
|
-
let normalization = getInterpolation(
|
|
53
|
+
let normalization = getInterpolation(
|
|
54
|
+
value,
|
|
55
|
+
this.#range.min,
|
|
56
|
+
this.#range.max,
|
|
57
|
+
this.#range.span
|
|
58
|
+
);
|
|
47
59
|
if (weightByRange) {
|
|
48
60
|
normalization *= this.#range.span;
|
|
49
61
|
}
|
package/src/utils/Timer.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createConsole } from "./Console.ts";
|
|
|
3
3
|
const _console = createConsole("Timer", { log: false });
|
|
4
4
|
|
|
5
5
|
export async function wait(delay: number) {
|
|
6
|
-
_console.log(`waiting for ${delay}
|
|
6
|
+
_console.log(`waiting for ${delay}ms`);
|
|
7
7
|
return new Promise((resolve: Function) => {
|
|
8
8
|
setTimeout(() => resolve(), delay);
|
|
9
9
|
});
|
package/src/utils/environment.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
type ENVIRONMENT_FLAG = "__BRILLIANTSOLE__DEV__" | "__BRILLIANTSOLE__PROD__";
|
|
2
|
-
const __BRILLIANTSOLE__ENVIRONMENT__: ENVIRONMENT_FLAG =
|
|
2
|
+
const __BRILLIANTSOLE__ENVIRONMENT__: ENVIRONMENT_FLAG =
|
|
3
|
+
"__BRILLIANTSOLE__DEV__";
|
|
3
4
|
|
|
4
5
|
//@ts-expect-error
|
|
5
|
-
const isInProduction =
|
|
6
|
+
const isInProduction =
|
|
7
|
+
__BRILLIANTSOLE__ENVIRONMENT__ == "__BRILLIANTSOLE__PROD__";
|
|
6
8
|
const isInDev = __BRILLIANTSOLE__ENVIRONMENT__ == "__BRILLIANTSOLE__DEV__";
|
|
7
9
|
|
|
8
10
|
// https://github.com/flexdinesh/browser-or-node/blob/master/src/index.ts
|
|
9
|
-
const isInBrowser =
|
|
10
|
-
|
|
11
|
+
const isInBrowser =
|
|
12
|
+
typeof window !== "undefined" && typeof window?.document !== "undefined";
|
|
13
|
+
const isInNode =
|
|
14
|
+
typeof process !== "undefined" && process?.versions?.node != null;
|
|
11
15
|
|
|
12
16
|
const userAgent = (isInBrowser && navigator.userAgent) || "";
|
|
13
17
|
|
|
@@ -22,13 +26,18 @@ const isInBluefy = isInBrowser && /Bluefy/i.test(userAgent);
|
|
|
22
26
|
const isInWebBLE = isInBrowser && /WebBLE/i.test(userAgent);
|
|
23
27
|
|
|
24
28
|
const isAndroid = isInBrowser && /Android/i.test(userAgent);
|
|
25
|
-
const isSafari =
|
|
29
|
+
const isSafari =
|
|
30
|
+
isInBrowser && /Safari/i.test(userAgent) && !/Chrome/i.test(userAgent);
|
|
26
31
|
|
|
27
32
|
const isIOS = isInBrowser && /iPad|iPhone|iPod/i.test(userAgent);
|
|
28
33
|
const isMac = isInBrowser && /Macintosh/i.test(userAgent);
|
|
29
34
|
|
|
30
35
|
// @ts-expect-error
|
|
31
|
-
const isInLensStudio =
|
|
36
|
+
const isInLensStudio =
|
|
37
|
+
!isInBrowser &&
|
|
38
|
+
!isInNode &&
|
|
39
|
+
typeof global !== "undefined" &&
|
|
40
|
+
typeof Studio !== "undefined";
|
|
32
41
|
|
|
33
42
|
export {
|
|
34
43
|
isInDev,
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.2.4";
|
|
2
|
-
|
|
3
|
-
import { registerModel } from "./utils.js";
|
|
4
|
-
|
|
5
|
-
let classifier = undefined;
|
|
6
|
-
let isRunning = false;
|
|
7
|
-
|
|
8
|
-
const createClassifier = async () => {
|
|
9
|
-
console.log("creating classifier");
|
|
10
|
-
classifier = await pipeline(
|
|
11
|
-
"audio-classification",
|
|
12
|
-
"Xenova/wav2vec2-large-xlsr-53-gender-recognition-librispeech"
|
|
13
|
-
);
|
|
14
|
-
console.log("created classifier", classifier);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
registerModel(
|
|
18
|
-
"gender",
|
|
19
|
-
() => {
|
|
20
|
-
if (!classifier) {
|
|
21
|
-
createClassifier();
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
() => {},
|
|
25
|
-
async (microphoneRecordingAudio, mediaResultsElement) => {
|
|
26
|
-
if (!classifier) {
|
|
27
|
-
console.error("classifier not created yet");
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (isRunning) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
isRunning = true;
|
|
34
|
-
const output = await classifier(microphoneRecordingAudio.src);
|
|
35
|
-
isRunning = false;
|
|
36
|
-
|
|
37
|
-
console.log("output", output);
|
|
38
|
-
let maxLabel, maxScore;
|
|
39
|
-
output.forEach(({ label, score }) => {
|
|
40
|
-
maxLabel ??= label;
|
|
41
|
-
maxScore ??= score;
|
|
42
|
-
if (score > maxScore) {
|
|
43
|
-
maxScore = score;
|
|
44
|
-
maxLabel = label;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
mediaResultsElement.innerText = `${maxLabel}: ${maxScore.toFixed(3)}`;
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const sampleOutput = [
|
|
52
|
-
{ label: "male", score: 0.9976564049720764 },
|
|
53
|
-
{ label: "female", score: 0.002343568252399564 },
|
|
54
|
-
];
|