speaker-calibration 2.2.222 → 2.2.224

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.222",
3
+ "version": "2.2.224",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -1,7 +1,5 @@
1
1
  import axios from 'axios';
2
- import {
3
- sleep
4
- } from '../utils';
2
+ import {sleep} from '../utils';
5
3
  /**
6
4
  *
7
5
  */
@@ -28,15 +26,7 @@ class PythonServerAPI {
28
26
  * @returns
29
27
  * @example
30
28
  */
31
- getImpulseResponse = async ({
32
- mls,
33
- sampleRate,
34
- numPeriods,
35
- sig,
36
- fs2,
37
- L_new_n,
38
- dL_n
39
- }) => {
29
+ getImpulseResponse = async ({mls, sampleRate, numPeriods, sig, fs2, L_new_n, dL_n}) => {
40
30
  const task = 'impulse-response';
41
31
  let res = null;
42
32
 
@@ -48,7 +38,7 @@ class PythonServerAPI {
48
38
  sig,
49
39
  fs2,
50
40
  L_new_n,
51
- dL_n
41
+ dL_n,
52
42
  });
53
43
 
54
44
  await axios({
@@ -69,18 +59,13 @@ class PythonServerAPI {
69
59
  return res.data[task];
70
60
  };
71
61
 
72
- getAutocorrelation = async ({
73
- mls,
74
- payload,
75
- sampleRate,
76
- numPeriods
77
- }) => {
62
+ getAutocorrelation = async ({mls, payload, sampleRate, numPeriods}) => {
78
63
  const task = 'autocorrelation';
79
64
  let res = null;
80
65
 
81
66
  const data = JSON.stringify({
82
67
  task,
83
- 'payload': payload,
68
+ payload: payload,
84
69
  'sample-rate': sampleRate,
85
70
  mls,
86
71
  numPeriods,
@@ -105,22 +90,22 @@ class PythonServerAPI {
105
90
  };
106
91
 
107
92
  getConvolution = async ({
108
- mls,
109
- inverse_response,
93
+ mls,
94
+ inverse_response,
110
95
  inverse_response_no_bandpass,
111
96
  attenuatorGain_dB,
112
- mls_amplitude
97
+ mls_amplitude,
113
98
  }) => {
114
99
  const task = 'convolution';
115
100
  let res = null;
116
101
 
117
102
  const data = JSON.stringify({
118
103
  task,
119
- mls,
120
- inverse_response,
104
+ mls,
105
+ inverse_response,
121
106
  inverse_response_no_bandpass,
122
107
  attenuatorGain_dB,
123
- mls_amplitude
108
+ mls_amplitude,
124
109
  });
125
110
 
126
111
  await axios({
@@ -141,7 +126,7 @@ class PythonServerAPI {
141
126
  return res.data[task];
142
127
  };
143
128
 
144
- getMLS = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
129
+ getMLS = async ({length, amplitude, calibrateSoundBurstMLSVersions}) => {
145
130
  const task = 'mls';
146
131
  let res = null;
147
132
 
@@ -171,12 +156,12 @@ class PythonServerAPI {
171
156
  return res.data[task];
172
157
  };
173
158
 
174
- getShortURL = async (originalURL) => {
159
+ getShortURL = async originalURL => {
175
160
  const task = 'url';
176
161
  let res = null;
177
162
  console.log(originalURL);
178
163
  const data = JSON.stringify({
179
- 'URL': originalURL
164
+ URL: originalURL,
180
165
  });
181
166
 
182
167
  console.log(data);
@@ -209,21 +194,20 @@ class PythonServerAPI {
209
194
  url: `/memory`,
210
195
  headers: {
211
196
  'Content-Type': 'application/json',
212
- }
197
+ },
213
198
  })
214
199
  .then(response => {
215
- console.log("memory used:", Math.round(response.data['memory']), "mb");
200
+ console.log('memory used:', Math.round(response.data['memory']), 'mb');
216
201
  res = response.data['memory'];
217
202
  })
218
203
  .catch(error => {
219
204
  throw error;
220
205
  });
221
- return res;
206
+ return res;
222
207
  };
223
208
 
224
-
225
209
  checkMemory = async () => {
226
- console.log("wait for memory under 500 mb to continue calibration");
210
+ console.log('wait for memory under 500 mb to continue calibration');
227
211
  await this.getMemory();
228
212
  // let memory = await this.getMemory();
229
213
  // while (memory >= 500) {
@@ -231,17 +215,15 @@ class PythonServerAPI {
231
215
  // await sleep(30);
232
216
  // memory = await this.getMemory();
233
217
  // }
234
-
235
218
  };
236
219
 
237
-
238
- getMLSWithRetry = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
220
+ getMLSWithRetry = async ({length, amplitude, calibrateSoundBurstMLSVersions}) => {
239
221
  let retryCount = 0;
240
222
  let response = null;
241
223
 
242
224
  while (retryCount < this.MAX_RETRY_COUNT) {
243
225
  try {
244
- response = await this.getMLS({length,amplitude, calibrateSoundBurstMLSVersions});
226
+ response = await this.getMLS({length, amplitude, calibrateSoundBurstMLSVersions});
245
227
  // If the request is successful, break out of the loop
246
228
  break;
247
229
  } catch (error) {
@@ -428,7 +410,7 @@ class PythonServerAPI {
428
410
  calibrateSoundSmoothOctaves,
429
411
  calibrateSoundSmoothMinBandwidthHz,
430
412
  calibrateSoundBurstFilteredExtraDb,
431
- calibrateSoundIIRPhase
413
+ calibrateSoundIIRPhase,
432
414
  }) => {
433
415
  const task = 'component-inverse-impulse-response';
434
416
  let res = null;
@@ -448,7 +430,7 @@ class PythonServerAPI {
448
430
  calibrateSoundSmoothOctaves,
449
431
  calibrateSoundSmoothMinBandwidthHz,
450
432
  calibrateSoundBurstFilteredExtraDb,
451
- calibrateSoundIIRPhase
433
+ calibrateSoundIIRPhase,
452
434
  });
453
435
 
454
436
  await axios({
@@ -478,7 +460,7 @@ class PythonServerAPI {
478
460
  sampleRate,
479
461
  mlsAmplitude,
480
462
  calibrateSoundBurstFilteredExtraDb,
481
- calibrateSoundIIRPhase
463
+ calibrateSoundIIRPhase,
482
464
  }) => {
483
465
  const task = 'system-inverse-impulse-response';
484
466
  let res = null;
@@ -493,7 +475,7 @@ class PythonServerAPI {
493
475
  sampleRate,
494
476
  mlsAmplitude,
495
477
  calibrateSoundBurstFilteredExtraDb,
496
- calibrateSoundIIRPhase
478
+ calibrateSoundIIRPhase,
497
479
  });
498
480
 
499
481
  await axios({
@@ -583,7 +565,7 @@ class PythonServerAPI {
583
565
  calibrateSoundSmoothOctaves,
584
566
  calibrateSoundSmoothMinBandwidthHz,
585
567
  calibrateSoundBurstFilteredExtraDb,
586
- calibrateSoundIIRPhase
568
+ calibrateSoundIIRPhase,
587
569
  }) => {
588
570
  let retryCount = 0;
589
571
  let response = null;
@@ -604,7 +586,7 @@ class PythonServerAPI {
604
586
  calibrateSoundSmoothOctaves,
605
587
  calibrateSoundSmoothMinBandwidthHz,
606
588
  calibrateSoundBurstFilteredExtraDb,
607
- calibrateSoundIIRPhase
589
+ calibrateSoundIIRPhase,
608
590
  });
609
591
  // If the request is successful, break out of the loop
610
592
  break;
@@ -633,7 +615,7 @@ class PythonServerAPI {
633
615
  sampleRate,
634
616
  mlsAmplitude,
635
617
  calibrateSoundBurstFilteredExtraDb,
636
- calibrateSoundIIRPhase
618
+ calibrateSoundIIRPhase,
637
619
  }) => {
638
620
  let retryCount = 0;
639
621
  let response = null;
@@ -649,7 +631,7 @@ class PythonServerAPI {
649
631
  sampleRate,
650
632
  mlsAmplitude,
651
633
  calibrateSoundBurstFilteredExtraDb,
652
- calibrateSoundIIRPhase
634
+ calibrateSoundIIRPhase,
653
635
  });
654
636
  // If the request is successful, break out of the loop
655
637
  break;
@@ -682,7 +664,7 @@ class PythonServerAPI {
682
664
  lCalib,
683
665
  });
684
666
 
685
- await axios({
667
+ const response = await axios({
686
668
  method: 'post',
687
669
  baseURL: PythonServerAPI.PYTHON_SERVER_URL,
688
670
  url: `/task/${task}`,
@@ -692,13 +674,26 @@ class PythonServerAPI {
692
674
  data,
693
675
  })
694
676
  .then(response => {
695
- res = response;
677
+ // if response.data is a string, parse it
678
+ if (typeof response.data === 'string') {
679
+ // response.data = response.data.replaceAll('Infinity', 99999999);
680
+ // response.data = JSON.parse(response.data);
681
+ //if there is Infinity in the string, throw an error
682
+ if (response.data.includes('Infinity')) {
683
+ throw new Error(
684
+ 'Server returned Infinity. Please Make sure the microphone is recording correclty'
685
+ );
686
+ }
687
+ response.data = JSON.parse(response.data);
688
+ }
689
+ return response.data[task];
696
690
  })
697
691
  .catch(error => {
698
692
  throw error;
699
693
  });
700
694
 
701
- return res.data[task];
695
+ console.log(response);
696
+ return response;
702
697
  };
703
698
 
704
699
  getVolumeCalibrationParameters = async ({
@@ -748,31 +743,19 @@ class PythonServerAPI {
748
743
  return res.data[task];
749
744
  };
750
745
 
751
- allHzPowerCheck = async ({
752
- payload,
753
- sampleRate,
754
- binDesiredSec,
755
- burstSec,
756
- repeats,
757
- warmUp
758
- }) => {
746
+ allHzPowerCheck = async ({payload, sampleRate, binDesiredSec, burstSec, repeats, warmUp}) => {
759
747
  const task = 'all-hz-check';
760
748
  let res = null;
761
749
 
762
- console.log({payload,
763
- sampleRate,
764
- binDesiredSec,
765
- burstSec,
766
- repeats,
767
- warmUp});
750
+ console.log({payload, sampleRate, binDesiredSec, burstSec, repeats, warmUp});
768
751
 
769
752
  const data = JSON.stringify({
770
- payload,
771
- sampleRate,
753
+ payload,
754
+ sampleRate,
772
755
  binDesiredSec,
773
756
  burstSec,
774
757
  repeats,
775
- warmUp
758
+ warmUp,
776
759
  });
777
760
 
778
761
  await axios({
@@ -794,22 +777,16 @@ class PythonServerAPI {
794
777
  return res.data[task];
795
778
  };
796
779
 
797
- volumePowerCheck = async ({
798
- payload,
799
- sampleRate,
800
- preSec,
801
- Sec,
802
- binDesiredSec
803
- }) => {
780
+ volumePowerCheck = async ({payload, sampleRate, preSec, Sec, binDesiredSec}) => {
804
781
  const task = 'volume-check';
805
782
  let res = null;
806
783
 
807
784
  const data = JSON.stringify({
808
- payload,
809
- sampleRate,
785
+ payload,
786
+ sampleRate,
810
787
  preSec,
811
788
  Sec,
812
- binDesiredSec
789
+ binDesiredSec,
813
790
  });
814
791
 
815
792
  await axios({
@@ -831,24 +808,19 @@ class PythonServerAPI {
831
808
  return res.data[task];
832
809
  };
833
810
 
834
- volumePowerCheckWithRetry = async ({
835
- payload,
836
- sampleRate,
837
- preSec,
838
- Sec,
839
- binDesiredSec
840
- }) => {
811
+ volumePowerCheckWithRetry = async ({payload, sampleRate, preSec, Sec, binDesiredSec}) => {
841
812
  let retryCount = 0;
842
813
  let response = null;
843
814
 
844
815
  while (retryCount < this.MAX_RETRY_COUNT) {
845
816
  try {
846
817
  response = await this.volumePowerCheck({
847
- payload,
848
- sampleRate,
818
+ payload,
819
+ sampleRate,
849
820
  preSec,
850
821
  Sec,
851
- binDesiredSec});
822
+ binDesiredSec,
823
+ });
852
824
  // If the request is successful, break out of the loop
853
825
  break;
854
826
  } catch (error) {
@@ -1958,7 +1958,6 @@ class Combination extends AudioCalibrator {
1958
1958
  * @example
1959
1959
  */
1960
1960
  startCalibrationImpulseResponse = async stream => {
1961
- console.log('JS used memory:', performance.memory.usedJSHeapSize / 1024 / 1024, 'mb');
1962
1961
  let desired_time = this.desired_time_per_mls;
1963
1962
  let checkRec = 'allhz';
1964
1963
 
@@ -2365,6 +2364,12 @@ class Combination extends AudioCalibrator {
2365
2364
  lCalib: lCalib,
2366
2365
  })
2367
2366
  .then(res => {
2367
+ //if res is undefined, throw an error
2368
+ if (res === undefined) {
2369
+ throw new Error(
2370
+ 'No response from server in getVolumeCalibration function. Please try again.'
2371
+ );
2372
+ }
2368
2373
  if (this.outDBSPL === null) {
2369
2374
  this.incrementStatusBar();
2370
2375
  this.outDBSPL = res['outDbSPL'];
@@ -2540,6 +2545,9 @@ class Combination extends AudioCalibrator {
2540
2545
  .then(res => {
2541
2546
  this.incrementStatusBar();
2542
2547
  return res;
2548
+ })
2549
+ .catch(err => {
2550
+ throw err;
2543
2551
  });
2544
2552
  if (this.isCalibrating) return null;
2545
2553
  const result = {