speaker-calibration 2.2.70 → 2.2.71

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 (119) 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/fetch-languages-sheets.js +77 -77
  31. package/dist/example/i18n.js +35846 -35846
  32. package/dist/example/index.html +47 -47
  33. package/dist/example/listener.html +62 -62
  34. package/dist/example/listener.js +282 -282
  35. package/dist/example/server.js +51 -51
  36. package/dist/example/speaker.html +145 -145
  37. package/dist/example/speakerUI.js +272 -272
  38. package/dist/example/styles.css +92 -92
  39. package/dist/main.js +17 -17
  40. package/dist/mlsGen.js +6814 -6814
  41. package/dist/mlsGen.wasm +0 -0
  42. package/dist/package-lock.json +1018 -1018
  43. package/dist/package.json +18 -18
  44. package/doc/AudioCalibrator.html +417 -417
  45. package/doc/AudioPeer.html +251 -251
  46. package/doc/AudioRecorder.html +195 -195
  47. package/doc/ImpulseResponse.html +215 -215
  48. package/doc/Listener.html +308 -308
  49. package/doc/MlsGenInterface.html +226 -226
  50. package/doc/MyEventEmitter.html +274 -274
  51. package/doc/PythonServerAPI.html +109 -109
  52. package/doc/Speaker.html +276 -276
  53. package/doc/Takes%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +128 -128
  54. package/doc/Takes%20the%20url%20of%20the%20current%20site%0Aand%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +138 -138
  55. package/doc/Takes%20the%20url%20of%20the%20current%20site%20and%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +137 -137
  56. package/doc/Volume.html +88 -88
  57. package/doc/audioCalibrator.js.html +179 -179
  58. package/doc/audioPeer.js.html +175 -175
  59. package/doc/audioRecorder.js.html +163 -163
  60. package/doc/creates%20a%20new%20AudioRecorder%20instance.%20%0ASets%20up%20the%20audio%20context%20and%20file%20reader..html +114 -114
  61. package/doc/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  62. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  63. package/doc/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  64. package/doc/fonts/OpenSans-Light-webfont.svg +1830 -1830
  65. package/doc/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  66. package/doc/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  67. package/doc/global.html +308 -308
  68. package/doc/index.html +58 -58
  69. package/doc/listener.js.html +170 -170
  70. package/doc/mlsGen_mlsGenInterface.js.html +117 -117
  71. package/doc/myEventEmitter.js.html +124 -124
  72. package/doc/peer-connection_audioPeer.js.html +188 -188
  73. package/doc/peer-connection_listener.js.html +311 -311
  74. package/doc/peer-connection_speaker.js.html +381 -381
  75. package/doc/scripts/linenumber.js +25 -25
  76. package/doc/scripts/prettify/Apache-License-2.0.txt +202 -202
  77. package/doc/scripts/prettify/lang-css.js +24 -24
  78. package/doc/scripts/prettify/prettify.js +640 -640
  79. package/doc/server_PythonServerAPI.js.html +160 -160
  80. package/doc/speaker.js.html +248 -248
  81. package/doc/styles/jsdoc-default.css +371 -371
  82. package/doc/styles/prettify-jsdoc.css +111 -111
  83. package/doc/styles/prettify-tomorrow.css +163 -163
  84. package/doc/tasks_audioCalibrator.js.html +207 -207
  85. package/doc/tasks_audioRecorder.js.html +190 -190
  86. package/doc/tasks_impulse-response_impulseResponse.js.html +442 -442
  87. package/doc/tasks_impulse-response_mlsGen_mlsGenInterface.js.html +175 -175
  88. package/doc/tasks_volume_volume.js.html +185 -185
  89. package/doc/utils.js.html +105 -105
  90. package/jest.config.js +173 -173
  91. package/netlify.toml +26 -26
  92. package/package.json +69 -69
  93. package/src/config/firebase.js +25 -25
  94. package/src/index.html +21 -21
  95. package/src/main.js +23 -23
  96. package/src/myEventEmitter.js +83 -83
  97. package/src/peer-connection/audioPeer.js +151 -151
  98. package/src/peer-connection/listener.js +306 -306
  99. package/src/peer-connection/peerErrors.js +25 -25
  100. package/src/peer-connection/speaker.js +473 -473
  101. package/src/server/PythonServerAPI.js +587 -587
  102. package/src/tasks/audioCalibrator.js +308 -308
  103. package/src/tasks/audioRecorder.js +281 -281
  104. package/src/tasks/combination/combination.js +2088 -2088
  105. package/src/tasks/combination/mlsGen/mlsGen.cpp +98 -98
  106. package/src/tasks/combination/mlsGen/mlsGen.hpp +303 -303
  107. package/src/tasks/combination/mlsGen/mlsGenInterface.js +131 -131
  108. package/src/tasks/combination/mlsGen/mlsGenTest.cpp +180 -180
  109. package/src/tasks/impulse-response/impulseResponse.js +610 -610
  110. package/src/tasks/impulse-response/mlsGen/mlsGen.cpp +98 -98
  111. package/src/tasks/impulse-response/mlsGen/mlsGen.hpp +303 -303
  112. package/src/tasks/impulse-response/mlsGen/mlsGenInterface.js +131 -131
  113. package/src/tasks/impulse-response/mlsGen/mlsGenTest.cpp +180 -180
  114. package/src/tasks/volume/volume.cpp +2 -2
  115. package/src/tasks/volume/volume.hpp +22 -22
  116. package/src/tasks/volume/volume.js +279 -279
  117. package/src/utils.js +88 -88
  118. package/webpack.config.js +37 -37
  119. package/makefile +0 -74
