speaker-calibration 2.2.66 → 2.2.68

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": "speaker-calibration",
3
- "version": "2.2.66",
3
+ "version": "2.2.68",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -27,6 +27,7 @@ class Speaker extends AudioPeer {
27
27
  */
28
28
  constructor(params, CalibratorInstance) {
29
29
  super(params);
30
+ this.language = params?.language ?? 'en-US';
30
31
  this.siteUrl += '/listener?';
31
32
  this.ac = CalibratorInstance;
32
33
  this.result = null;
@@ -199,6 +200,7 @@ class Speaker extends AudioPeer {
199
200
  isSmartPhone: this.isSmartPhone,
200
201
  calibrateSoundHz: this.calibrateSoundHz,
201
202
  calibrateSoundSamplingDesiredBits: this.calibrateSoundSamplingDesiredBits,
203
+ lang: this.language,
202
204
  };
203
205
  const queryString = this.queryStringFromObject(queryStringParameters);
204
206
  const uri = this.siteUrl + queryString;
@@ -257,7 +259,7 @@ class Speaker extends AudioPeer {
257
259
  instructionDisplay.style.whiteSpace = 'nowrap';
258
260
  instructionDisplay.style.fontWeight = 'bold';
259
261
  instructionDisplay.style.width = 'fit-content';
260
- instructionDisplay.innerHTML = phrases.RC_soundRecording['en-US'];
262
+ instructionDisplay.innerHTML = phrases.RC_soundRecording[this.language];
261
263
  let fontSize = 100;
262
264
  instructionDisplay.style.fontSize = fontSize + 'px';
263
265
  while (instructionDisplay.scrollWidth > background.scrollWidth * 0.9 && fontSize > 10) {
@@ -276,7 +278,7 @@ class Speaker extends AudioPeer {
276
278
 
277
279
  const timeToCalibrateDisplay = document.getElementById(this.timeToCalibrateDisplay);
278
280
  if (timeToCalibrateDisplay) {
279
- const timeToCalibrateText = phrases.RC_howLongToCalibrate['en-US'];
281
+ const timeToCalibrateText = phrases.RC_howLongToCalibrate[this.language];
280
282
  timeToCalibrateDisplay.innerHTML = timeToCalibrateText.replace('111', this.timeToCalibrate);
281
283
  timeToCalibrateDisplay.style.fontWeight = 'normal';
282
284
  timeToCalibrateDisplay.style.fontSize = '1rem';
@@ -289,7 +291,7 @@ class Speaker extends AudioPeer {
289
291
  // replace 5 with 6
290
292
  titleDisplay.innerHTML = this.isSmartPhone
291
293
  ? titleDisplay.innerHTML.replace('2', '3')
292
- : titleDisplay.innerHTML.replace('5', '6');
294
+ : titleDisplay.innerHTML.replace('4', '5');
293
295
  }
294
296
  };
295
297
 
@@ -187,6 +187,12 @@ class Combination extends AudioCalibrator {
187
187
  },
188
188
  };
189
189
 
190
+ /** @private */
191
+ timeStamp = [];
192
+
193
+ /** @private */
194
+ startTime;
195
+
190
196
  /**generate string template that gets reevaluated as variable increases */
191
197
  generateTemplate = () => {
192
198
  if (this.percent_complete > 100) {
@@ -223,6 +229,7 @@ class Combination extends AudioCalibrator {
223
229
  * @example
224
230
  */
225
231
  sendSystemImpulseResponsesToServerForProcessing = async () => {
232
+ this.addTimeStamp("Get system iir");
226
233
  const computedIRs = await Promise.all(this.impulseResponses);
227
234
  const filteredComputedIRs = computedIRs.filter(element => {
228
235
  return element != undefined;
@@ -276,6 +283,7 @@ class Combination extends AudioCalibrator {
276
283
  * @example
277
284
  */
278
285
  sendComponentImpulseResponsesToServerForProcessing = async () => {
286
+ this.addTimeStamp("Get component iir");
279
287
  const computedIRs = await Promise.all(this.impulseResponses);
280
288
  const filteredComputedIRs = computedIRs.filter(element => {
281
289
  return element != undefined;
@@ -337,6 +345,7 @@ class Combination extends AudioCalibrator {
337
345
  // Slice the array from the calculated start index to the end of the array
338
346
  const background_rec = background_rec_whole.slice(startIndex);
339
347
  console.log('Sending background recording to server for processing');
348
+ this.addTimeStamp("Get background PSD");
340
349
  this.pyServerAPI
341
350
  .getBackgroundNoisePSDWithRetry({
342
351
  background_rec,
@@ -694,6 +703,7 @@ class Combination extends AudioCalibrator {
694
703
  this.#currentConvolution = this.componentConvolution;
695
704
  this.filteredMLSRange.component.Min = findMinValue(this.#currentConvolution);
696
705
  this.filteredMLSRange.component.Max = findMaxValue(this.#currentConvolution);
706
+ this.addTimeStamp("Play MLS with component IIR");
697
707
  await this.playMLSwithIIR(stream, this.#currentConvolution);
698
708
  this.#stopCalibrationAudio();
699
709
  let component_conv_recs = this.getAllFilteredRecordedSignals();
@@ -701,6 +711,7 @@ class Combination extends AudioCalibrator {
701
711
  this.clearAllFilteredRecordedSignals();
702
712
 
703
713
  this.#currentConvolution = this.testConvolution;
714
+ this.addTimeStamp("Play MLS with test IIR");
704
715
  await this.playMLSwithIIR(stream, this.#currentConvolution);
705
716
  this.#stopCalibrationAudio();
706
717
  let test_conv_recs = this.getAllFilteredRecordedSignals();
@@ -710,6 +721,7 @@ class Combination extends AudioCalibrator {
710
721
  this.#currentConvolution = this.systemConvolution;
711
722
  this.filteredMLSRange.system.Min = findMinValue(this.#currentConvolution);
712
723
  this.filteredMLSRange.system.Max = findMaxValue(this.#currentConvolution);
724
+ this.addTimeStamp("Play MLS with system IIR");
713
725
  await this.playMLSwithIIR(stream, this.#currentConvolution);
714
726
  this.#stopCalibrationAudio();
715
727
  let system_conv_recs = this.getAllFilteredRecordedSignals();
@@ -727,6 +739,7 @@ class Combination extends AudioCalibrator {
727
739
  let knownGain = this.oldComponentIR.Gain;
728
740
  let knownFreq = this.oldComponentIR.Freq;
729
741
  let sampleRate = this.sourceSamplingRate || 96000;
742
+ this.addTimeStamp("Get PSD of mls recording");
730
743
  let component_unconv_rec_psd = await this.pyServerAPI
731
744
  .getSubtractedPSDWithRetry(unconv_rec, knownGain, knownFreq, sampleRate)
732
745
  .then(res => {
@@ -741,6 +754,7 @@ class Combination extends AudioCalibrator {
741
754
  console.error(err);
742
755
  });
743
756
 
757
+ this.addTimeStamp("Get PSD of filtered recording (component)");
744
758
  let component_conv_rec_psd = await this.pyServerAPI
745
759
  .getSubtractedPSDWithRetry(conv_rec, knownGain, knownFreq, sampleRate)
746
760
  .then(res => {
@@ -754,7 +768,8 @@ class Combination extends AudioCalibrator {
754
768
  .catch(err => {
755
769
  console.error(err);
756
770
  });
757
-
771
+
772
+ this.addTimeStamp("Get PSD of filtered recording (test component)");
758
773
  let test_conv_rec_psd = await this.pyServerAPI
759
774
  .getSubtractedPSDWithRetry(return_test_conv_rec, knownGain, knownFreq, sampleRate)
760
775
  .then(res => {
@@ -771,6 +786,7 @@ class Combination extends AudioCalibrator {
771
786
 
772
787
  conv_rec = system_conv_recs[0];
773
788
  //psd of system
789
+ this.addTimeStamp("Get PSD of filtered recording (system) and unfiltered recording");
774
790
  let system_recs_psd = await this.pyServerAPI
775
791
  .getPSDWithRetry({
776
792
  unconv_rec,
@@ -792,6 +808,7 @@ class Combination extends AudioCalibrator {
792
808
  //iir w/ and without bandpass psd. done
793
809
  unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
794
810
  conv_rec = this.componentInvertedImpulseResponse;
811
+ this.addTimeStamp("Get PSD of component iir and component iir no band pass");
795
812
  let component_iir_psd = await this.pyServerAPI
796
813
  .getPSDWithRetry({
797
814
  unconv_rec,
@@ -811,6 +828,7 @@ class Combination extends AudioCalibrator {
811
828
  });
812
829
  unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
813
830
  conv_rec = this.systemInvertedImpulseResponse;
831
+ this.addTimeStamp("Get PSD of system iir and system iir no band pass");
814
832
  let system_iir_psd = await this.pyServerAPI
815
833
  .getPSDWithRetry({
816
834
  unconv_rec,
@@ -828,7 +846,8 @@ class Combination extends AudioCalibrator {
828
846
  .catch(err => {
829
847
  console.error(err);
830
848
  });
831
-
849
+
850
+ this.addTimeStamp("Get PSD of mls sequence");
832
851
  let mls_psd = await this.pyServerAPI
833
852
  .getMLSPSDWithRetry({mls: this.#mlsBufferView, sampleRate: this.sourceSamplingRate || 96000})
834
853
  .then(res => {
@@ -843,6 +862,8 @@ class Combination extends AudioCalibrator {
843
862
  console.error(err);
844
863
  });
845
864
 
865
+
866
+ this.addTimeStamp("Get PSD of filered mls (system)");
846
867
  let system_filtered_mls_psd = await this.pyServerAPI
847
868
  .getMLSPSDWithRetry({
848
869
  mls: this.systemConvolution,
@@ -860,6 +881,8 @@ class Combination extends AudioCalibrator {
860
881
  console.error(err);
861
882
  });
862
883
 
884
+
885
+ this.addTimeStamp("Get PSD of filered mls (component)");
863
886
  let component_filtered_mls_psd = await this.pyServerAPI
864
887
  .getMLSPSDWithRetry({
865
888
  mls: this.componentConvolution,
@@ -955,10 +978,12 @@ class Combination extends AudioCalibrator {
955
978
  this.#currentConvolution = this.componentConvolution;
956
979
  this.filteredMLSRange.component.Min = findMinValue(this.#currentConvolution);
957
980
  this.filteredMLSRange.component.Max = findMaxValue(this.#currentConvolution);
981
+ this.addTimeStamp("Play MLS with component IIR");
958
982
  } else {
959
983
  this.#currentConvolution = this.systemConvolution;
960
984
  this.filteredMLSRange.system.Min = findMinValue(this.#currentConvolution);
961
985
  this.filteredMLSRange.system.Max = findMaxValue(this.#currentConvolution);
986
+ this.addTimeStamp("Play MLS with system IIR");
962
987
  }
963
988
  await this.playMLSwithIIR(stream, this.#currentConvolution);
964
989
  this.#stopCalibrationAudio();
@@ -972,6 +997,7 @@ class Combination extends AudioCalibrator {
972
997
  let conv_rec = conv_recs[0];
973
998
  let return_conv_rec = conv_rec;
974
999
  if (this._calibrateSoundCheck != 'system') {
1000
+ this.addTimeStamp("Play MLS with test IIR");
975
1001
  this.#currentConvolution = this.testConvolution;
976
1002
  await this.playMLSwithIIR(stream, this.#currentConvolution);
977
1003
  this.#stopCalibrationAudio();
@@ -983,6 +1009,7 @@ class Combination extends AudioCalibrator {
983
1009
  let knownGain = this.oldComponentIR.Gain;
984
1010
  let knownFreq = this.oldComponentIR.Freq;
985
1011
  let sampleRate = this.sourceSamplingRate || 96000;
1012
+ this.addTimeStamp("Get PSD of mls recording");
986
1013
  let unconv_results = await this.pyServerAPI
987
1014
  .getSubtractedPSDWithRetry(unconv_rec, knownGain, knownFreq, sampleRate)
988
1015
  .then(res => {
@@ -997,6 +1024,7 @@ class Combination extends AudioCalibrator {
997
1024
  console.error(err);
998
1025
  });
999
1026
 
1027
+ this.addTimeStamp("Get PSD recording of filtered recording (component)");
1000
1028
  let conv_results = await this.pyServerAPI
1001
1029
  .getSubtractedPSDWithRetry(conv_rec, knownGain, knownFreq, sampleRate)
1002
1030
  .then(res => {
@@ -1010,7 +1038,8 @@ class Combination extends AudioCalibrator {
1010
1038
  .catch(err => {
1011
1039
  console.error(err);
1012
1040
  });
1013
-
1041
+
1042
+ this.addTimeStamp("Get PSD of filtered recording (test component)");
1014
1043
  let test_conv_results = await this.pyServerAPI
1015
1044
  .getSubtractedPSDWithRetry(return_test_conv_rec, knownGain, knownFreq, sampleRate)
1016
1045
  .then(res => {
@@ -1027,6 +1056,7 @@ class Combination extends AudioCalibrator {
1027
1056
 
1028
1057
  unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
1029
1058
  conv_rec = this.componentInvertedImpulseResponse;
1059
+ this.addTimeStamp("Get PSD of component iir and component iir no bandpass");
1030
1060
  let component_iir_psd = await this.pyServerAPI
1031
1061
  .getPSDWithRetry({
1032
1062
  unconv_rec,
@@ -1046,6 +1076,7 @@ class Combination extends AudioCalibrator {
1046
1076
  });
1047
1077
  unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
1048
1078
  conv_rec = this.systemInvertedImpulseResponse;
1079
+ this.addTimeStamp("Get PSD of system iir and system iir no bandpass");
1049
1080
  let system_iir_psd = await this.pyServerAPI
1050
1081
  .getPSDWithRetry({
1051
1082
  unconv_rec,
@@ -1063,7 +1094,8 @@ class Combination extends AudioCalibrator {
1063
1094
  .catch(err => {
1064
1095
  console.error(err);
1065
1096
  });
1066
-
1097
+
1098
+ this.addTimeStamp("Get PSD of mls sequence");
1067
1099
  let mls_psd = await this.pyServerAPI
1068
1100
  .getMLSPSDWithRetry({
1069
1101
  mls: this.#mlsBufferView,
@@ -1081,6 +1113,7 @@ class Combination extends AudioCalibrator {
1081
1113
  console.error(err);
1082
1114
  });
1083
1115
 
1116
+ this.addTimeStamp("Get PSD of filtered mls (component)");
1084
1117
  let filtered_mls_psd = await this.pyServerAPI
1085
1118
  .getMLSPSDWithRetry({
1086
1119
  mls: this.componentConvolution,
@@ -1162,6 +1195,7 @@ class Combination extends AudioCalibrator {
1162
1195
  impulseResponses: [],
1163
1196
  };
1164
1197
  } else {
1198
+ this.addTimeStamp("Get PSD of filtered recording (system) and unfiltered recording");
1165
1199
  let results = await this.pyServerAPI
1166
1200
  .getPSDWithRetry({
1167
1201
  unconv_rec,
@@ -1183,6 +1217,7 @@ class Combination extends AudioCalibrator {
1183
1217
  //iir w/ and without bandpass psd
1184
1218
  unconv_rec = this.componentInvertedImpulseResponseNoBandpass;
1185
1219
  conv_rec = this.componentInvertedImpulseResponse;
1220
+ this.addTimeStamp("Get PSD of component iir and component iir no band pass");
1186
1221
  let component_iir_psd = await this.pyServerAPI
1187
1222
  .getPSDWithRetry({
1188
1223
  unconv_rec,
@@ -1202,6 +1237,7 @@ class Combination extends AudioCalibrator {
1202
1237
  });
1203
1238
  unconv_rec = this.systemInvertedImpulseResponseNoBandpass;
1204
1239
  conv_rec = this.systemInvertedImpulseResponse;
1240
+ this.addTimeStamp("Get PSD of system iir and system iir no band pass");
1205
1241
  let system_iir_psd = await this.pyServerAPI
1206
1242
  .getPSDWithRetry({
1207
1243
  unconv_rec,
@@ -1220,6 +1256,7 @@ class Combination extends AudioCalibrator {
1220
1256
  console.error(err);
1221
1257
  });
1222
1258
 
1259
+ this.addTimeStamp("Get PSD of mls sequence");
1223
1260
  let mls_psd = await this.pyServerAPI
1224
1261
  .getMLSPSDWithRetry({
1225
1262
  mls: this.#mlsBufferView,
@@ -1237,6 +1274,8 @@ class Combination extends AudioCalibrator {
1237
1274
  console.error(err);
1238
1275
  });
1239
1276
 
1277
+
1278
+ this.addTimeStamp("Get PSD of filtered mls (system)");
1240
1279
  let filtered_mls_psd = await this.pyServerAPI
1241
1280
  .getMLSPSDWithRetry({
1242
1281
  mls: this.systemConvolution,
@@ -1359,6 +1398,8 @@ class Combination extends AudioCalibrator {
1359
1398
  * @example
1360
1399
  */
1361
1400
  startCalibrationImpulseResponse = async stream => {
1401
+
1402
+
1362
1403
  let desired_time = this.desired_time_per_mls;
1363
1404
  let checkRec = 'allhz';
1364
1405
 
@@ -1367,6 +1408,7 @@ class Combination extends AudioCalibrator {
1367
1408
  length = this.sourceSamplingRate * desired_time;
1368
1409
  //get mls here
1369
1410
  const calibrateSoundBurstDb = this._calibrateSoundBurstDb;
1411
+ this.addTimeStamp("Get MLS sequence");
1370
1412
  await this.pyServerAPI
1371
1413
  .getMLSWithRetry({length, calibrateSoundBurstDb})
1372
1414
  .then(res => {
@@ -1675,6 +1717,7 @@ class Combination extends AudioCalibrator {
1675
1717
 
1676
1718
  #sendToServerForProcessing = lCalib => {
1677
1719
  console.log('Sending data to server');
1720
+ this.addTimeStamp("Send volume data to server");
1678
1721
  let left = this.calibrateSound1000HzPreSec;
1679
1722
  let right = this.calibrateSound1000HzPreSec + this.calibrateSound1000HzSec;
1680
1723
  this.pyServerAPI
@@ -1714,7 +1757,8 @@ class Combination extends AudioCalibrator {
1714
1757
  this.generateTemplate().toString();
1715
1758
  //this.emit('update', {message: `1000 Hz Calibration: Sound Level ${soundLevelToDiscard} dB`});
1716
1759
  this.emit('update', {message: this.status});
1717
-
1760
+ this.startTime = new Date().getTime();
1761
+
1718
1762
  do {
1719
1763
  // eslint-disable-next-line no-await-in-loop
1720
1764
  await this.volumeCalibrationSteps(
@@ -1772,6 +1816,8 @@ class Combination extends AudioCalibrator {
1772
1816
  }
1773
1817
 
1774
1818
  // get the volume calibration parameters from the server
1819
+ this.addTimeStamp("Get Volume Calibration Parameters");
1820
+
1775
1821
  const parameters = await this.pyServerAPI
1776
1822
  .getVolumeCalibrationParameters({
1777
1823
  inDBValues: inDBValues,
@@ -1890,6 +1936,12 @@ class Combination extends AudioCalibrator {
1890
1936
  }
1891
1937
  };
1892
1938
 
1939
+ // add time stamp
1940
+ addTimeStamp = (taskName) => {
1941
+ let startTaskTime = (new Date().getTime() - this.startTime)/1000;
1942
+ this.timeStamp.push(`SOUND ${Number(startTaskTime.toFixed(1))} s. ${taskName}`);
1943
+ }
1944
+
1893
1945
  // Example of how to use the writeFrqGain and readFrqGain functions
1894
1946
  // writeFrqGain('speaker1', [1, 2, 3], [4, 5, 6]);
1895
1947
  // Speaker1 is the speakerID you want to write to in the database
@@ -1950,7 +2002,7 @@ class Combination extends AudioCalibrator {
1950
2002
  ? this.deviceInfo.OEM.toLowerCase().split(' ').join('')
1951
2003
  : micManufacturer;
1952
2004
  // const ID = "711-4754";
1953
- // const OEM = "MiniDSP";
2005
+ // const OEM = "minidsp";
1954
2006
  const micInfo = {
1955
2007
  micModelName: isSmartPhone ? micModelName : microphoneName,
1956
2008
  OEM: OEM,
@@ -2026,9 +2078,13 @@ class Combination extends AudioCalibrator {
2026
2078
  total_results['audioInfo']['sinkSampleRate'] = this.sinkSamplingRate;
2027
2079
  total_results['audioInfo']['sourceSampleRate'] = this.sourceSamplingRate;
2028
2080
  total_results['audioInfo']['bitsPerSample'] = this.sampleSize;
2029
-
2081
+ const timeStampresult = [...this.timeStamp].join('\n');
2082
+ total_results["timeStamps"] = timeStampresult;
2030
2083
  console.log('total results');
2031
2084
  console.log(total_results);
2085
+ console.log('Time Stamps');
2086
+ console.log(timeStampresult);
2087
+
2032
2088
  return total_results;
2033
2089
  };
2034
2090
  }