speaker-calibration 2.2.182 → 2.2.183

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.
Files changed (122) hide show
  1. package/.eslintignore +71 -71
  2. package/.eslintrc.json +40 -40
  3. package/.github/workflows/update-phrases.yml +37 -0
  4. package/.prettierignore +69 -69
  5. package/.prettierrc +14 -14
  6. package/LICENSE +20 -20
  7. package/README.md +133 -133
  8. package/__mocks__/fileMock.js +1 -1
  9. package/__mocks__/styleMock.js +1 -1
  10. package/babel.config.js +3 -3
  11. package/coverage/clover.xml +71 -71
  12. package/coverage/coverage-final.json +224 -224
  13. package/coverage/lcov-report/PythonServerInterface.js.html +265 -265
  14. package/coverage/lcov-report/base.css +354 -354
  15. package/coverage/lcov-report/block-navigation.js +82 -82
  16. package/coverage/lcov-report/index.html +123 -123
  17. package/coverage/lcov-report/prettify.css +101 -101
  18. package/coverage/lcov-report/prettify.js +937 -937
  19. package/coverage/lcov-report/sorter.js +189 -189
  20. package/coverage/lcov-report/src/index.html +121 -121
  21. package/coverage/lcov-report/src/server/PythonServerInterface.js.html +268 -268
  22. package/coverage/lcov-report/src/server/index.html +123 -123
  23. package/coverage/lcov-report/src/tasks/audioCalibrator.js.html +499 -499
  24. package/coverage/lcov-report/src/tasks/audioRecorder.js.html +412 -412
  25. package/coverage/lcov-report/src/tasks/index.html +143 -143
  26. package/coverage/lcov-report/src/tasks/volume/index.html +123 -123
  27. package/coverage/lcov-report/src/tasks/volume/volume.js.html +409 -409
  28. package/coverage/lcov-report/src/utils.js.html +172 -172
  29. package/coverage/lcov.info +91 -91
  30. package/dist/example/NoSleep.min.js +1 -1
  31. package/dist/example/fetch-languages-sheets.js +77 -77
  32. package/dist/example/i18n.js +25828 -25820
  33. package/dist/example/index.html +47 -47
  34. package/dist/example/listener.html +79 -79
  35. package/dist/example/listener.js +149 -149
  36. package/dist/example/server.js +51 -51
  37. package/dist/example/speaker.html +145 -145
  38. package/dist/example/speakerUI.js +273 -273
  39. package/dist/example/styles.css +99 -99
  40. package/dist/main.js +2 -1224
  41. package/dist/main.js.LICENSE.txt +118 -0
  42. package/dist/mlsGen.js +6814 -6814
  43. package/dist/mlsGen.wasm +0 -0
  44. package/dist/package-lock.json +1018 -1018
  45. package/dist/package.json +18 -18
  46. package/doc/AudioCalibrator.html +417 -417
  47. package/doc/AudioPeer.html +251 -251
  48. package/doc/AudioRecorder.html +195 -195
  49. package/doc/ImpulseResponse.html +215 -215
  50. package/doc/Listener.html +308 -308
  51. package/doc/MlsGenInterface.html +226 -226
  52. package/doc/MyEventEmitter.html +274 -274
  53. package/doc/PythonServerAPI.html +109 -109
  54. package/doc/Speaker.html +276 -276
  55. package/doc/Takes%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +128 -128
  56. package/doc/Takes%20the%20url%20of%20the%20current%20site%0Aand%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +138 -138
  57. package/doc/Takes%20the%20url%20of%20the%20current%20site%20and%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +137 -137
  58. package/doc/Volume.html +88 -88
  59. package/doc/audioCalibrator.js.html +179 -179
  60. package/doc/audioPeer.js.html +175 -175
  61. package/doc/audioRecorder.js.html +163 -163
  62. package/doc/creates%20a%20new%20AudioRecorder%20instance.%20%0ASets%20up%20the%20audio%20context%20and%20file%20reader..html +114 -114
  63. package/doc/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  64. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  65. package/doc/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  66. package/doc/fonts/OpenSans-Light-webfont.svg +1830 -1830
  67. package/doc/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  68. package/doc/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  69. package/doc/global.html +308 -308
  70. package/doc/index.html +58 -58
  71. package/doc/listener.js.html +170 -170
  72. package/doc/mlsGen_mlsGenInterface.js.html +117 -117
  73. package/doc/myEventEmitter.js.html +124 -124
  74. package/doc/peer-connection_audioPeer.js.html +188 -188
  75. package/doc/peer-connection_listener.js.html +311 -311
  76. package/doc/peer-connection_speaker.js.html +381 -381
  77. package/doc/scripts/linenumber.js +25 -25
  78. package/doc/scripts/prettify/Apache-License-2.0.txt +202 -202
  79. package/doc/scripts/prettify/lang-css.js +24 -24
  80. package/doc/scripts/prettify/prettify.js +640 -640
  81. package/doc/server_PythonServerAPI.js.html +160 -160
  82. package/doc/speaker.js.html +248 -248
  83. package/doc/styles/jsdoc-default.css +371 -371
  84. package/doc/styles/prettify-jsdoc.css +111 -111
  85. package/doc/styles/prettify-tomorrow.css +163 -163
  86. package/doc/tasks_audioCalibrator.js.html +207 -207
  87. package/doc/tasks_audioRecorder.js.html +190 -190
  88. package/doc/tasks_impulse-response_impulseResponse.js.html +442 -442
  89. package/doc/tasks_impulse-response_mlsGen_mlsGenInterface.js.html +175 -175
  90. package/doc/tasks_volume_volume.js.html +185 -185
  91. package/doc/utils.js.html +105 -105
  92. package/jest.config.js +173 -173
  93. package/makefile +74 -0
  94. package/netlify.toml +26 -26
  95. package/package.json +72 -72
  96. package/src/config/firebase.js +26 -26
  97. package/src/index.html +21 -21
  98. package/src/main.js +23 -23
  99. package/src/myEventEmitter.js +83 -83
  100. package/src/peer-connection/audioPeer.js +178 -178
  101. package/src/peer-connection/listener.js +340 -340
  102. package/src/peer-connection/peerErrors.js +25 -25
  103. package/src/peer-connection/speaker.js +725 -725
  104. package/src/server/PythonServerAPI.js +830 -830
  105. package/src/tasks/audioCalibrator.js +323 -323
  106. package/src/tasks/audioRecorder.js +315 -315
  107. package/src/tasks/combination/combination.js +2955 -2937
  108. package/src/tasks/combination/mlsGen/mlsGen.cpp +98 -98
  109. package/src/tasks/combination/mlsGen/mlsGen.hpp +303 -303
  110. package/src/tasks/combination/mlsGen/mlsGenInterface.js +131 -131
  111. package/src/tasks/combination/mlsGen/mlsGenTest.cpp +180 -180
  112. package/src/tasks/impulse-response/impulseResponse.js +610 -610
  113. package/src/tasks/impulse-response/mlsGen/mlsGen.cpp +98 -98
  114. package/src/tasks/impulse-response/mlsGen/mlsGen.hpp +303 -303
  115. package/src/tasks/impulse-response/mlsGen/mlsGenInterface.js +131 -131
  116. package/src/tasks/impulse-response/mlsGen/mlsGenTest.cpp +180 -180
  117. package/src/tasks/volume/volume.cpp +2 -2
  118. package/src/tasks/volume/volume.hpp +22 -22
  119. package/src/tasks/volume/volume.js +279 -279
  120. package/src/utils.js +205 -205
  121. package/webpack.config.js +37 -37
  122. package/.gitignore +0 -81
