speaker-calibration 2.2.225 → 2.2.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/example/i18n.js +1715 -1627
- package/dist/listener.js +4 -742
- package/dist/main.js +6 -224
- package/dist/phonePeer.js +1252 -0
- package/package.json +1 -1
- package/src/listener-app/PhonePeer.js +462 -0
- package/src/peer-connection/audioPeer.js +0 -48
- package/src/peer-connection/listener.js +42 -190
- package/src/peer-connection/speaker.js +167 -115
- package/src/server/PythonServerAPI.js +55 -13
- package/src/tasks/audioCalibrator.js +14 -15
- package/src/tasks/audioRecorder.js +19 -11
- package/src/tasks/combination/combination.js +265 -92
- package/webpack.config.js +1 -0
|
@@ -56,7 +56,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
56
56
|
/** @private */
|
|
57
57
|
startTime;
|
|
58
58
|
|
|
59
|
-
numCalibratingRoundsCompleted=0;
|
|
59
|
+
numCalibratingRoundsCompleted = 0;
|
|
60
60
|
/**
|
|
61
61
|
* Called when a call is received.
|
|
62
62
|
* Creates a local audio DOM element and attaches it to the page.
|
|
@@ -70,22 +70,20 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
70
70
|
targetElement.appendChild(this.localAudio);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
addTimeStamp =
|
|
73
|
+
addTimeStamp = taskName => {
|
|
74
74
|
const currentTime = new Date().getTime(); // Current time in ms
|
|
75
75
|
const elapsedTime = (currentTime - this.startTime) / 1000; // Convert to seconds
|
|
76
76
|
const stepDuration = elapsedTime - this.currentTime;
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
this.currentTime = elapsedTime; // Update for next step
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
// Format numbers to 1 decimal place without padding
|
|
81
81
|
const elapsedStr = elapsedTime.toFixed(1);
|
|
82
82
|
const stepStr = stepDuration.toFixed(1);
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
// Push timestamp string (without padding)
|
|
85
85
|
this.timeStamp.push(`${elapsedStr} s. ∆ ${stepStr} s. ${taskName}`);
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
87
|
|
|
90
88
|
recordBackground = async (
|
|
91
89
|
stream,
|
|
@@ -141,7 +139,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
141
139
|
checkRec
|
|
142
140
|
) => {
|
|
143
141
|
// if it finished 2 attempts, it move to next iteration so reset numSuccessfulCaptured
|
|
144
|
-
if (this.numSuccessfulCaptured >=2) {
|
|
142
|
+
if (this.numSuccessfulCaptured >= 2) {
|
|
145
143
|
this.numSuccessfulCaptured = 0;
|
|
146
144
|
}
|
|
147
145
|
|
|
@@ -156,8 +154,10 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
156
154
|
// do something before recording such as awaiting a certain amount of time
|
|
157
155
|
console.warn('beforeRecord');
|
|
158
156
|
await beforeRecord();
|
|
159
|
-
const totalSec =
|
|
160
|
-
|
|
157
|
+
const totalSec =
|
|
158
|
+
this._calibrateSoundBurstPreSec +
|
|
159
|
+
(this.numMLSPerCapture - this.num_mls_to_skip) * this._calibrateSoundBurstSec +
|
|
160
|
+
this._calibrateSoundBurstPostSec;
|
|
161
161
|
|
|
162
162
|
// calibration loop
|
|
163
163
|
while (loopCondition()) {
|
|
@@ -207,7 +207,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
207
207
|
maxRetry
|
|
208
208
|
) => {
|
|
209
209
|
this.numCalibratingRoundsCompleted = 0;
|
|
210
|
-
console.log(
|
|
210
|
+
console.log('maxSD in VolumeCaibrationSteps: ', maxSD, '0' >= maxSD);
|
|
211
211
|
// calibration loop
|
|
212
212
|
while (!this.isCalibrating && this.numCalibratingRoundsCompleted < maxRetry) {
|
|
213
213
|
if (this.isCalibrating) break;
|
|
@@ -232,8 +232,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
232
232
|
if (sd <= maxSD) {
|
|
233
233
|
console.log(`SD =${sd}, less than calibrateSound1000HzMaxSD_dB=${maxSD}`);
|
|
234
234
|
this.numCalibratingRoundsCompleted += maxRetry;
|
|
235
|
-
sdMessage =
|
|
236
|
-
|
|
235
|
+
sdMessage = `. SD = ${sd} dB`;
|
|
237
236
|
} else {
|
|
238
237
|
// if exist the maxSD do it one more time and only one more time
|
|
239
238
|
console.log(`SD =${sd}, greater than calibrateSound1000HzMaxSD_dB=${maxSD}`);
|
|
@@ -247,7 +246,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
247
246
|
`1000 Hz at ${this.inDB} dB${sdMessage}`
|
|
248
247
|
);
|
|
249
248
|
this.calibrationNodes = [];
|
|
250
|
-
|
|
249
|
+
|
|
251
250
|
// eslint-disable-next-line no-await-in-loop
|
|
252
251
|
await sleep(2);
|
|
253
252
|
}
|
|
@@ -284,7 +283,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
284
283
|
|
|
285
284
|
setFlags = flags => {
|
|
286
285
|
this.flags = flags;
|
|
287
|
-
}
|
|
286
|
+
};
|
|
288
287
|
|
|
289
288
|
sampleRatesSet = () => this.sourceSamplingRate && this.sinkSamplingRate;
|
|
290
289
|
|
|
@@ -87,20 +87,19 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
87
87
|
' unique values.'
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
if (mode === 'volume'){
|
|
91
|
-
console.log('Saving 1000 Hz Recording to #allVolumeRecordings')
|
|
90
|
+
if (mode === 'volume') {
|
|
91
|
+
console.log('Saving 1000 Hz Recording to #allVolumeRecordings');
|
|
92
92
|
this.#allVolumeRecordings.push(dataArray);
|
|
93
|
-
}else if (mode ==='unfiltered'){
|
|
94
|
-
console.log('Saving unfiltered all Hz recording to #allHzUnfilteredRecordings')
|
|
93
|
+
} else if (mode === 'unfiltered') {
|
|
94
|
+
console.log('Saving unfiltered all Hz recording to #allHzUnfilteredRecordings');
|
|
95
95
|
this.#allHzUnfilteredRecordings.push(dataArray);
|
|
96
|
-
}else if (mode ==='filtered'){
|
|
97
|
-
console.log('Saving filtered all hz recording to #allHzFilteredRecordings')
|
|
96
|
+
} else if (mode === 'filtered') {
|
|
97
|
+
console.log('Saving filtered all hz recording to #allHzFilteredRecordings');
|
|
98
98
|
this.#allHzFilteredRecordings.push(dataArray);
|
|
99
|
-
}else if (mode ==='background'){
|
|
100
|
-
console.log('Saving background recording to #allBackgroundRecordings')
|
|
99
|
+
} else if (mode === 'background') {
|
|
100
|
+
console.log('Saving background recording to #allBackgroundRecordings');
|
|
101
101
|
this.#allBackgroundRecordings.push(dataArray);
|
|
102
102
|
}
|
|
103
|
-
|
|
104
103
|
};
|
|
105
104
|
|
|
106
105
|
#saveFilteredRecording = async () => {
|
|
@@ -139,6 +138,11 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
139
138
|
this.#mediaRecorder.ondataavailable = e => this.#onRecorderDataAvailable(e);
|
|
140
139
|
};
|
|
141
140
|
|
|
141
|
+
#removeMediaRecorder = () => {
|
|
142
|
+
this.#mediaRecorder.ondataavailable = null;
|
|
143
|
+
this.#mediaRecorder = null;
|
|
144
|
+
};
|
|
145
|
+
|
|
142
146
|
#setAudioContext = () => {
|
|
143
147
|
this.#audioContext = new (window.AudioContext ||
|
|
144
148
|
window.webkitAudioContext ||
|
|
@@ -163,6 +167,9 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
163
167
|
if (!this.#mediaRecorder) this.#setMediaRecorder(stream);
|
|
164
168
|
// clear recorded chunks
|
|
165
169
|
this.#recordedChunks = [];
|
|
170
|
+
if (this.#mediaRecorder.state === 'recording') {
|
|
171
|
+
this.#mediaRecorder.stop();
|
|
172
|
+
}
|
|
166
173
|
// start recording
|
|
167
174
|
this.#mediaRecorder.start();
|
|
168
175
|
} catch (error) {
|
|
@@ -217,7 +224,8 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
217
224
|
* @returns
|
|
218
225
|
* @example
|
|
219
226
|
*/
|
|
220
|
-
getLastVolumeRecordedSignal = () =>
|
|
227
|
+
getLastVolumeRecordedSignal = () =>
|
|
228
|
+
Array.from(this.#allVolumeRecordings[this.#allVolumeRecordings.length - 1]);
|
|
221
229
|
|
|
222
230
|
/** .
|
|
223
231
|
* .
|
|
@@ -257,7 +265,7 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
257
265
|
* @returns
|
|
258
266
|
* @example
|
|
259
267
|
*/
|
|
260
|
-
clearAllFilteredRecordedSignals = () => this.#allHzFilteredRecordings = [];
|
|
268
|
+
clearAllFilteredRecordedSignals = () => (this.#allHzFilteredRecordings = []);
|
|
261
269
|
|
|
262
270
|
/** .
|
|
263
271
|
* .
|