speaker-calibration 2.2.161 → 2.2.163

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