@@ -1,587 +1,587 @@
1
- import axios from 'axios';
2
- /**
3
- *
4
- */
5
- class PythonServerAPI {
6
- static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
7
-
8
- static TEST_SERVER_URL = 'http://127.0.0.1:5000';
9
- // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
10
-
11
- /** @private */
12
- MAX_RETRY_COUNT = 3;
13
- /** @private */
14
- RETRY_DELAY_MS = 1000;
15
- /**
16
- * @param data- -
17
- * g = inverted impulse response, when convolved with the impulse
18
- * reponse, they cancel out.
19
- * @param data.payload
20
- * @param data.sampleRate
21
- * @param data.P
22
- * @param data-.payload
23
- * @param data-.sampleRate
24
- * @param data-.P
25
- * @returns
26
- * @example
27
- */
28
- getImpulseResponse = async ({mls, payload, sampleRate, P, numPeriods}) => {
29
- const task = 'impulse-response';
30
- let res = null;
31
-
32
- console.log({payload});
33
-
34
- const data = JSON.stringify({
35
- task,
36
- payload,
37
- 'sample-rate': sampleRate,
38
- mls,
39
- P,
40
- numPeriods,
41
- });
42
-
43
- await axios({
44
- method: 'post',
45
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
46
- url: `/task/${task}`,
47
- headers: {
48
- 'Content-Type': 'application/json',
49
- },
50
- data,
51
- })
52
- .then(response => {
53
- res = response;
54
- })
55
- .catch(error => {
56
- throw error;
57
- });
58
- return res.data[task];
59
- };
60
-
61
- getMLS = async ({length,calibrateSoundBurstDb}) => {
62
- const task = 'mls';
63
- let res = null;
64
-
65
- const data = JSON.stringify({
66
- task,
67
- length: length,
68
- calibrateSoundBurstDb: calibrateSoundBurstDb
69
- });
70
-
71
- await axios({
72
- method: 'post',
73
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
74
- url: `/task/${task}`,
75
- headers: {
76
- 'Content-Type': 'application/json',
77
- },
78
- data,
79
- })
80
- .then(response => {
81
- res = response;
82
- })
83
- .catch(error => {
84
- throw error;
85
- });
86
-
87
- return res.data[task];
88
- };
89
- getMLSWithRetry = async ({length,calibrateSoundBurstDb}) => {
90
- let retryCount = 0;
91
- let response = null;
92
-
93
- while (retryCount < this.MAX_RETRY_COUNT) {
94
- try {
95
- response = await this.getMLS({length,calibrateSoundBurstDb});
96
- // If the request is successful, break out of the loop
97
- break;
98
- } catch (error) {
99
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
100
- retryCount++;
101
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
102
- }
103
- }
104
-
105
- if (response) {
106
- return response;
107
- } else {
108
- throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
109
- }
110
- };
111
-
112
- getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
113
- const task = 'psd';
114
- let res = null;
115
-
116
- const data = JSON.stringify({
117
- task,
118
- unconv_rec,
119
- conv_rec,
120
- sampleRate,
121
- });
122
-
123
- await axios({
124
- method: 'post',
125
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
126
- url: `/task/${task}`,
127
- headers: {
128
- 'Content-Type': 'application/json',
129
- },
130
- data,
131
- })
132
- .then(response => {
133
- res = response;
134
- })
135
- .catch(error => {
136
- throw error;
137
- });
138
- return res.data[task];
139
- };
140
-
141
- getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
142
- const task = 'background-psd';
143
- let res = null;
144
-
145
- const data = JSON.stringify({
146
- task,
147
- background_rec,
148
- sampleRate,
149
- });
150
-
151
- await axios({
152
- method: 'post',
153
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
154
- url: `/task/${task}`,
155
- headers: {
156
- 'Content-Type': 'application/json',
157
- },
158
- data,
159
- })
160
- .then(response => {
161
- res = response;
162
- })
163
- .catch(error => {
164
- throw error;
165
- });
166
- return res.data[task];
167
- };
168
-
169
- getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
170
- let retryCount = 0;
171
- let response = null;
172
-
173
- while (retryCount < this.MAX_RETRY_COUNT) {
174
- try {
175
- response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
176
- // If the request is successful, break out of the loop
177
- break;
178
- } catch (error) {
179
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
180
- retryCount++;
181
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
182
- }
183
- }
184
-
185
- if (response) {
186
- return response;
187
- } else {
188
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
189
- }
190
- };
191
-
192
- getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
193
- const task = 'subtracted-psd';
194
- let res = null;
195
-
196
- const data = JSON.stringify({
197
- task,
198
- rec,
199
- knownGains,
200
- knownFrequencies,
201
- sampleRate,
202
- });
203
-
204
- await axios({
205
- method: 'post',
206
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
207
- url: `/task/${task}`,
208
- headers: {
209
- 'Content-Type': 'application/json',
210
- },
211
- data,
212
- })
213
- .then(response => {
214
- res = response;
215
- })
216
- .catch(error => {
217
- throw error;
218
- });
219
- return res.data[task];
220
- };
221
-
222
- getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
223
- let retryCount = 0;
224
- let response = null;
225
-
226
- while (retryCount < this.MAX_RETRY_COUNT) {
227
- try {
228
- response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
229
- // If the request is successful, break out of the loop
230
- break;
231
- } catch (error) {
232
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
233
- retryCount++;
234
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
235
- }
236
- }
237
-
238
- if (response) {
239
- return response;
240
- } else {
241
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
242
- }
243
- };
244
-
245
- getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
246
- let retryCount = 0;
247
- let response = null;
248
-
249
- while (retryCount < this.MAX_RETRY_COUNT) {
250
- try {
251
- response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
252
- // If the request is successful, break out of the loop
253
- break;
254
- } catch (error) {
255
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
256
- retryCount++;
257
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
258
- }
259
- }
260
-
261
- if (response) {
262
- return response;
263
- } else {
264
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
265
- }
266
- };
267
-
268
- getComponentInverseImpulseResponse = async ({
269
- payload,
270
- mls,
271
- lowHz,
272
- highHz,
273
- componentIRGains,
274
- iirLength,
275
- componentIRFreqs,
276
- num_periods,
277
- sampleRate,
278
- calibrateSoundBurstDb
279
- }) => {
280
- const task = 'component-inverse-impulse-response';
281
- let res = null;
282
-
283
- console.log({payload});
284
-
285
- const data = JSON.stringify({
286
- task,
287
- payload,
288
- mls,
289
- lowHz,
290
- highHz,
291
- iirLength,
292
- componentIRGains,
293
- componentIRFreqs,
294
- num_periods,
295
- sampleRate,
296
- calibrateSoundBurstDb
297
- });
298
-
299
- await axios({
300
- method: 'post',
301
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
302
- url: `/task/${task}`,
303
- headers: {
304
- 'Content-Type': 'application/json',
305
- },
306
- data,
307
- })
308
- .then(response => {
309
- res = response;
310
- })
311
- .catch(error => {
312
- throw error;
313
- });
314
-
315
- return res.data[task];
316
- };
317
- getSystemInverseImpulseResponse = async ({
318
- payload,
319
- mls,
320
- lowHz,
321
- highHz,
322
- iirLength,
323
- num_periods,
324
- sampleRate,
325
- calibrateSoundBurstDb
326
- }) => {
327
- const task = 'system-inverse-impulse-response';
328
- let res = null;
329
-
330
- console.log({payload});
331
-
332
- const data = JSON.stringify({
333
- task,
334
- payload,
335
- mls,
336
- lowHz,
337
- iirLength,
338
- highHz,
339
- num_periods,
340
- sampleRate,
341
- calibrateSoundBurstDb
342
- });
343
-
344
- await axios({
345
- method: 'post',
346
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
347
- url: `/task/${task}`,
348
- headers: {
349
- 'Content-Type': 'application/json',
350
- },
351
- data,
352
- })
353
- .then(response => {
354
- res = response;
355
- })
356
- .catch(error => {
357
- throw error;
358
- });
359
-
360
- return res.data[task];
361
- };
362
-
363
- getMLSPSD = async ({mls, sampleRate}) => {
364
- const task = 'mls-psd';
365
- let res = null;
366
-
367
- const data = JSON.stringify({
368
- task,
369
- mls,
370
- sampleRate,
371
- });
372
-
373
- await axios({
374
- method: 'post',
375
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
376
- url: `/task/${task}`,
377
- headers: {
378
- 'Content-Type': 'application/json',
379
- },
380
- data,
381
- })
382
- .then(response => {
383
- res = response;
384
- })
385
- .catch(error => {
386
- throw error;
387
- });
388
-
389
- return res.data[task];
390
- };
391
-
392
- getMLSPSDWithRetry = async ({mls, sampleRate}) => {
393
- let retryCount = 0;
394
- let response = null;
395
-
396
- while (retryCount < this.MAX_RETRY_COUNT) {
397
- try {
398
- response = await this.getMLSPSD({mls, sampleRate});
399
- // If the request is successful, break out of the loop
400
- break;
401
- } catch (error) {
402
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
403
- retryCount++;
404
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
405
- }
406
- }
407
-
408
- if (response) {
409
- return response;
410
- } else {
411
- throw new Error(
412
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
413
- );
414
- }
415
- };
416
-
417
- getComponentInverseImpulseResponseWithRetry = async ({
418
- payload,
419
- mls,
420
- lowHz,
421
- highHz,
422
- componentIRGains,
423
- iirLength,
424
- componentIRFreqs,
425
- num_periods,
426
- sampleRate,
427
- calibrateSoundBurstDb
428
- }) => {
429
- let retryCount = 0;
430
- let response = null;
431
-
432
- while (retryCount < this.MAX_RETRY_COUNT) {
433
- try {
434
- response = await this.getComponentInverseImpulseResponse({
435
- payload,
436
- mls,
437
- lowHz,
438
- highHz,
439
- componentIRGains,
440
- iirLength,
441
- componentIRFreqs,
442
- num_periods,
443
- sampleRate,
444
- calibrateSoundBurstDb
445
- });
446
- // If the request is successful, break out of the loop
447
- break;
448
- } catch (error) {
449
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
450
- retryCount++;
451
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
452
- }
453
- }
454
-
455
- if (response) {
456
- return response;
457
- } else {
458
- throw new Error(
459
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
460
- );
461
- }
462
- };
463
-
464
- getSystemInverseImpulseResponseWithRetry = async ({
465
- payload,
466
- mls,
467
- lowHz,
468
- highHz,
469
- iirLength,
470
- num_periods,
471
- sampleRate,
472
- calibrateSoundBurstDb
473
- }) => {
474
- let retryCount = 0;
475
- let response = null;
476
-
477
- while (retryCount < this.MAX_RETRY_COUNT) {
478
- try {
479
- response = await this.getSystemInverseImpulseResponse({
480
- payload,
481
- mls,
482
- lowHz,
483
- highHz,
484
- iirLength,
485
- num_periods,
486
- sampleRate,
487
- calibrateSoundBurstDb
488
- });
489
- // If the request is successful, break out of the loop
490
- break;
491
- } catch (error) {
492
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
493
- retryCount++;
494
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
495
- }
496
- }
497
-
498
- if (response) {
499
- return response;
500
- } else {
501
- throw new Error(
502
- `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
503
- );
504
- }
505
- };
506
-
507
- getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
508
- const task = 'volume';
509
- let res = null;
510
-
511
- console.log({payload});
512
-
513
- const data = JSON.stringify({
514
- task,
515
- payload,
516
- 'sample-rate': sampleRate,
517
- lCalib,
518
- });
519
-
520
- await axios({
521
- method: 'post',
522
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
523
- url: `/task/${task}`,
524
- headers: {
525
- 'Content-Type': 'application/json',
526
- },
527
- data,
528
- })
529
- .then(response => {
530
- res = response;
531
- })
532
- .catch(error => {
533
- throw error;
534
- });
535
-
536
- return res.data[task];
537
- };
538
-
539
- getVolumeCalibrationParameters = async ({
540
- inDBValues,
541
- outDBSPLValues,
542
- lCalib,
543
- componentGainDBSPL,
544
- }) => {
545
- const task = 'volume-parameters';
546
- let res = null;
547
-
548
- const data = JSON.stringify({
549
- task,
550
- inDBValues,
551
- outDBSPLValues,
552
- lCalib,
553
- componentGainDBSPL,
554
- });
555
-
556
- await axios({
557
- method: 'post',
558
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
559
- url: `/task/${task}`,
560
- headers: {
561
- 'Content-Type': 'application/json',
562
- },
563
- data,
564
- })
565
- .then(response => {
566
- res = response;
567
- console.log(res.data[task]);
568
- })
569
- .catch(error => {
570
- throw error;
571
- });
572
-
573
- // console.log(res.data[task]);
574
- //below is an example of res.data[task]
575
- //{
576
- // R: 16.56981076554259,
577
- // RMSError: 1.9289162528535229
578
- // T: -47.79799120884434,
579
- // W: 61.0485247483732,
580
- // backgroundDBSPL: 43.88233142069752,
581
- // gainDBSPL: -128.24742161208985
582
- //}
583
- return res.data[task];
584
- };
585
- }
586
-
587
- export default PythonServerAPI;
1
+ import axios from 'axios';
2
+ /**
3
+ *
4
+ */
5
+ class PythonServerAPI {
6
+ static PYTHON_SERVER_URL = 'https://easyeyes-python-flask-server.herokuapp.com';
7
+
8
+ static TEST_SERVER_URL = 'http://127.0.0.1:5000';
9
+ // static PYTHON_SERVER_URL ='http://127.0.0.1:5000';
10
+
11
+ /** @private */
12
+ MAX_RETRY_COUNT = 3;
13
+ /** @private */
14
+ RETRY_DELAY_MS = 1000;
15
+ /**
16
+ * @param data- -
17
+ * g = inverted impulse response, when convolved with the impulse
18
+ * reponse, they cancel out.
19
+ * @param data.payload
20
+ * @param data.sampleRate
21
+ * @param data.P
22
+ * @param data-.payload
23
+ * @param data-.sampleRate
24
+ * @param data-.P
25
+ * @returns
26
+ * @example
27
+ */
28
+ getImpulseResponse = async ({mls, payload, sampleRate, P, numPeriods}) => {
29
+ const task = 'impulse-response';
30
+ let res = null;
31
+
32
+ console.log({payload});
33
+
34
+ const data = JSON.stringify({
35
+ task,
36
+ payload,
37
+ 'sample-rate': sampleRate,
38
+ mls,
39
+ P,
40
+ numPeriods,
41
+ });
42
+
43
+ await axios({
44
+ method: 'post',
45
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
46
+ url: `/task/${task}`,
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ },
50
+ data,
51
+ })
52
+ .then(response => {
53
+ res = response;
54
+ })
55
+ .catch(error => {
56
+ throw error;
57
+ });
58
+ return res.data[task];
59
+ };
60
+
61
+ getMLS = async ({length,calibrateSoundBurstDb}) => {
62
+ const task = 'mls';
63
+ let res = null;
64
+
65
+ const data = JSON.stringify({
66
+ task,
67
+ length: length,
68
+ calibrateSoundBurstDb: calibrateSoundBurstDb
69
+ });
70
+
71
+ await axios({
72
+ method: 'post',
73
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
74
+ url: `/task/${task}`,
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ },
78
+ data,
79
+ })
80
+ .then(response => {
81
+ res = response;
82
+ })
83
+ .catch(error => {
84
+ throw error;
85
+ });
86
+
87
+ return res.data[task];
88
+ };
89
+ getMLSWithRetry = async ({length,calibrateSoundBurstDb}) => {
90
+ let retryCount = 0;
91
+ let response = null;
92
+
93
+ while (retryCount < this.MAX_RETRY_COUNT) {
94
+ try {
95
+ response = await this.getMLS({length,calibrateSoundBurstDb});
96
+ // If the request is successful, break out of the loop
97
+ break;
98
+ } catch (error) {
99
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
100
+ retryCount++;
101
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
102
+ }
103
+ }
104
+
105
+ if (response) {
106
+ return response;
107
+ } else {
108
+ throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
109
+ }
110
+ };
111
+
112
+ getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
113
+ const task = 'psd';
114
+ let res = null;
115
+
116
+ const data = JSON.stringify({
117
+ task,
118
+ unconv_rec,
119
+ conv_rec,
120
+ sampleRate,
121
+ });
122
+
123
+ await axios({
124
+ method: 'post',
125
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
126
+ url: `/task/${task}`,
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ },
130
+ data,
131
+ })
132
+ .then(response => {
133
+ res = response;
134
+ })
135
+ .catch(error => {
136
+ throw error;
137
+ });
138
+ return res.data[task];
139
+ };
140
+
141
+ getBackgroundNoisePSD = async ({background_rec, sampleRate}) => {
142
+ const task = 'background-psd';
143
+ let res = null;
144
+
145
+ const data = JSON.stringify({
146
+ task,
147
+ background_rec,
148
+ sampleRate,
149
+ });
150
+
151
+ await axios({
152
+ method: 'post',
153
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
154
+ url: `/task/${task}`,
155
+ headers: {
156
+ 'Content-Type': 'application/json',
157
+ },
158
+ data,
159
+ })
160
+ .then(response => {
161
+ res = response;
162
+ })
163
+ .catch(error => {
164
+ throw error;
165
+ });
166
+ return res.data[task];
167
+ };
168
+
169
+ getBackgroundNoisePSDWithRetry = async ({background_rec, sampleRate}) => {
170
+ let retryCount = 0;
171
+ let response = null;
172
+
173
+ while (retryCount < this.MAX_RETRY_COUNT) {
174
+ try {
175
+ response = await this.getBackgroundNoisePSD({background_rec, sampleRate});
176
+ // If the request is successful, break out of the loop
177
+ break;
178
+ } catch (error) {
179
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
180
+ retryCount++;
181
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
182
+ }
183
+ }
184
+
185
+ if (response) {
186
+ return response;
187
+ } else {
188
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
189
+ }
190
+ };
191
+
192
+ getSubtractedPSD = async (rec, knownGains, knownFrequencies, sampleRate) => {
193
+ const task = 'subtracted-psd';
194
+ let res = null;
195
+
196
+ const data = JSON.stringify({
197
+ task,
198
+ rec,
199
+ knownGains,
200
+ knownFrequencies,
201
+ sampleRate,
202
+ });
203
+
204
+ await axios({
205
+ method: 'post',
206
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
207
+ url: `/task/${task}`,
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ },
211
+ data,
212
+ })
213
+ .then(response => {
214
+ res = response;
215
+ })
216
+ .catch(error => {
217
+ throw error;
218
+ });
219
+ return res.data[task];
220
+ };
221
+
222
+ getSubtractedPSDWithRetry = async (rec, knownGains, knownFrequencies, sampleRate) => {
223
+ let retryCount = 0;
224
+ let response = null;
225
+
226
+ while (retryCount < this.MAX_RETRY_COUNT) {
227
+ try {
228
+ response = await this.getSubtractedPSD(rec, knownGains, knownFrequencies, sampleRate);
229
+ // If the request is successful, break out of the loop
230
+ break;
231
+ } catch (error) {
232
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
233
+ retryCount++;
234
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
235
+ }
236
+ }
237
+
238
+ if (response) {
239
+ return response;
240
+ } else {
241
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
242
+ }
243
+ };
244
+
245
+ getPSDWithRetry = async ({unconv_rec, conv_rec, sampleRate}) => {
246
+ let retryCount = 0;
247
+ let response = null;
248
+
249
+ while (retryCount < this.MAX_RETRY_COUNT) {
250
+ try {
251
+ response = await this.getPSD({unconv_rec, conv_rec, sampleRate});
252
+ // If the request is successful, break out of the loop
253
+ break;
254
+ } catch (error) {
255
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
256
+ retryCount++;
257
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
258
+ }
259
+ }
260
+
261
+ if (response) {
262
+ return response;
263
+ } else {
264
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
265
+ }
266
+ };
267
+
268
+ getComponentInverseImpulseResponse = async ({
269
+ payload,
270
+ mls,
271
+ lowHz,
272
+ highHz,
273
+ componentIRGains,
274
+ iirLength,
275
+ componentIRFreqs,
276
+ num_periods,
277
+ sampleRate,
278
+ calibrateSoundBurstDb
279
+ }) => {
280
+ const task = 'component-inverse-impulse-response';
281
+ let res = null;
282
+
283
+ console.log({payload});
284
+
285
+ const data = JSON.stringify({
286
+ task,
287
+ payload,
288
+ mls,
289
+ lowHz,
290
+ highHz,
291
+ iirLength,
292
+ componentIRGains,
293
+ componentIRFreqs,
294
+ num_periods,
295
+ sampleRate,
296
+ calibrateSoundBurstDb
297
+ });
298
+
299
+ await axios({
300
+ method: 'post',
301
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
302
+ url: `/task/${task}`,
303
+ headers: {
304
+ 'Content-Type': 'application/json',
305
+ },
306
+ data,
307
+ })
308
+ .then(response => {
309
+ res = response;
310
+ })
311
+ .catch(error => {
312
+ throw error;
313
+ });
314
+
315
+ return res.data[task];
316
+ };
317
+ getSystemInverseImpulseResponse = async ({
318
+ payload,
319
+ mls,
320
+ lowHz,
321
+ highHz,
322
+ iirLength,
323
+ num_periods,
324
+ sampleRate,
325
+ calibrateSoundBurstDb
326
+ }) => {
327
+ const task = 'system-inverse-impulse-response';
328
+ let res = null;
329
+
330
+ console.log({payload});
331
+
332
+ const data = JSON.stringify({
333
+ task,
334
+ payload,
335
+ mls,
336
+ lowHz,
337
+ iirLength,
338
+ highHz,
339
+ num_periods,
340
+ sampleRate,
341
+ calibrateSoundBurstDb
342
+ });
343
+
344
+ await axios({
345
+ method: 'post',
346
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
347
+ url: `/task/${task}`,
348
+ headers: {
349
+ 'Content-Type': 'application/json',
350
+ },
351
+ data,
352
+ })
353
+ .then(response => {
354
+ res = response;
355
+ })
356
+ .catch(error => {
357
+ throw error;
358
+ });
359
+
360
+ return res.data[task];
361
+ };
362
+
363
+ getMLSPSD = async ({mls, sampleRate}) => {
364
+ const task = 'mls-psd';
365
+ let res = null;
366
+
367
+ const data = JSON.stringify({
368
+ task,
369
+ mls,
370
+ sampleRate,
371
+ });
372
+
373
+ await axios({
374
+ method: 'post',
375
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
376
+ url: `/task/${task}`,
377
+ headers: {
378
+ 'Content-Type': 'application/json',
379
+ },
380
+ data,
381
+ })
382
+ .then(response => {
383
+ res = response;
384
+ })
385
+ .catch(error => {
386
+ throw error;
387
+ });
388
+
389
+ return res.data[task];
390
+ };
391
+
392
+ getMLSPSDWithRetry = async ({mls, sampleRate}) => {
393
+ let retryCount = 0;
394
+ let response = null;
395
+
396
+ while (retryCount < this.MAX_RETRY_COUNT) {
397
+ try {
398
+ response = await this.getMLSPSD({mls, sampleRate});
399
+ // If the request is successful, break out of the loop
400
+ break;
401
+ } catch (error) {
402
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
403
+ retryCount++;
404
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
405
+ }
406
+ }
407
+
408
+ if (response) {
409
+ return response;
410
+ } else {
411
+ throw new Error(
412
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
413
+ );
414
+ }
415
+ };
416
+
417
+ getComponentInverseImpulseResponseWithRetry = async ({
418
+ payload,
419
+ mls,
420
+ lowHz,
421
+ highHz,
422
+ componentIRGains,
423
+ iirLength,
424
+ componentIRFreqs,
425
+ num_periods,
426
+ sampleRate,
427
+ calibrateSoundBurstDb
428
+ }) => {
429
+ let retryCount = 0;
430
+ let response = null;
431
+
432
+ while (retryCount < this.MAX_RETRY_COUNT) {
433
+ try {
434
+ response = await this.getComponentInverseImpulseResponse({
435
+ payload,
436
+ mls,
437
+ lowHz,
438
+ highHz,
439
+ componentIRGains,
440
+ iirLength,
441
+ componentIRFreqs,
442
+ num_periods,
443
+ sampleRate,
444
+ calibrateSoundBurstDb
445
+ });
446
+ // If the request is successful, break out of the loop
447
+ break;
448
+ } catch (error) {
449
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
450
+ retryCount++;
451
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
452
+ }
453
+ }
454
+
455
+ if (response) {
456
+ return response;
457
+ } else {
458
+ throw new Error(
459
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
460
+ );
461
+ }
462
+ };
463
+
464
+ getSystemInverseImpulseResponseWithRetry = async ({
465
+ payload,
466
+ mls,
467
+ lowHz,
468
+ highHz,
469
+ iirLength,
470
+ num_periods,
471
+ sampleRate,
472
+ calibrateSoundBurstDb
473
+ }) => {
474
+ let retryCount = 0;
475
+ let response = null;
476
+
477
+ while (retryCount < this.MAX_RETRY_COUNT) {
478
+ try {
479
+ response = await this.getSystemInverseImpulseResponse({
480
+ payload,
481
+ mls,
482
+ lowHz,
483
+ highHz,
484
+ iirLength,
485
+ num_periods,
486
+ sampleRate,
487
+ calibrateSoundBurstDb
488
+ });
489
+ // If the request is successful, break out of the loop
490
+ break;
491
+ } catch (error) {
492
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
493
+ retryCount++;
494
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
495
+ }
496
+ }
497
+
498
+ if (response) {
499
+ return response;
500
+ } else {
501
+ throw new Error(
502
+ `Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`
503
+ );
504
+ }
505
+ };
506
+
507
+ getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
508
+ const task = 'volume';
509
+ let res = null;
510
+
511
+ console.log({payload});
512
+
513
+ const data = JSON.stringify({
514
+ task,
515
+ payload,
516
+ 'sample-rate': sampleRate,
517
+ lCalib,
518
+ });
519
+
520
+ await axios({
521
+ method: 'post',
522
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
523
+ url: `/task/${task}`,
524
+ headers: {
525
+ 'Content-Type': 'application/json',
526
+ },
527
+ data,
528
+ })
529
+ .then(response => {
530
+ res = response;
531
+ })
532
+ .catch(error => {
533
+ throw error;
534
+ });
535
+
536
+ return res.data[task];
537
+ };
538
+
539
+ getVolumeCalibrationParameters = async ({
540
+ inDBValues,
541
+ outDBSPLValues,
542
+ lCalib,
543
+ componentGainDBSPL,
544
+ }) => {
545
+ const task = 'volume-parameters';
546
+ let res = null;
547
+
548
+ const data = JSON.stringify({
549
+ task,
550
+ inDBValues,
551
+ outDBSPLValues,
552
+ lCalib,
553
+ componentGainDBSPL,
554
+ });
555
+
556
+ await axios({
557
+ method: 'post',
558
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
559
+ url: `/task/${task}`,
560
+ headers: {
561
+ 'Content-Type': 'application/json',
562
+ },
563
+ data,
564
+ })
565
+ .then(response => {
566
+ res = response;
567
+ console.log(res.data[task]);
568
+ })
569
+ .catch(error => {
570
+ throw error;
571
+ });
572
+
573
+ // console.log(res.data[task]);
574
+ //below is an example of res.data[task]
575
+ //{
576
+ // R: 16.56981076554259,
577
+ // RMSError: 1.9289162528535229
578
+ // T: -47.79799120884434,
579
+ // W: 61.0485247483732,
580
+ // backgroundDBSPL: 43.88233142069752,
581
+ // gainDBSPL: -128.24742161208985
582
+ //}
583
+ return res.data[task];
584
+ };
585
+ }
586
+
587
+ export default PythonServerAPI;