brilliantsole 0.0.27 → 0.0.29
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/assets/3d/anchor.glb +0 -0
- package/assets/3d/coin.glb +0 -0
- package/assets/3d/glasses.glb +0 -0
- package/assets/audio/bounceMedium.wav +0 -0
- package/assets/audio/bounceStrong.wav +0 -0
- package/assets/audio/bounceWeak.wav +0 -0
- package/assets/audio/coin.wav +0 -0
- package/assets/audio/getUp.wav +0 -0
- package/assets/audio/grab.wav +0 -0
- package/assets/audio/kick.wav +0 -0
- package/assets/audio/platterFadeIn old.wav +0 -0
- package/assets/audio/platterFadeIn.wav +0 -0
- package/assets/audio/platterFadeOut.wav +0 -0
- package/assets/audio/punch.wav +0 -0
- package/assets/audio/punchSqueak.wav +0 -0
- package/assets/audio/purr.wav +0 -0
- package/assets/audio/purrFadeOut.wav +0 -0
- package/assets/audio/release.wav +0 -0
- package/assets/audio/splat.wav +0 -0
- package/assets/audio/stomp.wav +0 -0
- package/build/brilliantsole.cjs +3091 -741
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2759 -709
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2602 -543
- 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 +295 -65
- package/build/brilliantsole.module.js +2749 -710
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +295 -65
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +289 -62
- package/build/brilliantsole.node.module.js +3080 -742
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS-output.d.ts +10 -0
- package/build/dts/BS.d.ts +21 -8
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +64 -13
- package/build/dts/DeviceInformationManager.d.ts +4 -4
- package/build/dts/DeviceManager.d.ts +2 -0
- package/build/dts/FileTransferManager.d.ts +18 -8
- package/build/dts/InformationManager.d.ts +2 -0
- package/build/dts/MicrophoneManager.d.ts +88 -0
- package/build/dts/TfliteManager.d.ts +22 -2
- package/build/dts/WifiManager.d.ts +61 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +35 -3
- package/build/dts/connection/ClientConnectionManager.d.ts +7 -2
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +2 -1
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +1 -0
- package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
- package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
- package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
- package/build/dts/devicePair/DevicePair.d.ts +5 -5
- package/build/dts/scanner/BaseScanner.d.ts +4 -1
- package/build/dts/scanner/NobleScanner.d.ts +2 -1
- package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
- package/build/dts/sensor/SensorDataManager.d.ts +5 -4
- package/build/dts/server/BaseClient.d.ts +5 -3
- package/build/dts/server/ServerUtils.d.ts +1 -1
- package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
- package/build/dts/utils/AudioUtils.d.ts +2 -0
- package/build/dts/utils/Console.d.ts +2 -0
- package/build/dts/utils/ThrottleUtils.d.ts +2 -0
- package/build/dts/vibration/VibrationManager.d.ts +19 -2
- package/build/index.d.ts +292 -62
- package/build/index.node.d.ts +286 -59
- package/examples/3d/scene.html +19 -5
- package/examples/3d-generic/index.html +144 -0
- package/examples/3d-generic/script.js +266 -0
- package/examples/basic/index.html +267 -17
- package/examples/basic/script.js +958 -105
- package/examples/camera/barcode-detector.js +109 -0
- package/examples/camera/depth-estimation.js +71 -0
- package/examples/camera/face-detector.js +119 -0
- package/examples/camera/face-landmark.js +111 -0
- package/examples/camera/gesture-recognition.js +97 -0
- package/examples/camera/hand-landmark.js +74 -0
- package/examples/camera/image-segmentation.js +98 -0
- package/examples/camera/image-to-text.js +43 -0
- package/examples/camera/image-upscale.js +75 -0
- package/examples/camera/index.html +129 -0
- package/examples/camera/object-detection.js +98 -0
- package/examples/camera/pose-landmark.js +60 -0
- package/examples/camera/script.js +316 -0
- package/examples/camera/utils.js +165 -0
- package/examples/camera/yolo-tiny.js +54 -0
- package/examples/camera/yolo.js +119 -0
- package/examples/edge-impulse/script.js +157 -48
- package/examples/edge-impulse-test/README.md +11 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
- package/examples/edge-impulse-test/index.html +75 -0
- package/examples/edge-impulse-test/run-impulse.js +135 -0
- package/examples/edge-impulse-test/script.js +200 -0
- package/examples/glasses-gestures/README.md +11 -0
- package/examples/glasses-gestures/edge-impulse-standalone.js +7228 -0
- package/examples/glasses-gestures/edge-impulse-standalone.wasm +0 -0
- package/examples/glasses-gestures/index.html +69 -0
- package/examples/glasses-gestures/run-impulse.js +135 -0
- package/examples/glasses-gestures/script.js +226 -0
- package/examples/gloves/edge-impulse-standalone.js +7228 -0
- package/examples/gloves/edge-impulse-standalone.wasm +0 -0
- package/examples/gloves/index.html +4 -1
- package/examples/gloves/run-impulse.js +135 -0
- package/examples/gloves/script.js +367 -51
- package/examples/graph/script.js +94 -37
- package/examples/microphone/gender.js +54 -0
- package/examples/microphone/index.html +102 -0
- package/examples/microphone/script.js +394 -0
- package/examples/microphone/utils.js +45 -0
- package/examples/microphone/whisper-realtime.js +166 -0
- package/examples/microphone/whisper.js +132 -0
- package/examples/punch/index.html +135 -0
- package/examples/punch/punch.tflite +0 -0
- package/examples/punch/script.js +169 -0
- package/examples/server/index.html +98 -22
- package/examples/server/script.js +317 -109
- package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
- package/examples/utils/aframe/aframe-master.min.js +2 -0
- package/examples/utils/aframe/bs-vibration.js +150 -0
- package/examples/utils/aframe/force-pushable.js +80 -0
- package/examples/utils/aframe/grabbable-anchor.js +46 -0
- package/examples/utils/aframe/grabbable-listener.js +31 -0
- package/examples/utils/aframe/grabbable-physics-body.js +190 -0
- package/examples/utils/aframe/grow-shrink.js +25 -0
- package/examples/utils/aframe/hand-punch.js +119 -0
- package/examples/utils/aframe/my-obb-collider.js +293 -0
- package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
- package/examples/utils/aframe/occlude-mesh.js +42 -0
- package/examples/utils/aframe/palm-up-detector.js +47 -0
- package/examples/utils/aframe/shadow-material.js +20 -0
- package/examples/utils/aframe/soft-shadow-light.js +9 -0
- package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
- package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
- package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
- package/examples/webxr-2/assets/images/shellTexture.png +0 -0
- package/examples/webxr-2/components/bs-ankle.js +337 -0
- package/examples/webxr-2/components/coin.js +84 -0
- package/examples/webxr-2/components/custom-wrap.js +17 -0
- package/examples/webxr-2/components/goomba.js +3250 -0
- package/examples/webxr-2/components/init-shell-material.js +215 -0
- package/examples/webxr-2/components/platter.js +172 -0
- package/examples/webxr-2/components/shell.js +374 -0
- package/examples/webxr-2/components/soccer-ball.js +250 -0
- package/examples/webxr-2/components/squashed-goomba.js +249 -0
- package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
- package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
- package/examples/webxr-2/index.html +996 -0
- package/examples/webxr-2/kick.tflite +0 -0
- package/examples/webxr-2/kick2.tflite +0 -0
- package/examples/webxr-2/run-impulse.js +135 -0
- package/examples/webxr-2/script.js +384 -0
- package/examples/webxr-3/components/bs-camera.js +65 -0
- package/examples/webxr-3/index.html +134 -0
- package/examples/webxr-3/script.js +432 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +79 -8
- package/src/CameraManager.ts +497 -0
- package/src/Device.ts +691 -86
- package/src/DeviceInformationManager.ts +19 -10
- package/src/DeviceManager.ts +85 -25
- package/src/FileTransferManager.ts +145 -20
- package/src/InformationManager.ts +40 -15
- package/src/MicrophoneManager.ts +599 -0
- package/src/TfliteManager.ts +171 -25
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +130 -30
- package/src/connection/ClientConnectionManager.ts +34 -10
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +8 -2
- package/src/connection/bluetooth/NobleConnectionManager.ts +147 -41
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +99 -34
- package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
- package/src/connection/udp/UDPConnectionManager.ts +356 -0
- package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
- package/src/devicePair/DevicePair.ts +95 -25
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +27 -7
- package/src/scanner/BaseScanner.ts +49 -11
- package/src/scanner/NobleScanner.ts +76 -14
- package/src/sensor/MotionSensorDataManager.ts +21 -6
- package/src/sensor/PressureSensorDataManager.ts +37 -8
- package/src/sensor/SensorConfigurationManager.ts +73 -22
- package/src/sensor/SensorDataManager.ts +109 -23
- package/src/server/BaseClient.ts +150 -36
- package/src/server/BaseServer.ts +50 -2
- package/src/server/ServerUtils.ts +39 -9
- package/src/server/udp/UDPServer.ts +73 -22
- package/src/server/udp/UDPUtils.ts +9 -2
- package/src/server/websocket/WebSocketClient.ts +27 -7
- package/src/server/websocket/WebSocketUtils.ts +4 -2
- package/src/utils/AudioUtils.ts +65 -0
- package/src/utils/Console.ts +62 -9
- package/src/utils/ParseUtils.ts +24 -5
- package/src/utils/ThrottleUtils.ts +62 -0
- package/src/utils/Timer.ts +1 -1
- package/src/vibration/VibrationManager.ts +166 -40
package/examples/graph/script.js
CHANGED
|
@@ -12,7 +12,9 @@ window.device = device;
|
|
|
12
12
|
// GET DEVICES
|
|
13
13
|
|
|
14
14
|
/** @type {HTMLTemplateElement} */
|
|
15
|
-
const availableDeviceTemplate = document.getElementById(
|
|
15
|
+
const availableDeviceTemplate = document.getElementById(
|
|
16
|
+
"availableDeviceTemplate"
|
|
17
|
+
);
|
|
16
18
|
const availableDevicesContainer = document.getElementById("availableDevices");
|
|
17
19
|
/** @param {BS.Device[]} availableDevices */
|
|
18
20
|
function onAvailableDevices(availableDevices) {
|
|
@@ -24,19 +26,24 @@ function onAvailableDevices(availableDevices) {
|
|
|
24
26
|
const availableDeviceContainer = availableDeviceTemplate.content
|
|
25
27
|
.cloneNode(true)
|
|
26
28
|
.querySelector(".availableDevice");
|
|
27
|
-
availableDeviceContainer.querySelector(".name").innerText =
|
|
28
|
-
|
|
29
|
+
availableDeviceContainer.querySelector(".name").innerText =
|
|
30
|
+
availableDevice.name;
|
|
31
|
+
availableDeviceContainer.querySelector(".type").innerText =
|
|
32
|
+
availableDevice.type;
|
|
29
33
|
|
|
30
34
|
/** @type {HTMLButtonElement} */
|
|
31
|
-
const toggleConnectionButton =
|
|
35
|
+
const toggleConnectionButton =
|
|
36
|
+
availableDeviceContainer.querySelector(".toggleConnection");
|
|
32
37
|
toggleConnectionButton.addEventListener("click", () => {
|
|
33
38
|
device.connectionManager = availableDevice.connectionManager;
|
|
34
39
|
device.reconnect();
|
|
35
40
|
});
|
|
36
41
|
device.addEventListener("connectionStatus", () => {
|
|
37
|
-
toggleConnectionButton.disabled =
|
|
42
|
+
toggleConnectionButton.disabled =
|
|
43
|
+
device.connectionStatus != "notConnected";
|
|
38
44
|
});
|
|
39
|
-
toggleConnectionButton.disabled =
|
|
45
|
+
toggleConnectionButton.disabled =
|
|
46
|
+
device.connectionStatus != "notConnected";
|
|
40
47
|
|
|
41
48
|
availableDevicesContainer.appendChild(availableDeviceContainer);
|
|
42
49
|
});
|
|
@@ -75,7 +82,9 @@ device.addEventListener("connectionStatus", () => {
|
|
|
75
82
|
case "connected":
|
|
76
83
|
case "notConnected":
|
|
77
84
|
toggleConnectionButton.disabled = false;
|
|
78
|
-
toggleConnectionButton.innerText = device.isConnected
|
|
85
|
+
toggleConnectionButton.innerText = device.isConnected
|
|
86
|
+
? "disconnect"
|
|
87
|
+
: "connect";
|
|
79
88
|
break;
|
|
80
89
|
case "connecting":
|
|
81
90
|
case "disconnecting":
|
|
@@ -99,15 +108,20 @@ function onConnectedDevice(connectedDevice) {
|
|
|
99
108
|
// SENSOR CONFIGURATION
|
|
100
109
|
|
|
101
110
|
/** @type {HTMLTemplateElement} */
|
|
102
|
-
const sensorTypeConfigurationTemplate = document.getElementById(
|
|
111
|
+
const sensorTypeConfigurationTemplate = document.getElementById(
|
|
112
|
+
"sensorTypeConfigurationTemplate"
|
|
113
|
+
);
|
|
103
114
|
BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
104
|
-
const sensorTypeConfigurationContainer =
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
const sensorTypeConfigurationContainer =
|
|
116
|
+
sensorTypeConfigurationTemplate.content
|
|
117
|
+
.cloneNode(true)
|
|
118
|
+
.querySelector(".sensorTypeConfiguration");
|
|
119
|
+
sensorTypeConfigurationContainer.querySelector(".sensorType").innerText =
|
|
120
|
+
sensorType;
|
|
108
121
|
|
|
109
122
|
/** @type {HTMLInputElement} */
|
|
110
|
-
const sensorRateInput =
|
|
123
|
+
const sensorRateInput =
|
|
124
|
+
sensorTypeConfigurationContainer.querySelector(".sensorRate");
|
|
111
125
|
sensorRateInput.value = 0;
|
|
112
126
|
sensorRateInput.max = BS.MaxSensorRate;
|
|
113
127
|
sensorRateInput.step = BS.SensorRateStep;
|
|
@@ -117,15 +131,20 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
117
131
|
device.setSensorConfiguration({ [sensorType]: sensorRate });
|
|
118
132
|
});
|
|
119
133
|
|
|
120
|
-
sensorTypeConfigurationTemplate.parentElement.appendChild(
|
|
134
|
+
sensorTypeConfigurationTemplate.parentElement.appendChild(
|
|
135
|
+
sensorTypeConfigurationContainer
|
|
136
|
+
);
|
|
121
137
|
sensorTypeConfigurationContainer.dataset.sensorType = sensorType;
|
|
122
138
|
});
|
|
123
139
|
/** @param {BS.Device} device */
|
|
124
140
|
function onSensorConfiguration(device) {
|
|
125
|
-
|
|
126
|
-
const sensorRate = device.sensorConfiguration[sensorType];
|
|
141
|
+
BS.SensorTypes.forEach((sensorType) => {
|
|
142
|
+
const sensorRate = device.sensorConfiguration[sensorType] ?? 0;
|
|
143
|
+
|
|
127
144
|
/** @type {HTMLInputElement?} */
|
|
128
|
-
const input = document.querySelector(
|
|
145
|
+
const input = document.querySelector(
|
|
146
|
+
`.sensorTypeConfiguration[data-sensor-type="${sensorType}"] .input`
|
|
147
|
+
);
|
|
129
148
|
if (input) {
|
|
130
149
|
input.value = sensorRate;
|
|
131
150
|
}
|
|
@@ -146,17 +165,21 @@ function onSensorConfiguration(device) {
|
|
|
146
165
|
chartContainer.style.display = display;
|
|
147
166
|
});
|
|
148
167
|
}
|
|
149
|
-
}
|
|
168
|
+
});
|
|
150
169
|
}
|
|
151
170
|
/** @param {BS.Device} device */
|
|
152
171
|
function updateSensorRateInputs(device) {
|
|
153
|
-
|
|
172
|
+
BS.SensorTypes.forEach((sensorType) => {
|
|
154
173
|
/** @type {HTMLInputElement?} */
|
|
155
|
-
const input = document.querySelector(
|
|
174
|
+
const input = document.querySelector(
|
|
175
|
+
`[data-sensor-type="${sensorType}"] .input`
|
|
176
|
+
);
|
|
156
177
|
if (input) {
|
|
157
|
-
|
|
178
|
+
const containsSensorType = sensorType in device.sensorConfiguration;
|
|
179
|
+
input.closest("label").style.display = containsSensorType ? "" : "none";
|
|
180
|
+
input.disabled = !device.isConnected || !containsSensorType;
|
|
158
181
|
}
|
|
159
|
-
}
|
|
182
|
+
});
|
|
160
183
|
}
|
|
161
184
|
|
|
162
185
|
// GRAPHING
|
|
@@ -276,7 +299,9 @@ window.chartContainers = chartContainers;
|
|
|
276
299
|
/** @type {HTMLTemplateElement} */
|
|
277
300
|
const chartTemplate = document.getElementById("chartTemplate");
|
|
278
301
|
BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
279
|
-
const chartContainer = chartTemplate.content
|
|
302
|
+
const chartContainer = chartTemplate.content
|
|
303
|
+
.cloneNode(true)
|
|
304
|
+
.querySelector(".chart");
|
|
280
305
|
chartsContainer.appendChild(chartContainer);
|
|
281
306
|
chartContainers[sensorType] = chartContainer;
|
|
282
307
|
|
|
@@ -299,6 +324,12 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
299
324
|
case "rotation":
|
|
300
325
|
axesLabels = ["x", "y", "z", "w"];
|
|
301
326
|
break;
|
|
327
|
+
case "orientation":
|
|
328
|
+
axesLabels = ["heading", "pitch", "roll"];
|
|
329
|
+
break;
|
|
330
|
+
case "barometer":
|
|
331
|
+
axesLabels = ["barometer"];
|
|
332
|
+
break;
|
|
302
333
|
default:
|
|
303
334
|
console.warn(`uncaught sensorType "${sensorType}"`);
|
|
304
335
|
return;
|
|
@@ -323,36 +354,53 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
323
354
|
yRange = { min: -360, max: 360 };
|
|
324
355
|
break;
|
|
325
356
|
case "magnetometer":
|
|
326
|
-
|
|
357
|
+
yRange = { min: -100, max: 100 };
|
|
327
358
|
break;
|
|
328
359
|
case "gameRotation":
|
|
329
360
|
case "rotation":
|
|
330
361
|
yRange = { min: -1, max: 1 };
|
|
331
362
|
break;
|
|
363
|
+
case "orientation":
|
|
364
|
+
yRange = { min: -360, max: 360 };
|
|
365
|
+
break;
|
|
332
366
|
}
|
|
333
367
|
|
|
334
368
|
switch (sensorType) {
|
|
335
369
|
case "gameRotation":
|
|
336
370
|
case "rotation":
|
|
337
371
|
{
|
|
338
|
-
const eulerChartContainer = chartTemplate.content
|
|
372
|
+
const eulerChartContainer = chartTemplate.content
|
|
373
|
+
.cloneNode(true)
|
|
374
|
+
.querySelector(".chart");
|
|
339
375
|
chartsContainer.appendChild(eulerChartContainer);
|
|
340
376
|
chartContainers[`${sensorType}.euler`] = eulerChartContainer;
|
|
341
|
-
createChart(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
377
|
+
createChart(
|
|
378
|
+
eulerChartContainer.querySelector("canvas"),
|
|
379
|
+
sensorType + "Euler",
|
|
380
|
+
["yaw", "pitch", "roll"],
|
|
381
|
+
{
|
|
382
|
+
min: -Math.PI,
|
|
383
|
+
max: Math.PI,
|
|
384
|
+
}
|
|
385
|
+
);
|
|
345
386
|
}
|
|
346
387
|
break;
|
|
347
388
|
case "pressure":
|
|
348
389
|
{
|
|
349
|
-
const pressureMetadataChartContainer = chartTemplate.content
|
|
390
|
+
const pressureMetadataChartContainer = chartTemplate.content
|
|
391
|
+
.cloneNode(true)
|
|
392
|
+
.querySelector(".chart");
|
|
350
393
|
chartsContainer.appendChild(pressureMetadataChartContainer);
|
|
351
394
|
chartContainers["pressureMetadata"] = pressureMetadataChartContainer;
|
|
352
|
-
createChart(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
395
|
+
createChart(
|
|
396
|
+
pressureMetadataChartContainer.querySelector("canvas"),
|
|
397
|
+
"pressureMetadata",
|
|
398
|
+
["sum", "x", "y"],
|
|
399
|
+
{
|
|
400
|
+
min: 0,
|
|
401
|
+
max: 1,
|
|
402
|
+
}
|
|
403
|
+
);
|
|
356
404
|
}
|
|
357
405
|
break;
|
|
358
406
|
}
|
|
@@ -361,7 +409,12 @@ BS.ContinuousSensorTypes.forEach((sensorType) => {
|
|
|
361
409
|
const euler = new THREE.Euler();
|
|
362
410
|
euler.reorder("YXZ");
|
|
363
411
|
|
|
364
|
-
createChart(
|
|
412
|
+
createChart(
|
|
413
|
+
chartContainer.querySelector("canvas"),
|
|
414
|
+
sensorType,
|
|
415
|
+
axesLabels,
|
|
416
|
+
yRange
|
|
417
|
+
);
|
|
365
418
|
});
|
|
366
419
|
|
|
367
420
|
/** @param {BS.Device} device */
|
|
@@ -437,12 +490,16 @@ if (false)
|
|
|
437
490
|
|
|
438
491
|
const websocketClient = new BS.WebSocketClient();
|
|
439
492
|
/** @type {HTMLButtonElement} */
|
|
440
|
-
const toggleServerConnectionButton = document.getElementById(
|
|
493
|
+
const toggleServerConnectionButton = document.getElementById(
|
|
494
|
+
"toggleServerConnection"
|
|
495
|
+
);
|
|
441
496
|
toggleServerConnectionButton.addEventListener("click", () => {
|
|
442
497
|
websocketClient.toggleConnection();
|
|
443
498
|
});
|
|
444
499
|
websocketClient.addEventListener("isConnected", () => {
|
|
445
|
-
toggleServerConnectionButton.innerText = websocketClient.isConnected
|
|
500
|
+
toggleServerConnectionButton.innerText = websocketClient.isConnected
|
|
501
|
+
? "disconnect from server"
|
|
502
|
+
: "connect to server";
|
|
446
503
|
});
|
|
447
504
|
websocketClient.addEventListener("connectionStatus", () => {
|
|
448
505
|
let disabled;
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<title>Microphone | BrilliantSole JavaScript SDK</title>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
5
|
+
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
|
6
|
+
<script src="https://unpkg.com/peaks.js/dist/peaks.js"></script>
|
|
7
|
+
<script type="module" src="./script.js"></script>
|
|
8
|
+
<script type="module" src="./whisper.js"></script>
|
|
9
|
+
<script type="module" src="./whisper-realtime.js"></script>
|
|
10
|
+
<script type="module" src="./gender.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<style>
|
|
13
|
+
#zoomview-container,
|
|
14
|
+
#overview-container {
|
|
15
|
+
width: 1000px;
|
|
16
|
+
height: 100px;
|
|
17
|
+
}
|
|
18
|
+
.highlighted {
|
|
19
|
+
color: green;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
<body>
|
|
23
|
+
<nav>
|
|
24
|
+
<a href="../../">home</a>
|
|
25
|
+
</nav>
|
|
26
|
+
|
|
27
|
+
<h1>Microphone | BrilliantSole JavaScript SDK</h1>
|
|
28
|
+
|
|
29
|
+
<button id="toggleConnection">connect</button>
|
|
30
|
+
<label>
|
|
31
|
+
model type
|
|
32
|
+
<select id="modelType">
|
|
33
|
+
<optgroup label="model type">
|
|
34
|
+
<option>none</option>
|
|
35
|
+
</optgroup>
|
|
36
|
+
</select>
|
|
37
|
+
</label>
|
|
38
|
+
<br />
|
|
39
|
+
|
|
40
|
+
<label><b>status:</b> <span id="microphoneStatus"></span></label>
|
|
41
|
+
|
|
42
|
+
<button disabled hidden id="toggleMicrophone">start microphone</button>
|
|
43
|
+
<button disabled id="startMicrophone">start microphone</button>
|
|
44
|
+
<button disabled id="stopMicrophone">stop microphone</button>
|
|
45
|
+
<button disabled id="enableMicrphoneVad">
|
|
46
|
+
enable microphone voice activity detection
|
|
47
|
+
</button>
|
|
48
|
+
<br />
|
|
49
|
+
<button disabled id="toggleMicrophoneRecording">start recording</button>
|
|
50
|
+
|
|
51
|
+
<br />
|
|
52
|
+
<label>
|
|
53
|
+
<b>microphone configuration: </b>
|
|
54
|
+
<pre id="microphoneConfigurationPre"></pre>
|
|
55
|
+
</label>
|
|
56
|
+
<br />
|
|
57
|
+
|
|
58
|
+
<div id="microphoneConfiguration">
|
|
59
|
+
<template id="microphoneConfigurationTypeTemplate">
|
|
60
|
+
<label class="microphoneConfigurationType">
|
|
61
|
+
<b class="type"></b> <span hidden></span>
|
|
62
|
+
<select disabled>
|
|
63
|
+
<optgroup></optgroup>
|
|
64
|
+
</select>
|
|
65
|
+
</label>
|
|
66
|
+
</template>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<div>
|
|
70
|
+
<b>stream</b>
|
|
71
|
+
<br />
|
|
72
|
+
<audio id="microphoneStream" controls autoplay></audio>
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<label>
|
|
76
|
+
visualization type
|
|
77
|
+
<select id="audioVisualizationType">
|
|
78
|
+
<optgroup label="type">
|
|
79
|
+
<option>waveform</option>
|
|
80
|
+
<option>fft</option>
|
|
81
|
+
</optgroup>
|
|
82
|
+
</select>
|
|
83
|
+
</label>
|
|
84
|
+
<br />
|
|
85
|
+
<canvas id="audioVisualizer" width="1000" height="200"></canvas>
|
|
86
|
+
|
|
87
|
+
<h1 id="modelResults"></h1>
|
|
88
|
+
|
|
89
|
+
<div>
|
|
90
|
+
<b>recording</b>
|
|
91
|
+
<label>
|
|
92
|
+
auto play
|
|
93
|
+
<input type="checkbox" id="autoPlayMicrphoneRecording" />
|
|
94
|
+
</label>
|
|
95
|
+
<br />
|
|
96
|
+
<audio id="microphoneRecording" controls></audio>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<div id="zoomview-container"></div>
|
|
100
|
+
<div id="overview-container"></div>
|
|
101
|
+
</body>
|
|
102
|
+
</html>
|