speaker-calibration 2.2.153 → 2.2.154

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.153",
3
+ "version": "2.2.154",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -31,8 +31,7 @@
31
31
  "license": "MIT",
32
32
  "repository": "git://github.com/EasyEyes/speaker-calibration.git",
33
33
  "dependencies": {
34
- "@tensorflow/tfjs": "^4.17.0",
35
- "axios": "^0.27.2",
34
+ "axios": "^1.6.7",
36
35
  "fftw-js": "^0.1.4",
37
36
  "firebase": "^9.23.0",
38
37
  "np": "^7.7.0",
@@ -56,11 +55,11 @@
56
55
  "eslint-plugin-no-floating-promise": "^1.0.2",
57
56
  "express": "^4.17.1",
58
57
  "jest": "^27.5.1",
59
- "jsdoc": "^3.6.10",
58
+ "jsdoc": "^4.0.2",
60
59
  "nodemon": "^2.0.15",
61
60
  "prettier": "^2.5.1",
62
61
  "style-loader": "^2.0.0",
63
- "webpack": "~5.69.1",
62
+ "webpack": "^5.90.3",
64
63
  "webpack-bundle-analyzer": "^4.5.0",
65
64
  "webpack-cli": "^4.9.2"
66
65
  },
@@ -6,10 +6,10 @@ import {
6
6
  *
7
7
  */
8
8
  class PythonServerAPI {
9
- static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
9
+ // static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
10
10
 
11
11
  static TEST_SERVER_URL = 'http://127.0.0.1:5000';
12
- // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
12
+ static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
13
13
 
14
14
  /** @private */
15
15
  MAX_RETRY_COUNT = 3;
@@ -141,14 +141,15 @@ class PythonServerAPI {
141
141
  return res.data[task];
142
142
  };
143
143
 
144
- getMLS = async ({length,amplitude}) => {
144
+ getMLS = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
145
145
  const task = 'mls';
146
146
  let res = null;
147
147
 
148
148
  const data = JSON.stringify({
149
149
  task,
150
150
  length: length,
151
- amplitude: amplitude
151
+ amplitude: amplitude,
152
+ calibrateSoundBurstMLSVersions: calibrateSoundBurstMLSVersions,
152
153
  });
153
154
 
154
155
  await axios({
@@ -204,13 +205,13 @@ class PythonServerAPI {
204
205
  };
205
206
 
206
207
 
207
- getMLSWithRetry = async ({length,amplitude}) => {
208
+ getMLSWithRetry = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
208
209
  let retryCount = 0;
209
210
  let response = null;
210
211
 
211
212
  while (retryCount < this.MAX_RETRY_COUNT) {
212
213
  try {
213
- response = await this.getMLS({length,amplitude});
214
+ response = await this.getMLS({length,amplitude, calibrateSoundBurstMLSVersions});
214
215
  // If the request is successful, break out of the loop
215
216
  break;
216
217
  } catch (error) {
@@ -1,7 +1,5 @@
1
1
  import AudioCalibrator from '../audioCalibrator';
2
2
 
3
- // import * as tf from '../../../node_modules/@tensorflow/tfjs';
4
-
5
3
  import {
6
4
  sleep,
7
5
  csvToArray,
@@ -289,6 +287,7 @@ class Combination extends AudioCalibrator {
289
287
  dL_n;
290
288
  L_new_n;
291
289
  fs2;
290
+ icapture = 0;
292
291
 
293
292
  /**generate string template that gets reevaluated as variable increases */
294
293
  generateTemplate = () => {
@@ -354,7 +353,8 @@ class Combination extends AudioCalibrator {
354
353
  const filteredComputedIRs = computedIRs.filter(element => {
355
354
  return element != undefined;
356
355
  }); //log any errors that are found in this step
357
- const mls = this.#mls;
356
+ console.log("filteredComputedIRs", filteredComputedIRs);
357
+ const mls = this.#mls[this.icapture];
358
358
  const lowHz = this.#lowHz; //gain of 1 below cutoff, need gain of 0
359
359
  const highHz = this.#highHz; //check error for anything other than 10 kHz
360
360
  const iirLength = this.iirLength;
@@ -432,7 +432,7 @@ class Combination extends AudioCalibrator {
432
432
  });
433
433
  const componentIRGains = this.componentIR['Gain'];
434
434
  const componentIRFreqs = this.componentIR['Freq'];
435
- const mls = this.#mls;
435
+ const mls = this.#mls[this.icapture];
436
436
  const lowHz = this.#lowHz;
437
437
  const iirLength = this.iirLength;
438
438
  const irLength = this.irLength;
@@ -552,7 +552,7 @@ class Combination extends AudioCalibrator {
552
552
  'Obtaining last all hz unfiltered recording from #allHzUnfilteredRecordings to send to server for processing'
553
553
  );
554
554
  const numSignals = allSignals.length;
555
- const mls = this.#mlsBufferView;
555
+ const mls = this.#mlsBufferView[this.icapture];
556
556
  const payload =
557
557
  signalCsv && signalCsv.length > 0 ? csvToArray(signalCsv) : allSignals[numSignals - 1];
558
558
  console.log('sending rec');
@@ -665,7 +665,7 @@ class Combination extends AudioCalibrator {
665
665
  let time_to_wait = 0;
666
666
  if (this.mode === 'unfiltered') {
667
667
  //unfiltered
668
- time_to_wait = (this.#mls.length / this.sourceSamplingRate) * this.numMLSPerCapture;
668
+ time_to_wait = (this.#mls[0].length / this.sourceSamplingRate) * this.numMLSPerCapture;
669
669
  time_to_wait = time_to_wait * 1.1;
670
670
  } else if (this.mode === 'filtered') {
671
671
  //filtered
@@ -715,7 +715,7 @@ class Combination extends AudioCalibrator {
715
715
  let number_of_bursts_to_skip = this.num_mls_to_skip;
716
716
  let time_to_sleep = 0;
717
717
  if (this.mode === 'unfiltered') {
718
- time_to_sleep = (this.#mls.length / this.sourceSamplingRate) * number_of_bursts_to_skip;
718
+ time_to_sleep = (this.#mls[0].length / this.sourceSamplingRate) * number_of_bursts_to_skip;
719
719
  } else if (this.mode === 'filtered') {
720
720
  console.log(this.#currentConvolution.length);
721
721
  // time_to_sleep =
@@ -829,7 +829,7 @@ class Combination extends AudioCalibrator {
829
829
  * @param {*} dataBufferArray
830
830
  * @example
831
831
  */
832
- #setCalibrationNodesFromBuffer = (dataBufferArray = [this.#mlsBufferView]) => {
832
+ #setCalibrationNodesFromBuffer = (dataBufferArray = [this.#mlsBufferView[this.icapture]]) => {
833
833
  if (dataBufferArray.length === 1) {
834
834
  this.#createCalibrationNodeFromBuffer(dataBufferArray[0]);
835
835
  } else {
@@ -1052,6 +1052,7 @@ class Combination extends AudioCalibrator {
1052
1052
  .map(value => 10 * Math.log10(value));
1053
1053
 
1054
1054
  this.SDofFilteredRange['mls'] = standardDeviation(mls_psd);
1055
+ console.log('mls_psd', this.SDofFilteredRange['mls']);
1055
1056
  this.SDofFilteredRange['system'] = standardDeviation(filtered_psd);
1056
1057
  this.incrementStatusBar();
1057
1058
  this.status =
@@ -1111,7 +1112,7 @@ class Combination extends AudioCalibrator {
1111
1112
  this.addTimeStamp('Get PSD of mls sequence');
1112
1113
  if (this.isCalibrating) return null;
1113
1114
  let mls_psd = await this.pyServerAPI
1114
- .getMLSPSDWithRetry({mls: this.#mlsBufferView, sampleRate: this.sourceSamplingRate || 96000})
1115
+ .getMLSPSDWithRetry({mls: this.#mlsBufferView[0], sampleRate: this.sourceSamplingRate || 96000})
1115
1116
  .then(res => {
1116
1117
  this.incrementStatusBar();
1117
1118
  this.status =
@@ -1361,6 +1362,15 @@ class Combination extends AudioCalibrator {
1361
1362
  let unconv_results = await this.pyServerAPI
1362
1363
  .getSubtractedPSDWithRetry(unconv_rec, knownGain, knownFreq, sampleRate)
1363
1364
  .then(res => {
1365
+ console.log(res);
1366
+ let mls_psd = res.y
1367
+ .filter(
1368
+ (value, index) =>
1369
+ res.x[index] >= this.#lowHz && res.x[index] <= this.systemFMaxHz
1370
+ )
1371
+ .map(value => 10 * Math.log10(value));
1372
+ this.SDofFilteredRange['mls'] = standardDeviation(mls_psd);
1373
+ console.log('mls sd', this.SDofFilteredRange['mls']);
1364
1374
  this.incrementStatusBar();
1365
1375
  this.status =
1366
1376
  `All Hz Calibration: done computing the PSD graphs...`.toString() +
@@ -1460,7 +1470,7 @@ class Combination extends AudioCalibrator {
1460
1470
  if (this.isCalibrating) return null;
1461
1471
  let mls_psd = await this.pyServerAPI
1462
1472
  .getMLSPSDWithRetry({
1463
- mls: this.#mlsBufferView,
1473
+ mls: this.#mlsBufferView[this.icapture],
1464
1474
  sampleRate: this.sourceSamplingRate || 96000,
1465
1475
  })
1466
1476
  .then(res => {
@@ -1606,9 +1616,8 @@ class Combination extends AudioCalibrator {
1606
1616
  res.x_unconv[index] >= this.#lowHz && res.x_conv[index] <= this.systemFMaxHz
1607
1617
  )
1608
1618
  .map(value => 10 * Math.log10(value));
1609
-
1619
+ this.SDofFilteredRange['mls'] = standardDeviation(mls_psd);
1610
1620
  this.SDofFilteredRange['system'] = standardDeviation(filtered_psd);
1611
- this.SDofFilteredRange['unfiltered'] = standardDeviation(mls_psd);
1612
1621
  this.incrementStatusBar();
1613
1622
  this.status =
1614
1623
  `All Hz Calibration: done computing the PSD graphs...`.toString() +
@@ -1668,7 +1677,7 @@ class Combination extends AudioCalibrator {
1668
1677
  if (this.isCalibrating) return null;
1669
1678
  let mls_psd = await this.pyServerAPI
1670
1679
  .getMLSPSDWithRetry({
1671
- mls: this.#mlsBufferView,
1680
+ mls: this.#mlsBufferView[this.icapture],
1672
1681
  sampleRate: this.sourceSamplingRate || 96000,
1673
1682
  })
1674
1683
  .then(res => {
@@ -1857,7 +1866,11 @@ class Combination extends AudioCalibrator {
1857
1866
  this.addTimeStamp('Get MLS sequence');
1858
1867
  if (this.isCalibrating) return null;
1859
1868
  await this.pyServerAPI
1860
- .getMLSWithRetry({length, amplitude})
1869
+ .getMLSWithRetry({
1870
+ length,
1871
+ amplitude,
1872
+ calibrateSoundBurstMLSVersions: this.numCaptures
1873
+ })
1861
1874
  .then(res => {
1862
1875
  console.log(res);
1863
1876
  this.#mlsBufferView = res['mls'];
@@ -1889,18 +1902,21 @@ class Combination extends AudioCalibrator {
1889
1902
  this.numSuccessfulCaptured = 0;
1890
1903
 
1891
1904
  if (this.isCalibrating) return null;
1892
- await this.calibrationSteps(
1893
- stream,
1894
- this.#playCalibrationAudio, // play audio func (required)
1895
- this.#createCalibrationNodeFromBuffer(this.#mlsBufferView), // before play func
1896
- this.#awaitSignalOnset, // before record
1897
- () => this.numSuccessfulCaptured < this.numCaptures, // loop while true
1898
- this.#awaitDesiredMLSLength, // during record
1899
- this.#afterMLSRecord, // after record
1900
- this.mode,
1901
- checkRec
1902
- );
1903
- this.stopCalibrationAudio();
1905
+ for (var i = 0; i < this.numCaptures; i++) {
1906
+ this.icapture = i;
1907
+ await this.calibrationSteps(
1908
+ stream,
1909
+ this.#playCalibrationAudio, // play audio func (required)
1910
+ this.#createCalibrationNodeFromBuffer(this.#mlsBufferView[this.icapture]), // before play func
1911
+ this.#awaitSignalOnset, // before record
1912
+ () => this.numSuccessfulCaptured < 1, // loop while true
1913
+ this.#awaitDesiredMLSLength, // during record
1914
+ this.#afterMLSRecord, // after record
1915
+ this.mode,
1916
+ checkRec
1917
+ );
1918
+ this.stopCalibrationAudio();
1919
+ }
1904
1920
  checkRec = false;
1905
1921
 
1906
1922
  // at this stage we've captured all the required signals,
@@ -2784,16 +2800,16 @@ class Combination extends AudioCalibrator {
2784
2800
  });
2785
2801
  }
2786
2802
  await this.pyServerAPI.checkMemory();
2787
- let volumeResults = await this.startCalibrationVolume(
2788
- stream,
2789
- gainValues,
2790
- lCalib,
2791
- this.componentGainDBSPL
2792
- );
2793
- if (!volumeResults) return;
2794
-
2795
- this.T = volumeResults["parameters"]["T"];
2796
- this.gainDBSPL = volumeResults["parameters"]["gainDBSPL"];
2803
+ // let volumeResults = await this.startCalibrationVolume(
2804
+ // stream,
2805
+ // gainValues,
2806
+ // lCalib,
2807
+ // this.componentGainDBSPL
2808
+ // );
2809
+ // if (!volumeResults) return;
2810
+
2811
+ // this.T = volumeResults["parameters"]["T"];
2812
+ // this.gainDBSPL = volumeResults["parameters"]["gainDBSPL"];
2797
2813
 
2798
2814
  let impulseResponseResults = await this.startCalibrationImpulseResponse(stream);
2799
2815
  if (!impulseResponseResults) return;