speaker-calibration 2.2.24 → 2.2.26

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 +6822 -6822
  32. package/dist/example/index.html +47 -47
  33. package/dist/example/listener.html +61 -61
  34. package/dist/example/listener.js +97 -97
  35. package/dist/example/server.js +51 -51
  36. package/dist/example/speaker.html +138 -138
  37. package/dist/example/speakerUI.js +269 -269
  38. package/dist/example/styles.css +63 -63
  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 +288 -288
  99. package/src/peer-connection/peerErrors.js +25 -25
  100. package/src/peer-connection/speaker.js +436 -436
  101. package/src/server/PythonServerAPI.js +415 -415
  102. package/src/tasks/audioCalibrator.js +271 -271
  103. package/src/tasks/audioRecorder.js +223 -209
  104. package/src/tasks/combination/combination.js +1239 -1219
  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 +55 -55
  118. package/webpack.config.js +37 -37
  119. package/makefile +0 -74
@@ -1,415 +1,415 @@
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) => {
62
- const task = 'mls';
63
- let res = null
64
-
65
- const data = JSON.stringify({
66
- task,
67
- 'length':length,
68
- })
69
-
70
- await axios({
71
- method:'post',
72
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
73
- url: `/task/${task}`,
74
- headers: {
75
- 'Content-Type':'application/json',
76
- },
77
- data,
78
- })
79
- .then(response => {
80
- res = response;
81
- })
82
- .catch(error => {
83
- throw error;
84
- })
85
-
86
- return res.data[task];
87
- }
88
- getMLSWithRetry = async (length) => {
89
- let retryCount = 0;
90
- let response = null;
91
-
92
- while (retryCount < this.MAX_RETRY_COUNT) {
93
- try {
94
- response = await this.getMLS(length);
95
- // If the request is successful, break out of the loop
96
- break;
97
- } catch (error) {
98
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
99
- retryCount++;
100
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
101
- }
102
- }
103
-
104
- if (response) {
105
- return response;
106
- } else {
107
- throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
108
- }
109
- };
110
-
111
- getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
112
- const task = 'psd';
113
- let res = null;
114
-
115
- const data = JSON.stringify({
116
- task,
117
- unconv_rec,
118
- conv_rec,
119
- sampleRate,
120
- });
121
-
122
- await axios({
123
- method: 'post',
124
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
125
- url: `/task/${task}`,
126
- headers: {
127
- 'Content-Type': 'application/json',
128
- },
129
- data,
130
- })
131
- .then(response => {
132
- res = response;
133
- })
134
- .catch(error => {
135
- throw error;
136
- });
137
- return res.data[task];
138
- };
139
-
140
- getSubtractedPSD = async (rec, knownGains, knownFrequencies,sampleRate) => {
141
- const task = 'subtracted-psd';
142
- let res = null;
143
-
144
- const data = JSON.stringify({
145
- task,
146
- rec,
147
- knownGains,
148
- knownFrequencies,
149
- sampleRate,
150
- });
151
-
152
- await axios({
153
- method: 'post',
154
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
155
- url: `/task/${task}`,
156
- headers: {
157
- 'Content-Type': 'application/json',
158
- },
159
- data,
160
- })
161
- .then(response => {
162
- res = response;
163
- })
164
- .catch(error => {
165
- throw error;
166
- });
167
- return res.data[task];
168
- };
169
-
170
- getSubtractedPSDWithRetry = async ( rec, knownGains, knownFrequencies,sampleRate) => {
171
- let retryCount = 0;
172
- let response = null;
173
-
174
- while (retryCount < this.MAX_RETRY_COUNT) {
175
- try {
176
- response = await this.getSubtractedPSD( rec, knownGains, knownFrequencies,sampleRate );
177
- // If the request is successful, break out of the loop
178
- break;
179
- } catch (error) {
180
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
181
- retryCount++;
182
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
183
- }
184
- }
185
-
186
- if (response) {
187
- return response;
188
- } else {
189
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
190
- }
191
- };
192
-
193
- getPSDWithRetry = async ({ unconv_rec, conv_rec,sampleRate }) => {
194
- let retryCount = 0;
195
- let response = null;
196
-
197
- while (retryCount < this.MAX_RETRY_COUNT) {
198
- try {
199
- response = await this.getPSD({ unconv_rec, conv_rec,sampleRate });
200
- // If the request is successful, break out of the loop
201
- break;
202
- } catch (error) {
203
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
204
- retryCount++;
205
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
206
- }
207
- }
208
-
209
- if (response) {
210
- return response;
211
- } else {
212
- throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
213
- }
214
- };
215
-
216
-
217
- getComponentInverseImpulseResponse = async ({payload,mls,lowHz,highHz,componentIRGains,iirLength,componentIRFreqs,num_periods,sampleRate}) => {
218
- const task = 'component-inverse-impulse-response';
219
- let res = null;
220
-
221
- console.log({payload});
222
-
223
- const data = JSON.stringify({
224
- task,
225
- payload,
226
- mls,
227
- lowHz,
228
- highHz,
229
- iirLength,
230
- componentIRGains,
231
- componentIRFreqs,
232
- num_periods,
233
- sampleRate,
234
- });
235
-
236
- await axios({
237
- method: 'post',
238
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
239
- url: `/task/${task}`,
240
- headers: {
241
- 'Content-Type': 'application/json',
242
- },
243
- data,
244
- })
245
- .then(response => {
246
- res = response;
247
- })
248
- .catch(error => {
249
- throw error;
250
- });
251
-
252
- return res.data[task];
253
- };
254
- getSystemInverseImpulseResponse = async ({payload,mls,lowHz,highHz,iirLength,num_periods,sampleRate}) => {
255
- const task = 'system-inverse-impulse-response';
256
- let res = null;
257
-
258
- console.log({payload});
259
-
260
- const data = JSON.stringify({
261
- task,
262
- payload,
263
- mls,
264
- lowHz,
265
- iirLength,
266
- highHz,
267
- num_periods,
268
- sampleRate,
269
- });
270
-
271
- await axios({
272
- method: 'post',
273
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
274
- url: `/task/${task}`,
275
- headers: {
276
- 'Content-Type': 'application/json',
277
- },
278
- data,
279
- })
280
- .then(response => {
281
- res = response;
282
- })
283
- .catch(error => {
284
- throw error;
285
- });
286
-
287
- return res.data[task];
288
- };
289
-
290
- getComponentInverseImpulseResponseWithRetry = async ({ payload, mls, lowHz, highHz,componentIRGains,iirLength,componentIRFreqs, num_periods,sampleRate}) => {
291
- let retryCount = 0;
292
- let response = null;
293
-
294
- while (retryCount < this.MAX_RETRY_COUNT) {
295
- try {
296
- response = await this.getComponentInverseImpulseResponse({ payload, mls, lowHz, highHz,componentIRGains,iirLength,componentIRFreqs,num_periods,sampleRate});
297
- // If the request is successful, break out of the loop
298
- break;
299
- } catch (error) {
300
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
301
- retryCount++;
302
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
303
- }
304
- }
305
-
306
- if (response) {
307
- return response;
308
- } else {
309
- throw new Error(`Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`);
310
- }
311
- };
312
-
313
- getSystemInverseImpulseResponseWithRetry = async ({ payload, mls, lowHz, highHz,iirLength, num_periods,sampleRate}) => {
314
- let retryCount = 0;
315
- let response = null;
316
-
317
- while (retryCount < this.MAX_RETRY_COUNT) {
318
- try {
319
- response = await this.getSystemInverseImpulseResponse({ payload, mls, lowHz, highHz,iirLength,num_periods,sampleRate});
320
- // If the request is successful, break out of the loop
321
- break;
322
- } catch (error) {
323
- console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
324
- retryCount++;
325
- await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
326
- }
327
- }
328
-
329
- if (response) {
330
- return response;
331
- } else {
332
- throw new Error(`Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`);
333
- }
334
- };
335
-
336
-
337
-
338
- getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
339
- const task = 'volume';
340
- let res = null;
341
-
342
- console.log({payload});
343
-
344
- const data = JSON.stringify({
345
- task,
346
- payload,
347
- 'sample-rate': sampleRate,
348
- lCalib,
349
- });
350
-
351
- await axios({
352
- method: 'post',
353
- baseURL: PythonServerAPI.PYTHON_SERVER_URL,
354
- url: `/task/${task}`,
355
- headers: {
356
- 'Content-Type': 'application/json',
357
- },
358
- data,
359
- })
360
- .then(response => {
361
- res = response;
362
- })
363
- .catch(error => {
364
- throw error;
365
- });
366
-
367
- return res.data[task];
368
- };
369
-
370
- getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues, lCalib, componentGainDBSPL}) => {
371
- const task = 'volume-parameters';
372
- let res = null;
373
-
374
- const data = JSON.stringify({
375
- task,
376
- inDBValues,
377
- outDBSPLValues,
378
- lCalib,
379
- componentGainDBSPL,
380
- });
381
-
382
- await axios({
383
- method: 'post',
384
- baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
385
- url: `/task/${task}`,
386
- headers: {
387
- 'Content-Type': 'application/json',
388
- },
389
- data,
390
- })
391
- .then(response => {
392
- res = response;
393
- console.log(res.data[task]);
394
- })
395
- .catch(error => {
396
- throw error;
397
- });
398
-
399
-
400
-
401
- // console.log(res.data[task]);
402
- //below is an example of res.data[task]
403
- //{
404
- // R: 16.56981076554259,
405
- // RMSError: 1.9289162528535229
406
- // T: -47.79799120884434,
407
- // W: 61.0485247483732,
408
- // backgroundDBSPL: 43.88233142069752,
409
- // gainDBSPL: -128.24742161208985
410
- //}
411
- return res.data[task];
412
- };
413
- }
414
-
415
- 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) => {
62
+ const task = 'mls';
63
+ let res = null
64
+
65
+ const data = JSON.stringify({
66
+ task,
67
+ 'length':length,
68
+ })
69
+
70
+ await axios({
71
+ method:'post',
72
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
73
+ url: `/task/${task}`,
74
+ headers: {
75
+ 'Content-Type':'application/json',
76
+ },
77
+ data,
78
+ })
79
+ .then(response => {
80
+ res = response;
81
+ })
82
+ .catch(error => {
83
+ throw error;
84
+ })
85
+
86
+ return res.data[task];
87
+ }
88
+ getMLSWithRetry = async (length) => {
89
+ let retryCount = 0;
90
+ let response = null;
91
+
92
+ while (retryCount < this.MAX_RETRY_COUNT) {
93
+ try {
94
+ response = await this.getMLS(length);
95
+ // If the request is successful, break out of the loop
96
+ break;
97
+ } catch (error) {
98
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
99
+ retryCount++;
100
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
101
+ }
102
+ }
103
+
104
+ if (response) {
105
+ return response;
106
+ } else {
107
+ throw new Error(`Failed to get MLS after ${this.MAX_RETRY_COUNT} attempts.`);
108
+ }
109
+ };
110
+
111
+ getPSD = async ({unconv_rec, conv_rec, sampleRate}) => {
112
+ const task = 'psd';
113
+ let res = null;
114
+
115
+ const data = JSON.stringify({
116
+ task,
117
+ unconv_rec,
118
+ conv_rec,
119
+ sampleRate,
120
+ });
121
+
122
+ await axios({
123
+ method: 'post',
124
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
125
+ url: `/task/${task}`,
126
+ headers: {
127
+ 'Content-Type': 'application/json',
128
+ },
129
+ data,
130
+ })
131
+ .then(response => {
132
+ res = response;
133
+ })
134
+ .catch(error => {
135
+ throw error;
136
+ });
137
+ return res.data[task];
138
+ };
139
+
140
+ getSubtractedPSD = async (rec, knownGains, knownFrequencies,sampleRate) => {
141
+ const task = 'subtracted-psd';
142
+ let res = null;
143
+
144
+ const data = JSON.stringify({
145
+ task,
146
+ rec,
147
+ knownGains,
148
+ knownFrequencies,
149
+ sampleRate,
150
+ });
151
+
152
+ await axios({
153
+ method: 'post',
154
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
155
+ url: `/task/${task}`,
156
+ headers: {
157
+ 'Content-Type': 'application/json',
158
+ },
159
+ data,
160
+ })
161
+ .then(response => {
162
+ res = response;
163
+ })
164
+ .catch(error => {
165
+ throw error;
166
+ });
167
+ return res.data[task];
168
+ };
169
+
170
+ getSubtractedPSDWithRetry = async ( rec, knownGains, knownFrequencies,sampleRate) => {
171
+ let retryCount = 0;
172
+ let response = null;
173
+
174
+ while (retryCount < this.MAX_RETRY_COUNT) {
175
+ try {
176
+ response = await this.getSubtractedPSD( rec, knownGains, knownFrequencies,sampleRate );
177
+ // If the request is successful, break out of the loop
178
+ break;
179
+ } catch (error) {
180
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
181
+ retryCount++;
182
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
183
+ }
184
+ }
185
+
186
+ if (response) {
187
+ return response;
188
+ } else {
189
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
190
+ }
191
+ };
192
+
193
+ getPSDWithRetry = async ({ unconv_rec, conv_rec,sampleRate }) => {
194
+ let retryCount = 0;
195
+ let response = null;
196
+
197
+ while (retryCount < this.MAX_RETRY_COUNT) {
198
+ try {
199
+ response = await this.getPSD({ unconv_rec, conv_rec,sampleRate });
200
+ // If the request is successful, break out of the loop
201
+ break;
202
+ } catch (error) {
203
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
204
+ retryCount++;
205
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
206
+ }
207
+ }
208
+
209
+ if (response) {
210
+ return response;
211
+ } else {
212
+ throw new Error(`Failed to get PSD after ${this.MAX_RETRY_COUNT} attempts.`);
213
+ }
214
+ };
215
+
216
+
217
+ getComponentInverseImpulseResponse = async ({payload,mls,lowHz,highHz,componentIRGains,iirLength,componentIRFreqs,num_periods,sampleRate}) => {
218
+ const task = 'component-inverse-impulse-response';
219
+ let res = null;
220
+
221
+ console.log({payload});
222
+
223
+ const data = JSON.stringify({
224
+ task,
225
+ payload,
226
+ mls,
227
+ lowHz,
228
+ highHz,
229
+ iirLength,
230
+ componentIRGains,
231
+ componentIRFreqs,
232
+ num_periods,
233
+ sampleRate,
234
+ });
235
+
236
+ await axios({
237
+ method: 'post',
238
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
239
+ url: `/task/${task}`,
240
+ headers: {
241
+ 'Content-Type': 'application/json',
242
+ },
243
+ data,
244
+ })
245
+ .then(response => {
246
+ res = response;
247
+ })
248
+ .catch(error => {
249
+ throw error;
250
+ });
251
+
252
+ return res.data[task];
253
+ };
254
+ getSystemInverseImpulseResponse = async ({payload,mls,lowHz,highHz,iirLength,num_periods,sampleRate}) => {
255
+ const task = 'system-inverse-impulse-response';
256
+ let res = null;
257
+
258
+ console.log({payload});
259
+
260
+ const data = JSON.stringify({
261
+ task,
262
+ payload,
263
+ mls,
264
+ lowHz,
265
+ iirLength,
266
+ highHz,
267
+ num_periods,
268
+ sampleRate,
269
+ });
270
+
271
+ await axios({
272
+ method: 'post',
273
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
274
+ url: `/task/${task}`,
275
+ headers: {
276
+ 'Content-Type': 'application/json',
277
+ },
278
+ data,
279
+ })
280
+ .then(response => {
281
+ res = response;
282
+ })
283
+ .catch(error => {
284
+ throw error;
285
+ });
286
+
287
+ return res.data[task];
288
+ };
289
+
290
+ getComponentInverseImpulseResponseWithRetry = async ({ payload, mls, lowHz, highHz,componentIRGains,iirLength,componentIRFreqs, num_periods,sampleRate}) => {
291
+ let retryCount = 0;
292
+ let response = null;
293
+
294
+ while (retryCount < this.MAX_RETRY_COUNT) {
295
+ try {
296
+ response = await this.getComponentInverseImpulseResponse({ payload, mls, lowHz, highHz,componentIRGains,iirLength,componentIRFreqs,num_periods,sampleRate});
297
+ // If the request is successful, break out of the loop
298
+ break;
299
+ } catch (error) {
300
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
301
+ retryCount++;
302
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
303
+ }
304
+ }
305
+
306
+ if (response) {
307
+ return response;
308
+ } else {
309
+ throw new Error(`Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`);
310
+ }
311
+ };
312
+
313
+ getSystemInverseImpulseResponseWithRetry = async ({ payload, mls, lowHz, highHz,iirLength, num_periods,sampleRate}) => {
314
+ let retryCount = 0;
315
+ let response = null;
316
+
317
+ while (retryCount < this.MAX_RETRY_COUNT) {
318
+ try {
319
+ response = await this.getSystemInverseImpulseResponse({ payload, mls, lowHz, highHz,iirLength,num_periods,sampleRate});
320
+ // If the request is successful, break out of the loop
321
+ break;
322
+ } catch (error) {
323
+ console.error(`Error occurred. Retrying... (${retryCount + 1}/${this.MAX_RETRY_COUNT})`);
324
+ retryCount++;
325
+ await new Promise(resolve => setTimeout(resolve, this.RETRY_DELAY_MS));
326
+ }
327
+ }
328
+
329
+ if (response) {
330
+ return response;
331
+ } else {
332
+ throw new Error(`Failed to get inverse impulse response after ${this.MAX_RETRY_COUNT} attempts.`);
333
+ }
334
+ };
335
+
336
+
337
+
338
+ getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
339
+ const task = 'volume';
340
+ let res = null;
341
+
342
+ console.log({payload});
343
+
344
+ const data = JSON.stringify({
345
+ task,
346
+ payload,
347
+ 'sample-rate': sampleRate,
348
+ lCalib,
349
+ });
350
+
351
+ await axios({
352
+ method: 'post',
353
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL,
354
+ url: `/task/${task}`,
355
+ headers: {
356
+ 'Content-Type': 'application/json',
357
+ },
358
+ data,
359
+ })
360
+ .then(response => {
361
+ res = response;
362
+ })
363
+ .catch(error => {
364
+ throw error;
365
+ });
366
+
367
+ return res.data[task];
368
+ };
369
+
370
+ getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues, lCalib, componentGainDBSPL}) => {
371
+ const task = 'volume-parameters';
372
+ let res = null;
373
+
374
+ const data = JSON.stringify({
375
+ task,
376
+ inDBValues,
377
+ outDBSPLValues,
378
+ lCalib,
379
+ componentGainDBSPL,
380
+ });
381
+
382
+ await axios({
383
+ method: 'post',
384
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
385
+ url: `/task/${task}`,
386
+ headers: {
387
+ 'Content-Type': 'application/json',
388
+ },
389
+ data,
390
+ })
391
+ .then(response => {
392
+ res = response;
393
+ console.log(res.data[task]);
394
+ })
395
+ .catch(error => {
396
+ throw error;
397
+ });
398
+
399
+
400
+
401
+ // console.log(res.data[task]);
402
+ //below is an example of res.data[task]
403
+ //{
404
+ // R: 16.56981076554259,
405
+ // RMSError: 1.9289162528535229
406
+ // T: -47.79799120884434,
407
+ // W: 61.0485247483732,
408
+ // backgroundDBSPL: 43.88233142069752,
409
+ // gainDBSPL: -128.24742161208985
410
+ //}
411
+ return res.data[task];
412
+ };
413
+ }
414
+
415
+ export default PythonServerAPI;