speaker-calibration 2.2.220 → 2.2.222
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/dist/example/i18n.js +1699 -1531
- package/dist/example/listener.html +6 -4
- package/dist/listener.js +2 -2
- package/dist/main.js +3 -3
- package/package.json +1 -1
- package/src/listener-app/listener.js +42 -9
- package/src/peer-connection/speaker.js +9 -1
- package/src/tasks/audioCalibrator.js +4 -4
- package/src/tasks/combination/combination.js +6 -2
package/package.json
CHANGED
|
@@ -307,14 +307,48 @@ switch (isSmartPhone) {
|
|
|
307
307
|
case 'false':
|
|
308
308
|
// Initialize listener immediately
|
|
309
309
|
listenerParameters.microphoneDeviceId = urlParams.get('deviceId');
|
|
310
|
-
window.listener = new Listener(listenerParameters);
|
|
311
310
|
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
// Wrap initialization in an IIFE
|
|
312
|
+
(async function initializeDesktopMode() {
|
|
313
|
+
window.listener = new Listener(listenerParameters);
|
|
314
|
+
await window.listener.initializePeer();
|
|
316
315
|
|
|
317
|
-
|
|
316
|
+
const timeout = 30000; // 30 seconds timeout
|
|
317
|
+
const startTime = Date.now();
|
|
318
|
+
|
|
319
|
+
// Wait for peer connection setup with timeout
|
|
320
|
+
while (Date.now() - startTime < timeout) {
|
|
321
|
+
if (
|
|
322
|
+
window.listener.peer.id !== null &&
|
|
323
|
+
window.listener.conn !== null &&
|
|
324
|
+
window.listener.connOpen
|
|
325
|
+
) {
|
|
326
|
+
console.log('Connection established successfully');
|
|
327
|
+
// Continue with desktop setup
|
|
328
|
+
setupDesktopUI();
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
console.log('Waiting for connection setup...');
|
|
332
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// If we get here, we've timed out
|
|
336
|
+
console.error('Connection setup timed out after 30 seconds');
|
|
337
|
+
// const message = document.getElementById('message');
|
|
338
|
+
// message.innerText = phrases.RC_microphonePermissionDenied['en-US'];
|
|
339
|
+
})().catch(console.error);
|
|
340
|
+
|
|
341
|
+
function setupDesktopUI() {
|
|
342
|
+
// remove the button
|
|
343
|
+
const calibrationBeginButton2 = document.getElementById('calibrationBeginButton');
|
|
344
|
+
calibrationBeginButton2.remove();
|
|
345
|
+
container.style.display = 'block';
|
|
346
|
+
|
|
347
|
+
//update the display to be
|
|
348
|
+
const display = document.getElementById('display');
|
|
349
|
+
if (display) {
|
|
350
|
+
display.style.textAlign = 'left';
|
|
351
|
+
}
|
|
318
352
|
// set the text of the html elements
|
|
319
353
|
recordingInProgressElement.innerText = recordingInProgress;
|
|
320
354
|
allowMicrophoneElement.innerText = allowMicrophone;
|
|
@@ -337,8 +371,7 @@ switch (isSmartPhone) {
|
|
|
337
371
|
p.innerText = backToExperimentWindow;
|
|
338
372
|
message.appendChild(p);
|
|
339
373
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
});
|
|
374
|
+
window.listener.startCalibration();
|
|
375
|
+
}
|
|
343
376
|
break;
|
|
344
377
|
}
|
|
@@ -46,6 +46,7 @@ class Speaker extends AudioPeer {
|
|
|
46
46
|
this.buttonsContainer = params?.buttonsContainer ?? document.createElement('div');
|
|
47
47
|
this.phrases = params?.phrases ?? {};
|
|
48
48
|
this.permissionStatus = 'pending';
|
|
49
|
+
this.calibrateSoundHz = params?.calibrateSoundHz ?? 48000;
|
|
49
50
|
|
|
50
51
|
/* Set up callbacks that handle any events related to our peer object. */
|
|
51
52
|
}
|
|
@@ -216,6 +217,7 @@ class Speaker extends AudioPeer {
|
|
|
216
217
|
params.calibrateSoundBurstNormalizeBy1000HzGainBool,
|
|
217
218
|
params.calibrateSoundBurstScalarDB,
|
|
218
219
|
params.calibrateSound1000HzMaxSD_dB,
|
|
220
|
+
params.calibrateSound1000HzMaxTries,
|
|
219
221
|
params._calibrateSoundBurstMaxSD_dB,
|
|
220
222
|
params.calibrateSoundSamplingDesiredBits,
|
|
221
223
|
params.language,
|
|
@@ -647,7 +649,12 @@ class Speaker extends AudioPeer {
|
|
|
647
649
|
|
|
648
650
|
switch (data.name) {
|
|
649
651
|
case 'samplingRate':
|
|
650
|
-
|
|
652
|
+
console.log('Received sampling rate from listener: ', data.payload);
|
|
653
|
+
if (!data.payload) {
|
|
654
|
+
this.ac.setSamplingRates(this.calibrateSoundHz);
|
|
655
|
+
} else {
|
|
656
|
+
this.ac.setSamplingRates(data.payload);
|
|
657
|
+
}
|
|
651
658
|
break;
|
|
652
659
|
case 'sampleSize':
|
|
653
660
|
this.ac.setSampleSize(data.payload);
|
|
@@ -781,6 +788,7 @@ class Speaker extends AudioPeer {
|
|
|
781
788
|
params.calibrateSoundBurstNormalizeBy1000HzGainBool,
|
|
782
789
|
params.calibrateSoundBurstScalarDB,
|
|
783
790
|
params.calibrateSound1000HzMaxSD_dB,
|
|
791
|
+
params.calibrateSound1000HzMaxTries,
|
|
784
792
|
params._calibrateSoundBurstMaxSD_dB,
|
|
785
793
|
params.calibrateSoundSamplingDesiredBits,
|
|
786
794
|
params.language,
|
|
@@ -203,13 +203,13 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
203
203
|
lCalib = 104.92978421490648,
|
|
204
204
|
checkRec,
|
|
205
205
|
checkSD,
|
|
206
|
-
maxSD
|
|
206
|
+
maxSD,
|
|
207
|
+
maxRetry
|
|
207
208
|
) => {
|
|
208
209
|
this.numCalibratingRoundsCompleted = 0;
|
|
209
|
-
this.numCalibratingRounds = 2;
|
|
210
210
|
console.log("maxSD in VolumeCaibrationSteps: ", maxSD, '0' >= maxSD);
|
|
211
211
|
// calibration loop
|
|
212
|
-
while (!this.isCalibrating && this.numCalibratingRoundsCompleted <
|
|
212
|
+
while (!this.isCalibrating && this.numCalibratingRoundsCompleted < maxRetry) {
|
|
213
213
|
if (this.isCalibrating) break;
|
|
214
214
|
// before recording
|
|
215
215
|
await beforeRecord(gainValue);
|
|
@@ -231,7 +231,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
231
231
|
let sdMessage;
|
|
232
232
|
if (sd <= maxSD) {
|
|
233
233
|
console.log(`SD =${sd}, less than calibrateSound1000HzMaxSD_dB=${maxSD}`);
|
|
234
|
-
this.numCalibratingRoundsCompleted +=
|
|
234
|
+
this.numCalibratingRoundsCompleted += maxRetry;
|
|
235
235
|
sdMessage = `. SD = ${sd} dB`;
|
|
236
236
|
|
|
237
237
|
} else {
|
|
@@ -2469,7 +2469,8 @@ class Combination extends AudioCalibrator {
|
|
|
2469
2469
|
() => {
|
|
2470
2470
|
return this.recordingChecks['volume'][this.inDB]['sd'];
|
|
2471
2471
|
},
|
|
2472
|
-
this.calibrateSound1000HzMaxSD_dB
|
|
2472
|
+
this.calibrateSound1000HzMaxSD_dB,
|
|
2473
|
+
this.calibrateSound1000HzMaxTries
|
|
2473
2474
|
);
|
|
2474
2475
|
} while (this.outDBSPL === null);
|
|
2475
2476
|
//reset the values
|
|
@@ -2513,7 +2514,8 @@ class Combination extends AudioCalibrator {
|
|
|
2513
2514
|
() => {
|
|
2514
2515
|
return this.recordingChecks?.['volume']?.[this.inDB]?.['sd'] || 0;
|
|
2515
2516
|
},
|
|
2516
|
-
this.calibrateSound1000HzMaxSD_dB
|
|
2517
|
+
this.calibrateSound1000HzMaxSD_dB,
|
|
2518
|
+
this.calibrateSound1000HzMaxTries
|
|
2517
2519
|
);
|
|
2518
2520
|
} while (this.outDBSPL === null);
|
|
2519
2521
|
outDBSPL1000Values.push(this.outDBSPL1000);
|
|
@@ -2885,6 +2887,7 @@ class Combination extends AudioCalibrator {
|
|
|
2885
2887
|
_calibrateSoundBurstNormalizeBy1000HzGainBool = false,
|
|
2886
2888
|
_calibrateSoundBurstScalarDB = 71,
|
|
2887
2889
|
calibrateSound1000HzMaxSD_dB = 4,
|
|
2890
|
+
calibrateSound1000HzMaxTries = 4,
|
|
2888
2891
|
_calibrateSoundBurstMaxSD_dB = 4,
|
|
2889
2892
|
calibrateSoundSamplingDesiredBits = 24,
|
|
2890
2893
|
language,
|
|
@@ -2945,6 +2948,7 @@ class Combination extends AudioCalibrator {
|
|
|
2945
2948
|
//feed calibration goal here
|
|
2946
2949
|
this._calibrateSoundCheck = _calibrateSoundCheck;
|
|
2947
2950
|
this.calibrateSound1000HzMaxSD_dB = calibrateSound1000HzMaxSD_dB;
|
|
2951
|
+
this.calibrateSound1000HzMaxTries = calibrateSound1000HzMaxTries;
|
|
2948
2952
|
this._calibrateSoundBurstMaxSD_dB = _calibrateSoundBurstMaxSD_dB;
|
|
2949
2953
|
//check if a componentIR was given to the system, if it isn't check for the microphone. using dummy data here bc we need to
|
|
2950
2954
|
//check the db based on the microphone currently connected
|