@@ -1,830 +1,830 @@
1
- import axios from 'axios';
2
- import {
3
- sleep
4
- } from '../utils';
5
- /**
6
- *
7
- */
8
- class PythonServerAPI {
9
- static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
10
-
11
- static TEST_SERVER_URL = 'http://127.0.0.1:5000';
12
- // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
13
-
14
- /** @private */
15
- MAX_RETRY_COUNT = 3;
16
- /** @private */
17
- RETRY_DELAY_MS = 1000;
18
- /**
19
- * @param data- -
20
- * g = inverted impulse response, when convolved with the impulse
21
- * reponse, they cancel out.
22
- * @param data.payload
23
- * @param data.sampleRate
24
- * @param data.P
25
- * @param data-.payload
26
- * @param data-.sampleRate
27
- * @param data-.P
28
- * @returns
29
- * @example
30
- */
31
- getImpulseResponse = async ({
32
- mls,
33
- sampleRate,
34
- numPeriods,
35
- sig,
36
- fs2,
37
- L_new_n,
38
- dL_n
39
- }) => {
40
- const task = 'impulse-response';
41
- let res = null;
42
-
43
- const data = JSON.stringify({
44
- task,
45
- 'sample-rate': sampleRate,
46
- mls,
47
- numPeriods,
48
- sig,
49
- fs2,
50
- L_new_n,
51
- dL_n
52
- });
53
-
54
- await axios({
55
- method: 'post',
56
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
57
- url: `/task/${task}`,
58
- headers: {
59
- 'Content-Type': 'application/json',
60
- },
61
- data,
62
- })
63
- .then(response => {
64
- res = response;
65
- })
66
- .catch(error => {
67
- throw error;
68
- });
69
- return res.data[task];
70
- };
71
-
72
- getAutocorrelation = async ({
73
- mls,
74
- payload,
75
- sampleRate,
76
- numPeriods
77
- }) => {
78
- const task = 'autocorrelation';
79
- let res = null;
80
-
81
- const data = JSON.stringify({
82
- task,
83
- payload,
84
- 'sample-rate': sampleRate,
85
- mls,
86
- numPeriods,
87
- });
88
-
89
- await axios({
90
- method: 'post',
91
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
92
- url: `/task/${task}`,
93
- headers: {
94
- 'Content-Type': 'application/json',
95
- },
96
- data,
97
- })
98
- .then(response => {
99
- res = response;
100
- })
101
- .catch(error => {
102
- throw error;
103
- });
104
- return res.data[task];
105
- };
106
-
107
- getConvolution = async ({
108
- mls,
109
- inverse_response,
110
- inverse_response_no_bandpass,
111
- attenuatorGain_dB,
112
- mls_amplitude
113
- }) => {
114
- const task = 'convolution';
115
- let res = null;
116
-
117
- const data = JSON.stringify({
118
- task,
119
- mls,
120
- inverse_response,
121
- inverse_response_no_bandpass,
122
- attenuatorGain_dB,
123
- mls_amplitude
124
- });
125
-
126
- await axios({
127
- method: 'post',
128
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
129
- url: `/task/${task}`,
130
- headers: {
131
- 'Content-Type': 'application/json',
132
- },
133
- data,
134
- })
135
- .then(response => {
136
- res = response;
137
- })
138
- .catch(error => {
139
- throw error;
140
- });
141
- return res.data[task];
142
- };
143
-
144
- getMLS = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
145
- const task = 'mls';
146
- let res = null;
147
-
148
- const data = JSON.stringify({
149
- task,
150
- length: length,
151
- amplitude: amplitude,
152
- calibrateSoundBurstMLSVersions: calibrateSoundBurstMLSVersions,
153
- });
154
-
155
- await axios({
156
- method: 'post',
157
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
158
- url: `/task/${task}`,
159
- headers: {
160
- 'Content-Type': 'application/json',
161
- },
162
- data,
163
- })
164
- .then(response => {
165
- res = response;
166
- })
167
- .catch(error => {
168
- throw error;
169
- });
170
-
171
- return res.data[task];
172
- };
173
-
174
- getShortURL = async (originalURL) => {
175
- const task = 'url';
176
- let res = null;
177
- console.log(originalURL);
178
- const data = JSON.stringify({
179
- 'URL': originalURL
180
- });
181
-
182
- console.log(data);
183
-
184
- await axios({
185
- method: 'post',
186
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
187
- url: `/task/${task}`,
188
- headers: {
189
- 'Content-Type': 'application/json',
190
- },
191
- data,
192
- })
193
- .then(response => {
194
- res = response;
195
- console.log(res.data[task]);
196
- })
197
- .catch(error => {
198
- throw error;
199
- });
200
-
201
- return res.data[task];
202
- };
203
-
204
- getMemory = async () => {
205
- let res;
206
- await axios({
207
- method: 'post',
208
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
209
- url: `/memory`,
210
- headers: {
211
- 'Content-Type': 'application/json',
212
- }
213
- })
214
- .then(response => {
215
- console.log("memory used:", Math.round(response.data['memory']), "mb");
216
- res = response.data['memory'];
217
- })
218
- .catch(error => {
219
- throw error;
220
- });
221
- return res;
222
- };
223
-
224
-
225
- checkMemory = async () => {
226
- console.log("wait for memory under 500 mb to continue calibration");
227
- await this.getMemory();
228
- // let memory = await this.getMemory();
229
- // while (memory >= 500) {
230
- // console.log("sleep 30s");
231
- // await sleep(30);
232
- // memory = await this.getMemory();
233
- // }
234
-
235
- };
236
-
237
-
238
- getMLSWithRetry = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
239
- let retryCount = 0;
240
- let response = null;
241
-
242
- while (retryCount < this.MAX_RETRY_COUNT) {
243
- try {
244
- response = await this.getMLS({length,amplitude, calibrateSoundBurstMLSVersions});
245
- // If the request is successful, break out of the loop
246
- break;
247
- } catch (error) {
248
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
249
- retryCount++;
250
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
251
- }
252
- }
253
-
254
- if (response) {
255
- return response;
256
- } else {
257
- throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
258
- }
259
- };
260
-
261
- getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
262
- const task = 'psd';
263
- let res = null;
264
-
265
- const data = JSON.stringify({
266
- task,
267
- unconv_rec,
268
- conv_rec,
269
- sampleRate,
270
- });
271
-
272
- await axios({
273
- method: 'post',
274
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
275
- url: `/task/${task}`,
276
- headers: {
277
- 'Content-Type': 'application/json',
278
- },
279
- data,
280
- })
281
- .then(response => {
282
- res = response;
283
- })
284
- .catch(error => {
285
- throw error;
286
- });
287
- return res.data[task];
288
- };
289
-
290
- getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
291
- const task = 'background-psd';
292
- let res = null;
293
-
294
- const data = JSON.stringify({
295
- task,
296
- background_rec,
297
- sampleRate,
298
- });
299
-
300
- await axios({
301
- method: 'post',
302
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
303
- url: `/task/${task}`,
304
- headers: {
305
- 'Content-Type': 'application/json',
306
- },
307
- data,
308
- })
309
- .then(response => {
310
- res = response;
311
- })
312
- .catch(error => {
313
- throw error;
314
- });
315
- return res.data[task];
316
- };
317
-
318
- getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
319
- let retryCount = 0;
320
- let response = null;
321
-
322
- while (retryCount < this.MAX_RETRY_COUNT) {
323
- try {
324
- response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
325
- // If the request is successful, break out of the loop
326
- break;
327
- } catch (error) {
328
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
329
- retryCount++;
330
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
331
- }
332
- }
333
-
334
- if (response) {
335
- return response;
336
- } else {
337
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
338
- }
339
- };
340
-
341
- getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
342
- const task = 'subtracted-psd';
343
- let res = null;
344
-
345
- const data = JSON.stringify({
346
- task,
347
- rec,
348
- knownGains,
349
- knownFrequencies,
350
- sampleRate,
351
- });
352
-
353
- await axios({
354
- method: 'post',
355
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
356
- url: `/task/${task}`,
357
- headers: {
358
- 'Content-Type': 'application/json',
359
- },
360
- data,
361
- })
362
- .then(response => {
363
- res = response;
364
- })
365
- .catch(error => {
366
- throw error;
367
- });
368
- return res.data[task];
369
- };
370
-
371
- getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
372
- let retryCount = 0;
373
- let response = null;
374
-
375
- while (retryCount < this.MAX_RETRY_COUNT) {
376
- try {
377
- response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
378
- // If the request is successful, break out of the loop
379
- break;
380
- } catch (error) {
381
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
382
- retryCount++;
383
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
384
- }
385
- }
386
-
387
- if (response) {
388
- return response;
389
- } else {
390
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
391
- }
392
- };
393
-
394
- getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
395
- let retryCount = 0;
396
- let response = null;
397
-
398
- while (retryCount < this.MAX_RETRY_COUNT) {
399
- try {
400
- response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
401
- // If the request is successful, break out of the loop
402
- break;
403
- } catch (error) {
404
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
405
- retryCount++;
406
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
407
- }
408
- }
409
-
410
- if (response) {
411
- return response;
412
- } else {
413
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
414
- }
415
- };
416
-
417
- getComponentInverseImpulseResponse = async ({
418
- payload,
419
- mls,
420
- lowHz,
421
- highHz,
422
- componentIRGains,
423
- iirLength,
424
- componentIRFreqs,
425
- sampleRate,
426
- mlsAmplitude,
427
- irLength,
428
- calibrateSoundSmoothOctaves,
429
- calibrateSoundSmoothMinBandwidthHz,
430
- calibrateSoundBurstFilteredExtraDb,
431
- calibrateSoundIIRPhase
432
- }) => {
433
- const task = 'component-inverse-impulse-response';
434
- let res = null;
435
-
436
- console.log({payload});
437
-
438
- const data = JSON.stringify({
439
- task,
440
- payload,
441
- mls,
442
- lowHz,
443
- highHz,
444
- iirLength,
445
- componentIRGains,
446
- componentIRFreqs,
447
- sampleRate,
448
- mlsAmplitude,
449
- irLength,
450
- calibrateSoundSmoothOctaves,
451
- calibrateSoundSmoothMinBandwidthHz,
452
- calibrateSoundBurstFilteredExtraDb,
453
- calibrateSoundIIRPhase
454
- });
455
-
456
- await axios({
457
- method: 'post',
458
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
459
- url: `/task/${task}`,
460
- headers: {
461
- 'Content-Type': 'application/json',
462
- },
463
- data,
464
- })
465
- .then(response => {
466
- res = response;
467
- })
468
- .catch(error => {
469
- throw error;
470
- });
471
-
472
- return res.data[task];
473
- };
474
- getSystemInverseImpulseResponse = async ({
475
- payload,
476
- mls,
477
- lowHz,
478
- highHz,
479
- iirLength,
480
- sampleRate,
481
- mlsAmplitude,
482
- calibrateSoundBurstFilteredExtraDb,
483
- calibrateSoundIIRPhase
484
- }) => {
485
- const task = 'system-inverse-impulse-response';
486
- let res = null;
487
-
488
- console.log({payload});
489
-
490
- const data = JSON.stringify({
491
- task,
492
- payload,
493
- mls,
494
- lowHz,
495
- iirLength,
496
- highHz,
497
- sampleRate,
498
- mlsAmplitude,
499
- calibrateSoundBurstFilteredExtraDb,
500
- calibrateSoundIIRPhase
501
- });
502
-
503
- await axios({
504
- method: 'post',
505
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
506
- url: `/task/${task}`,
507
- headers: {
508
- 'Content-Type': 'application/json',
509
- },
510
- data,
511
- })
512
- .then(response => {
513
- res = response;
514
- })
515
- .catch(error => {
516
- throw error;
517
- });
518
-
519
- return res.data[task];
520
- };
521
-
522
- getMLSPSD = async ({mls, sampleRate}) => {
523
- const task = 'mls-psd';
524
- let res = null;
525
-
526
- const data = JSON.stringify({
527
- task,
528
- mls,
529
- sampleRate,
530
- });
531
-
532
- await axios({
533
- method: 'post',
534
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
535
- url: `/task/${task}`,
536
- headers: {
537
- 'Content-Type': 'application/json',
538
- },
539
- data,
540
- })
541
- .then(response => {
542
- res = response;
543
- })
544
- .catch(error => {
545
- throw error;
546
- });
547
-
548
- return res.data[task];
549
- };
550
-
551
- getMLSPSDWithRetry = async ({mls, sampleRate}) => {
552
- let retryCount = 0;
553
- let response = null;
554
-
555
- while (retryCount < this.MAX_RETRY_COUNT) {
556
- try {
557
- response = await this.getMLSPSD({mls, sampleRate});
558
- // If the request is successful, break out of the loop
559
- break;
560
- } catch (error) {
561
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
562
- retryCount++;
563
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
564
- }
565
- }
566
-
567
- if (response) {
568
- return response;
569
- } else {
570
- throw new Error(
571
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
572
- );
573
- }
574
- };
575
-
576
- getComponentInverseImpulseResponseWithRetry = async ({
577
- payload,
578
- mls,
579
- lowHz,
580
- highHz,
581
- componentIRGains,
582
- iirLength,
583
- componentIRFreqs,
584
- sampleRate,
585
- mlsAmplitude,
586
- irLength,
587
- calibrateSoundSmoothOctaves,
588
- calibrateSoundSmoothMinBandwidthHz,
589
- calibrateSoundBurstFilteredExtraDb,
590
- calibrateSoundIIRPhase
591
- }) => {
592
- let retryCount = 0;
593
- let response = null;
594
-
595
- while (retryCount < this.MAX_RETRY_COUNT) {
596
- try {
597
- response = await this.getComponentInverseImpulseResponse({
598
- payload,
599
- mls,
600
- lowHz,
601
- highHz,
602
- componentIRGains,
603
- iirLength,
604
- componentIRFreqs,
605
- sampleRate,
606
- mlsAmplitude,
607
- irLength,
608
- calibrateSoundSmoothOctaves,
609
- calibrateSoundSmoothMinBandwidthHz,
610
- calibrateSoundBurstFilteredExtraDb,
611
- calibrateSoundIIRPhase
612
- });
613
- // If the request is successful, break out of the loop
614
- break;
615
- } catch (error) {
616
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
617
- retryCount++;
618
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
619
- }
620
- }
621
-
622
- if (response) {
623
- return response;
624
- } else {
625
- throw new Error(
626
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
627
- );
628
- }
629
- };
630
-
631
- getSystemInverseImpulseResponseWithRetry = async ({
632
- payload,
633
- mls,
634
- lowHz,
635
- highHz,
636
- iirLength,
637
- sampleRate,
638
- mlsAmplitude,
639
- calibrateSoundBurstFilteredExtraDb,
640
- calibrateSoundIIRPhase
641
- }) => {
642
- let retryCount = 0;
643
- let response = null;
644
-
645
- while (retryCount < this.MAX_RETRY_COUNT) {
646
- try {
647
- response = await this.getSystemInverseImpulseResponse({
648
- payload,
649
- mls,
650
- lowHz,
651
- highHz,
652
- iirLength,
653
- sampleRate,
654
- mlsAmplitude,
655
- calibrateSoundBurstFilteredExtraDb,
656
- calibrateSoundIIRPhase
657
- });
658
- // If the request is successful, break out of the loop
659
- break;
660
- } catch (error) {
661
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
662
- retryCount++;
663
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
664
- }
665
- }
666
-
667
- if (response) {
668
- return response;
669
- } else {
670
- throw new Error(
671
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
672
- );
673
- }
674
- };
675
-
676
- getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
677
- const task = 'volume';
678
- let res = null;
679
-
680
- console.log({payload});
681
-
682
- const data = JSON.stringify({
683
- task,
684
- payload,
685
- 'sample-rate': sampleRate,
686
- lCalib,
687
- });
688
-
689
- await axios({
690
- method: 'post',
691
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
692
- url: `/task/${task}`,
693
- headers: {
694
- 'Content-Type': 'application/json',
695
- },
696
- data,
697
- })
698
- .then(response => {
699
- res = response;
700
- })
701
- .catch(error => {
702
- throw error;
703
- });
704
-
705
- return res.data[task];
706
- };
707
-
708
- getVolumeCalibrationParameters = async ({
709
- inDBValues,
710
- outDBSPLValues,
711
- lCalib,
712
- componentGainDBSPL,
713
- }) => {
714
- const task = 'volume-parameters';
715
- let res = null;
716
-
717
- const data = JSON.stringify({
718
- task,
719
- inDBValues,
720
- outDBSPLValues,
721
- lCalib,
722
- componentGainDBSPL,
723
- });
724
-
725
- await axios({
726
- method: 'post',
727
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
728
- url: `/task/${task}`,
729
- headers: {
730
- 'Content-Type': 'application/json',
731
- },
732
- data,
733
- })
734
- .then(response => {
735
- res = response;
736
- console.log(res.data[task]);
737
- })
738
- .catch(error => {
739
- throw error;
740
- });
741
-
742
- // console.log(res.data[task]);
743
- //below is an example of res.data[task]
744
- //{
745
- // R: 16.56981076554259,
746
- // RMSError: 1.9289162528535229
747
- // T: -47.79799120884434,
748
- // W: 61.0485247483732,
749
- // backgroundDBSPL: 43.88233142069752,
750
- // gainDBSPL: -128.24742161208985
751
- //}
752
- return res.data[task];
753
- };
754
-
755
- allHzPowerCheck = async ({
756
- payload,
757
- sampleRate,
758
- binDesiredSec,
759
- burstSec,
760
- repeats
761
- }) => {
762
- const task = 'all-hz-check';
763
- let res = null;
764
-
765
- const data = JSON.stringify({
766
- payload,
767
- sampleRate,
768
- binDesiredSec,
769
- burstSec,
770
- repeats
771
- });
772
-
773
- await axios({
774
- method: 'post',
775
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
776
- url: `/task/${task}`,
777
- headers: {
778
- 'Content-Type': 'application/json',
779
- },
780
- data,
781
- })
782
- .then(response => {
783
- res = response;
784
- console.log(res.data[task]);
785
- })
786
- .catch(error => {
787
- throw error;
788
- });
789
- return res.data[task];
790
- };
791
-
792
- volumePowerCheck = async ({
793
- payload,
794
- sampleRate,
795
- preSec,
796
- Sec,
797
- binDesiredSec
798
- }) => {
799
- const task = 'volume-check';
800
- let res = null;
801
-
802
- const data = JSON.stringify({
803
- payload,
804
- sampleRate,
805
- preSec,
806
- Sec,
807
- binDesiredSec
808
- });
809
-
810
- await axios({
811
- method: 'post',
812
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
813
- url: `/task/${task}`,
814
- headers: {
815
- 'Content-Type': 'application/json',
816
- },
817
- data,
818
- })
819
- .then(response => {
820
- res = response;
821
- console.log(res.data[task]);
822
- })
823
- .catch(error => {
824
- throw error;
825
- });
826
- return res.data[task];
827
- };
828
- }
829
-
830
- export default PythonServerAPI;
1
+ import axios from 'axios';
2
+ import {
3
+ sleep
4
+ } from '../utils';
5
+ /**
6
+ *
7
+ */
8
+ class PythonServerAPI {
9
+ static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
10
+
11
+ static TEST_SERVER_URL = 'http://127.0.0.1:5000';
12
+ // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
13
+
14
+ /** @private */
15
+ MAX_RETRY_COUNT = 3;
16
+ /** @private */
17
+ RETRY_DELAY_MS = 1000;
18
+ /**
19
+ * @param data- -
20
+ * g = inverted impulse response, when convolved with the impulse
21
+ * reponse, they cancel out.
22
+ * @param data.payload
23
+ * @param data.sampleRate
24
+ * @param data.P
25
+ * @param data-.payload
26
+ * @param data-.sampleRate
27
+ * @param data-.P
28
+ * @returns
29
+ * @example
30
+ */
31
+ getImpulseResponse = async ({
32
+ mls,
33
+ sampleRate,
34
+ numPeriods,
35
+ sig,
36
+ fs2,
37
+ L_new_n,
38
+ dL_n
39
+ }) => {
40
+ const task = 'impulse-response';
41
+ let res = null;
42
+
43
+ const data = JSON.stringify({
44
+ task,
45
+ 'sample-rate': sampleRate,
46
+ mls,
47
+ numPeriods,
48
+ sig,
49
+ fs2,
50
+ L_new_n,
51
+ dL_n
52
+ });
53
+
54
+ await axios({
55
+ method: 'post',
56
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
57
+ url: `/task/${task}`,
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ data,
62
+ })
63
+ .then(response => {
64
+ res = response;
65
+ })
66
+ .catch(error => {
67
+ throw error;
68
+ });
69
+ return res.data[task];
70
+ };
71
+
72
+ getAutocorrelation = async ({
73
+ mls,
74
+ payload,
75
+ sampleRate,
76
+ numPeriods
77
+ }) => {
78
+ const task = 'autocorrelation';
79
+ let res = null;
80
+
81
+ const data = JSON.stringify({
82
+ task,
83
+ payload,
84
+ 'sample-rate': sampleRate,
85
+ mls,
86
+ numPeriods,
87
+ });
88
+
89
+ await axios({
90
+ method: 'post',
91
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
92
+ url: `/task/${task}`,
93
+ headers: {
94
+ 'Content-Type': 'application/json',
95
+ },
96
+ data,
97
+ })
98
+ .then(response => {
99
+ res = response;
100
+ })
101
+ .catch(error => {
102
+ throw error;
103
+ });
104
+ return res.data[task];
105
+ };
106
+
107
+ getConvolution = async ({
108
+ mls,
109
+ inverse_response,
110
+ inverse_response_no_bandpass,
111
+ attenuatorGain_dB,
112
+ mls_amplitude
113
+ }) => {
114
+ const task = 'convolution';
115
+ let res = null;
116
+
117
+ const data = JSON.stringify({
118
+ task,
119
+ mls,
120
+ inverse_response,
121
+ inverse_response_no_bandpass,
122
+ attenuatorGain_dB,
123
+ mls_amplitude
124
+ });
125
+
126
+ await axios({
127
+ method: 'post',
128
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
129
+ url: `/task/${task}`,
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ },
133
+ data,
134
+ })
135
+ .then(response => {
136
+ res = response;
137
+ })
138
+ .catch(error => {
139
+ throw error;
140
+ });
141
+ return res.data[task];
142
+ };
143
+
144
+ getMLS = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
145
+ const task = 'mls';
146
+ let res = null;
147
+
148
+ const data = JSON.stringify({
149
+ task,
150
+ length: length,
151
+ amplitude: amplitude,
152
+ calibrateSoundBurstMLSVersions: calibrateSoundBurstMLSVersions,
153
+ });
154
+
155
+ await axios({
156
+ method: 'post',
157
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
158
+ url: `/task/${task}`,
159
+ headers: {
160
+ 'Content-Type': 'application/json',
161
+ },
162
+ data,
163
+ })
164
+ .then(response => {
165
+ res = response;
166
+ })
167
+ .catch(error => {
168
+ throw error;
169
+ });
170
+
171
+ return res.data[task];
172
+ };
173
+
174
+ getShortURL = async (originalURL) => {
175
+ const task = 'url';
176
+ let res = null;
177
+ console.log(originalURL);
178
+ const data = JSON.stringify({
179
+ 'URL': originalURL
180
+ });
181
+
182
+ console.log(data);
183
+
184
+ await axios({
185
+ method: 'post',
186
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
187
+ url: `/task/${task}`,
188
+ headers: {
189
+ 'Content-Type': 'application/json',
190
+ },
191
+ data,
192
+ })
193
+ .then(response => {
194
+ res = response;
195
+ console.log(res.data[task]);
196
+ })
197
+ .catch(error => {
198
+ throw error;
199
+ });
200
+
201
+ return res.data[task];
202
+ };
203
+
204
+ getMemory = async () => {
205
+ let res;
206
+ await axios({
207
+ method: 'post',
208
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
209
+ url: `/memory`,
210
+ headers: {
211
+ 'Content-Type': 'application/json',
212
+ }
213
+ })
214
+ .then(response => {
215
+ console.log("memory used:", Math.round(response.data['memory']), "mb");
216
+ res = response.data['memory'];
217
+ })
218
+ .catch(error => {
219
+ throw error;
220
+ });
221
+ return res;
222
+ };
223
+
224
+
225
+ checkMemory = async () => {
226
+ console.log("wait for memory under 500 mb to continue calibration");
227
+ await this.getMemory();
228
+ // let memory = await this.getMemory();
229
+ // while (memory >= 500) {
230
+ // console.log("sleep 30s");
231
+ // await sleep(30);
232
+ // memory = await this.getMemory();
233
+ // }
234
+
235
+ };
236
+
237
+
238
+ getMLSWithRetry = async ({length,amplitude,calibrateSoundBurstMLSVersions}) => {
239
+ let retryCount = 0;
240
+ let response = null;
241
+
242
+ while (retryCount < this.MAX_RETRY_COUNT) {
243
+ try {
244
+ response = await this.getMLS({length,amplitude, calibrateSoundBurstMLSVersions});
245
+ // If the request is successful, break out of the loop
246
+ break;
247
+ } catch (error) {
248
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
249
+ retryCount++;
250
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
251
+ }
252
+ }
253
+
254
+ if (response) {
255
+ return response;
256
+ } else {
257
+ throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
258
+ }
259
+ };
260
+
261
+ getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
262
+ const task = 'psd';
263
+ let res = null;
264
+
265
+ const data = JSON.stringify({
266
+ task,
267
+ unconv_rec,
268
+ conv_rec,
269
+ sampleRate,
270
+ });
271
+
272
+ await axios({
273
+ method: 'post',
274
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
275
+ url: `/task/${task}`,
276
+ headers: {
277
+ 'Content-Type': 'application/json',
278
+ },
279
+ data,
280
+ })
281
+ .then(response => {
282
+ res = response;
283
+ })
284
+ .catch(error => {
285
+ throw error;
286
+ });
287
+ return res.data[task];
288
+ };
289
+
290
+ getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
291
+ const task = 'background-psd';
292
+ let res = null;
293
+
294
+ const data = JSON.stringify({
295
+ task,
296
+ background_rec,
297
+ sampleRate,
298
+ });
299
+
300
+ await axios({
301
+ method: 'post',
302
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
303
+ url: `/task/${task}`,
304
+ headers: {
305
+ 'Content-Type': 'application/json',
306
+ },
307
+ data,
308
+ })
309
+ .then(response => {
310
+ res = response;
311
+ })
312
+ .catch(error => {
313
+ throw error;
314
+ });
315
+ return res.data[task];
316
+ };
317
+
318
+ getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
319
+ let retryCount = 0;
320
+ let response = null;
321
+
322
+ while (retryCount < this.MAX_RETRY_COUNT) {
323
+ try {
324
+ response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
325
+ // If the request is successful, break out of the loop
326
+ break;
327
+ } catch (error) {
328
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
329
+ retryCount++;
330
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
331
+ }
332
+ }
333
+
334
+ if (response) {
335
+ return response;
336
+ } else {
337
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
338
+ }
339
+ };
340
+
341
+ getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
342
+ const task = 'subtracted-psd';
343
+ let res = null;
344
+
345
+ const data = JSON.stringify({
346
+ task,
347
+ rec,
348
+ knownGains,
349
+ knownFrequencies,
350
+ sampleRate,
351
+ });
352
+
353
+ await axios({
354
+ method: 'post',
355
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
356
+ url: `/task/${task}`,
357
+ headers: {
358
+ 'Content-Type': 'application/json',
359
+ },
360
+ data,
361
+ })
362
+ .then(response => {
363
+ res = response;
364
+ })
365
+ .catch(error => {
366
+ throw error;
367
+ });
368
+ return res.data[task];
369
+ };
370
+
371
+ getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
372
+ let retryCount = 0;
373
+ let response = null;
374
+
375
+ while (retryCount < this.MAX_RETRY_COUNT) {
376
+ try {
377
+ response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
378
+ // If the request is successful, break out of the loop
379
+ break;
380
+ } catch (error) {
381
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
382
+ retryCount++;
383
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
384
+ }
385
+ }
386
+
387
+ if (response) {
388
+ return response;
389
+ } else {
390
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
391
+ }
392
+ };
393
+
394
+ getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
395
+ let retryCount = 0;
396
+ let response = null;
397
+
398
+ while (retryCount < this.MAX_RETRY_COUNT) {
399
+ try {
400
+ response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
401
+ // If the request is successful, break out of the loop
402
+ break;
403
+ } catch (error) {
404
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
405
+ retryCount++;
406
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
407
+ }
408
+ }
409
+
410
+ if (response) {
411
+ return response;
412
+ } else {
413
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
414
+ }
415
+ };
416
+
417
+ getComponentInverseImpulseResponse = async ({
418
+ payload,
419
+ mls,
420
+ lowHz,
421
+ highHz,
422
+ componentIRGains,
423
+ iirLength,
424
+ componentIRFreqs,
425
+ sampleRate,
426
+ mlsAmplitude,
427
+ irLength,
428
+ calibrateSoundSmoothOctaves,
429
+ calibrateSoundSmoothMinBandwidthHz,
430
+ calibrateSoundBurstFilteredExtraDb,
431
+ calibrateSoundIIRPhase
432
+ }) => {
433
+ const task = 'component-inverse-impulse-response';
434
+ let res = null;
435
+
436
+ console.log({payload});
437
+
438
+ const data = JSON.stringify({
439
+ task,
440
+ payload,
441
+ mls,
442
+ lowHz,
443
+ highHz,
444
+ iirLength,
445
+ componentIRGains,
446
+ componentIRFreqs,
447
+ sampleRate,
448
+ mlsAmplitude,
449
+ irLength,
450
+ calibrateSoundSmoothOctaves,
451
+ calibrateSoundSmoothMinBandwidthHz,
452
+ calibrateSoundBurstFilteredExtraDb,
453
+ calibrateSoundIIRPhase
454
+ });
455
+
456
+ await axios({
457
+ method: 'post',
458
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
459
+ url: `/task/${task}`,
460
+ headers: {
461
+ 'Content-Type': 'application/json',
462
+ },
463
+ data,
464
+ })
465
+ .then(response => {
466
+ res = response;
467
+ })
468
+ .catch(error => {
469
+ throw error;
470
+ });
471
+
472
+ return res.data[task];
473
+ };
474
+ getSystemInverseImpulseResponse = async ({
475
+ payload,
476
+ mls,
477
+ lowHz,
478
+ highHz,
479
+ iirLength,
480
+ sampleRate,
481
+ mlsAmplitude,
482
+ calibrateSoundBurstFilteredExtraDb,
483
+ calibrateSoundIIRPhase
484
+ }) => {
485
+ const task = 'system-inverse-impulse-response';
486
+ let res = null;
487
+
488
+ console.log({payload});
489
+
490
+ const data = JSON.stringify({
491
+ task,
492
+ payload,
493
+ mls,
494
+ lowHz,
495
+ iirLength,
496
+ highHz,
497
+ sampleRate,
498
+ mlsAmplitude,
499
+ calibrateSoundBurstFilteredExtraDb,
500
+ calibrateSoundIIRPhase
501
+ });
502
+
503
+ await axios({
504
+ method: 'post',
505
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
506
+ url: `/task/${task}`,
507
+ headers: {
508
+ 'Content-Type': 'application/json',
509
+ },
510
+ data,
511
+ })
512
+ .then(response => {
513
+ res = response;
514
+ })
515
+ .catch(error => {
516
+ throw error;
517
+ });
518
+
519
+ return res.data[task];
520
+ };
521
+
522
+ getMLSPSD = async ({mls, sampleRate}) => {
523
+ const task = 'mls-psd';
524
+ let res = null;
525
+
526
+ const data = JSON.stringify({
527
+ task,
528
+ mls,
529
+ sampleRate,
530
+ });
531
+
532
+ await axios({
533
+ method: 'post',
534
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
535
+ url: `/task/${task}`,
536
+ headers: {
537
+ 'Content-Type': 'application/json',
538
+ },
539
+ data,
540
+ })
541
+ .then(response => {
542
+ res = response;
543
+ })
544
+ .catch(error => {
545
+ throw error;
546
+ });
547
+
548
+ return res.data[task];
549
+ };
550
+
551
+ getMLSPSDWithRetry = async ({mls, sampleRate}) => {
552
+ let retryCount = 0;
553
+ let response = null;
554
+
555
+ while (retryCount < this.MAX_RETRY_COUNT) {
556
+ try {
557
+ response = await this.getMLSPSD({mls, sampleRate});
558
+ // If the request is successful, break out of the loop
559
+ break;
560
+ } catch (error) {
561
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
562
+ retryCount++;
563
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
564
+ }
565
+ }
566
+
567
+ if (response) {
568
+ return response;
569
+ } else {
570
+ throw new Error(
571
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
572
+ );
573
+ }
574
+ };
575
+
576
+ getComponentInverseImpulseResponseWithRetry = async ({
577
+ payload,
578
+ mls,
579
+ lowHz,
580
+ highHz,
581
+ componentIRGains,
582
+ iirLength,
583
+ componentIRFreqs,
584
+ sampleRate,
585
+ mlsAmplitude,
586
+ irLength,
587
+ calibrateSoundSmoothOctaves,
588
+ calibrateSoundSmoothMinBandwidthHz,
589
+ calibrateSoundBurstFilteredExtraDb,
590
+ calibrateSoundIIRPhase
591
+ }) => {
592
+ let retryCount = 0;
593
+ let response = null;
594
+
595
+ while (retryCount < this.MAX_RETRY_COUNT) {
596
+ try {
597
+ response = await this.getComponentInverseImpulseResponse({
598
+ payload,
599
+ mls,
600
+ lowHz,
601
+ highHz,
602
+ componentIRGains,
603
+ iirLength,
604
+ componentIRFreqs,
605
+ sampleRate,
606
+ mlsAmplitude,
607
+ irLength,
608
+ calibrateSoundSmoothOctaves,
609
+ calibrateSoundSmoothMinBandwidthHz,
610
+ calibrateSoundBurstFilteredExtraDb,
611
+ calibrateSoundIIRPhase
612
+ });
613
+ // If the request is successful, break out of the loop
614
+ break;
615
+ } catch (error) {
616
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
617
+ retryCount++;
618
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
619
+ }
620
+ }
621
+
622
+ if (response) {
623
+ return response;
624
+ } else {
625
+ throw new Error(
626
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
627
+ );
628
+ }
629
+ };
630
+
631
+ getSystemInverseImpulseResponseWithRetry = async ({
632
+ payload,
633
+ mls,
634
+ lowHz,
635
+ highHz,
636
+ iirLength,
637
+ sampleRate,
638
+ mlsAmplitude,
639
+ calibrateSoundBurstFilteredExtraDb,
640
+ calibrateSoundIIRPhase
641
+ }) => {
642
+ let retryCount = 0;
643
+ let response = null;
644
+
645
+ while (retryCount < this.MAX_RETRY_COUNT) {
646
+ try {
647
+ response = await this.getSystemInverseImpulseResponse({
648
+ payload,
649
+ mls,
650
+ lowHz,
651
+ highHz,
652
+ iirLength,
653
+ sampleRate,
654
+ mlsAmplitude,
655
+ calibrateSoundBurstFilteredExtraDb,
656
+ calibrateSoundIIRPhase
657
+ });
658
+ // If the request is successful, break out of the loop
659
+ break;
660
+ } catch (error) {
661
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
662
+ retryCount++;
663
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
664
+ }
665
+ }
666
+
667
+ if (response) {
668
+ return response;
669
+ } else {
670
+ throw new Error(
671
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
672
+ );
673
+ }
674
+ };
675
+
676
+ getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
677
+ const task = 'volume';
678
+ let res = null;
679
+
680
+ console.log({payload});
681
+
682
+ const data = JSON.stringify({
683
+ task,
684
+ payload,
685
+ 'sample-rate': sampleRate,
686
+ lCalib,
687
+ });
688
+
689
+ await axios({
690
+ method: 'post',
691
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
692
+ url: `/task/${task}`,
693
+ headers: {
694
+ 'Content-Type': 'application/json',
695
+ },
696
+ data,
697
+ })
698
+ .then(response => {
699
+ res = response;
700
+ })
701
+ .catch(error => {
702
+ throw error;
703
+ });
704
+
705
+ return res.data[task];
706
+ };
707
+
708
+ getVolumeCalibrationParameters = async ({
709
+ inDBValues,
710
+ outDBSPLValues,
711
+ lCalib,
712
+ componentGainDBSPL,
713
+ }) => {
714
+ const task = 'volume-parameters';
715
+ let res = null;
716
+
717
+ const data = JSON.stringify({
718
+ task,
719
+ inDBValues,
720
+ outDBSPLValues,
721
+ lCalib,
722
+ componentGainDBSPL,
723
+ });
724
+
725
+ await axios({
726
+ method: 'post',
727
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
728
+ url: `/task/${task}`,
729
+ headers: {
730
+ 'Content-Type': 'application/json',
731
+ },
732
+ data,
733
+ })
734
+ .then(response => {
735
+ res = response;
736
+ console.log(res.data[task]);
737
+ })
738
+ .catch(error => {
739
+ throw error;
740
+ });
741
+
742
+ // console.log(res.data[task]);
743
+ //below is an example of res.data[task]
744
+ //{
745
+ // R: 16.56981076554259,
746
+ // RMSError: 1.9289162528535229
747
+ // T: -47.79799120884434,
748
+ // W: 61.0485247483732,
749
+ // backgroundDBSPL: 43.88233142069752,
750
+ // gainDBSPL: -128.24742161208985
751
+ //}
752
+ return res.data[task];
753
+ };
754
+
755
+ allHzPowerCheck = async ({
756
+ payload,
757
+ sampleRate,
758
+ binDesiredSec,
759
+ burstSec,
760
+ repeats
761
+ }) => {
762
+ const task = 'all-hz-check';
763
+ let res = null;
764
+
765
+ const data = JSON.stringify({
766
+ payload,
767
+ sampleRate,
768
+ binDesiredSec,
769
+ burstSec,
770
+ repeats
771
+ });
772
+
773
+ await axios({
774
+ method: 'post',
775
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
776
+ url: `/task/${task}`,
777
+ headers: {
778
+ 'Content-Type': 'application/json',
779
+ },
780
+ data,
781
+ })
782
+ .then(response => {
783
+ res = response;
784
+ console.log(res.data[task]);
785
+ })
786
+ .catch(error => {
787
+ throw error;
788
+ });
789
+ return res.data[task];
790
+ };
791
+
792
+ volumePowerCheck = async ({
793
+ payload,
794
+ sampleRate,
795
+ preSec,
796
+ Sec,
797
+ binDesiredSec
798
+ }) => {
799
+ const task = 'volume-check';
800
+ let res = null;
801
+
802
+ const data = JSON.stringify({
803
+ payload,
804
+ sampleRate,
805
+ preSec,
806
+ Sec,
807
+ binDesiredSec
808
+ });
809
+
810
+ await axios({
811
+ method: 'post',
812
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
813
+ url: `/task/${task}`,
814
+ headers: {
815
+ 'Content-Type': 'application/json',
816
+ },
817
+ data,
818
+ })
819
+ .then(response => {
820
+ res = response;
821
+ console.log(res.data[task]);
822
+ })
823
+ .catch(error => {
824
+ throw error;
825
+ });
826
+ return res.data[task];
827
+ };
828
+ }
829
+
830
+ export default PythonServerAPI;