speaker-calibration 2.2.23 → 2.2.24
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/package.json +1 -1
- package/src/tasks/audioRecorder.js +23 -9
package/package.json
CHANGED
|
@@ -32,7 +32,7 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
32
32
|
* @private
|
|
33
33
|
* @example
|
|
34
34
|
*/
|
|
35
|
-
#saveRecording = async
|
|
35
|
+
#saveRecording = async checkRec => {
|
|
36
36
|
const arrayBuffer = await this.#audioBlob.arrayBuffer();
|
|
37
37
|
const audioBuffer = await this.#audioContext.decodeAudioData(arrayBuffer);
|
|
38
38
|
const data = audioBuffer.getChannelData(0);
|
|
@@ -40,22 +40,36 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
40
40
|
|
|
41
41
|
console.log(`Decoded audio buffer with ${data.length} samples`);
|
|
42
42
|
console.log(`Unfiltered recording should be of length: ${data.length}`);
|
|
43
|
-
if (checkRec == 'loudest'){
|
|
43
|
+
if (checkRec == 'loudest') {
|
|
44
44
|
const uniqueSet = new Set(dataArray);
|
|
45
45
|
const numberOfUniqueValues = uniqueSet.size;
|
|
46
46
|
const squaredValues = dataArray.map(value => value * value);
|
|
47
47
|
const sum_of_squares = squaredValues.reduce((total, value) => total + value, 0);
|
|
48
48
|
const squared_mean = sum_of_squares / dataArray.length;
|
|
49
49
|
const dbLevel = 20 * Math.log10(Math.sqrt(squared_mean));
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const roundedDbLevel = Math.round(dbLevel * 10) / 10;
|
|
51
|
+
console.log(
|
|
52
|
+
'Loudest 1000-Hz recording: ' +
|
|
53
|
+
roundedDbLevel +
|
|
54
|
+
' dB with ' +
|
|
55
|
+
numberOfUniqueValues +
|
|
56
|
+
' unique values.'
|
|
57
|
+
);
|
|
58
|
+
} else if (checkRec == 'allhz') {
|
|
52
59
|
const uniqueSet = new Set(dataArray);
|
|
53
60
|
const numberOfUniqueValues = uniqueSet.size;
|
|
54
61
|
const squaredValues = dataArray.map(value => value * value);
|
|
55
62
|
const sum_of_squares = squaredValues.reduce((total, value) => total + value, 0);
|
|
56
63
|
const squared_mean = sum_of_squares / dataArray.length;
|
|
57
64
|
const dbLevel = 20 * Math.log10(Math.sqrt(squared_mean));
|
|
58
|
-
|
|
65
|
+
const roundedDbLevel = Math.round(dbLevel * 10) / 10;
|
|
66
|
+
console.log(
|
|
67
|
+
'All Hz Recording: ' +
|
|
68
|
+
roundedDbLevel +
|
|
69
|
+
' dB with ' +
|
|
70
|
+
numberOfUniqueValues +
|
|
71
|
+
' unique values.'
|
|
72
|
+
);
|
|
59
73
|
}
|
|
60
74
|
this.#recordedSignals.push(dataArray);
|
|
61
75
|
};
|
|
@@ -128,7 +142,7 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
128
142
|
* @public
|
|
129
143
|
* @example
|
|
130
144
|
*/
|
|
131
|
-
stopRecording = async (mode,checkRec) => {
|
|
145
|
+
stopRecording = async (mode, checkRec) => {
|
|
132
146
|
// Stop the media recorder, and wait for the data to be available
|
|
133
147
|
await new Promise(resolve => {
|
|
134
148
|
this.#mediaRecorder.onstop = () => {
|
|
@@ -142,9 +156,9 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
142
156
|
this.#mediaRecorder.stop();
|
|
143
157
|
});
|
|
144
158
|
// Now that we have data, save it
|
|
145
|
-
if (mode === 'filtered'){
|
|
159
|
+
if (mode === 'filtered') {
|
|
146
160
|
await this.#saveFilteredRecording();
|
|
147
|
-
}else{
|
|
161
|
+
} else {
|
|
148
162
|
await this.#saveRecording(checkRec);
|
|
149
163
|
}
|
|
150
164
|
};
|
|
@@ -169,7 +183,7 @@ class AudioRecorder extends MyEventEmitter {
|
|
|
169
183
|
*/
|
|
170
184
|
getAllRecordedSignals = () => this.#recordedSignals;
|
|
171
185
|
|
|
172
|
-
|
|
186
|
+
/** .
|
|
173
187
|
* .
|
|
174
188
|
* .
|
|
175
189
|
* Public method to get all the recorded audio signals
|