speaker-calibration 2.1.2 → 2.1.4
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/speakerUI.js +2 -0
- package/dist/main.js +1 -913
- package/package.json +1 -1
- package/src/peer-connection/audioPeer.js +1 -1
- package/src/peer-connection/speaker.js +7 -3
- package/src/server/PythonServerAPI.js +5 -2
- package/src/tasks/audioCalibrator.js +3 -2
- package/src/tasks/volume/volume.js +24 -15
package/package.json
CHANGED
|
@@ -23,10 +23,10 @@ class Speaker extends AudioPeer {
|
|
|
23
23
|
*/
|
|
24
24
|
constructor(params, CalibratorInstance) {
|
|
25
25
|
super(params);
|
|
26
|
-
|
|
27
26
|
this.siteUrl += '/listener?';
|
|
28
27
|
this.ac = CalibratorInstance;
|
|
29
28
|
this.result = null;
|
|
29
|
+
this.debug = params?.debug ?? false;
|
|
30
30
|
|
|
31
31
|
/* Set up callbacks that handle any events related to our peer object. */
|
|
32
32
|
this.peer.on('open', this.#onPeerOpen);
|
|
@@ -71,7 +71,11 @@ class Speaker extends AudioPeer {
|
|
|
71
71
|
await sleep(1);
|
|
72
72
|
}
|
|
73
73
|
// resolve when we have a result
|
|
74
|
-
speaker.result = await speaker.ac.startCalibration(
|
|
74
|
+
speaker.result = await speaker.ac.startCalibration(
|
|
75
|
+
stream,
|
|
76
|
+
params.gainValues,
|
|
77
|
+
params.ICalib
|
|
78
|
+
);
|
|
75
79
|
speaker.#removeUIElems();
|
|
76
80
|
resolve(speaker.result);
|
|
77
81
|
});
|
|
@@ -158,7 +162,7 @@ class Speaker extends AudioPeer {
|
|
|
158
162
|
// If specified HTML Id is available, show QR code there
|
|
159
163
|
if (document.getElementById(this.targetElement)) {
|
|
160
164
|
if (document.getElementById(this.targetElement)) {
|
|
161
|
-
if (
|
|
165
|
+
if (this.debug) {
|
|
162
166
|
const linkTag = document.createElement('a');
|
|
163
167
|
linkTag.setAttribute('href', uri);
|
|
164
168
|
linkTag.innerHTML = "Click here to connect to the speaker's microphone";
|
|
@@ -82,7 +82,7 @@ class PythonServerAPI {
|
|
|
82
82
|
return res.data[task];
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
getVolumeCalibration = async ({payload, sampleRate}) => {
|
|
85
|
+
getVolumeCalibration = async ({payload, sampleRate, lCalib}) => {
|
|
86
86
|
const task = 'volume';
|
|
87
87
|
let res = null;
|
|
88
88
|
|
|
@@ -92,6 +92,7 @@ class PythonServerAPI {
|
|
|
92
92
|
task,
|
|
93
93
|
payload,
|
|
94
94
|
'sample-rate': sampleRate,
|
|
95
|
+
lCalib,
|
|
95
96
|
});
|
|
96
97
|
|
|
97
98
|
await axios({
|
|
@@ -113,7 +114,7 @@ class PythonServerAPI {
|
|
|
113
114
|
return res.data[task];
|
|
114
115
|
};
|
|
115
116
|
|
|
116
|
-
getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues}) => {
|
|
117
|
+
getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues, lCalib}) => {
|
|
117
118
|
const task = 'volume-parameters';
|
|
118
119
|
let res = null;
|
|
119
120
|
|
|
@@ -121,6 +122,7 @@ class PythonServerAPI {
|
|
|
121
122
|
task,
|
|
122
123
|
inDBValues,
|
|
123
124
|
outDBSPLValues,
|
|
125
|
+
lCalib,
|
|
124
126
|
});
|
|
125
127
|
|
|
126
128
|
await axios({
|
|
@@ -143,6 +145,7 @@ class PythonServerAPI {
|
|
|
143
145
|
//below is an example of res.data[task]
|
|
144
146
|
//{
|
|
145
147
|
// R: 16.56981076554259,
|
|
148
|
+
// RMSError: 1.9289162528535229
|
|
146
149
|
// T: -47.79799120884434,
|
|
147
150
|
// W: 61.0485247483732,
|
|
148
151
|
// backgroundDBSPL: 43.88233142069752,
|
|
@@ -128,7 +128,8 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
128
128
|
playCalibrationAudio,
|
|
129
129
|
beforeRecord = () => {},
|
|
130
130
|
afterRecord = () => {},
|
|
131
|
-
gainValue
|
|
131
|
+
gainValue,
|
|
132
|
+
lCalib = 104.92978421490648
|
|
132
133
|
) => {
|
|
133
134
|
this.numCalibratingRoundsCompleted = 0;
|
|
134
135
|
|
|
@@ -149,7 +150,7 @@ class AudioCalibrator extends AudioRecorder {
|
|
|
149
150
|
await this.stopRecording();
|
|
150
151
|
|
|
151
152
|
// after recording
|
|
152
|
-
await afterRecord();
|
|
153
|
+
await afterRecord(lCalib);
|
|
153
154
|
|
|
154
155
|
this.calibrationNodes = [];
|
|
155
156
|
|
|
@@ -25,8 +25,9 @@ class Volume extends AudioCalibrator {
|
|
|
25
25
|
#CALIBRATION_TONE_DURATION = 5; // seconds
|
|
26
26
|
|
|
27
27
|
/** @private */
|
|
28
|
-
soundGainDBSPL = null;
|
|
29
28
|
outDBSPL = null;
|
|
29
|
+
THD = null;
|
|
30
|
+
outDBSPL1000 = null;
|
|
30
31
|
|
|
31
32
|
handleIncomingData = data => {
|
|
32
33
|
console.log('Received data: ', data);
|
|
@@ -114,17 +115,19 @@ class Volume extends AudioCalibrator {
|
|
|
114
115
|
await sleep(totalDuration);
|
|
115
116
|
};
|
|
116
117
|
|
|
117
|
-
#sendToServerForProcessing = () => {
|
|
118
|
+
#sendToServerForProcessing = (lCalib = 104.92978421490648) => {
|
|
118
119
|
console.log('Sending data to server');
|
|
119
120
|
this.pyServerAPI
|
|
120
121
|
.getVolumeCalibration({
|
|
121
122
|
sampleRate: this.sourceSamplingRate,
|
|
122
123
|
payload: this.#getTruncatedSignal(),
|
|
124
|
+
lCalib: lCalib,
|
|
123
125
|
})
|
|
124
126
|
.then(res => {
|
|
125
127
|
if (this.outDBSPL === null) {
|
|
126
128
|
this.outDBSPL = res['outDbSPL'];
|
|
127
|
-
this.
|
|
129
|
+
this.outDBSPL1000 = res['outDbSPL1000'];
|
|
130
|
+
this.THD = res['thd'];
|
|
128
131
|
}
|
|
129
132
|
})
|
|
130
133
|
.catch(err => {
|
|
@@ -132,13 +135,13 @@ class Volume extends AudioCalibrator {
|
|
|
132
135
|
});
|
|
133
136
|
};
|
|
134
137
|
|
|
135
|
-
startCalibration = async (stream, gainValues) => {
|
|
138
|
+
startCalibration = async (stream, gainValues, lCalib = 104.92978421490648) => {
|
|
136
139
|
const trialIterations = gainValues.length;
|
|
137
|
-
const
|
|
140
|
+
const thdValues = [];
|
|
138
141
|
const inDBValues = [];
|
|
139
142
|
let inDB = 0;
|
|
140
143
|
const outDBSPLValues = [];
|
|
141
|
-
|
|
144
|
+
const outDBSPL1000Values = [];
|
|
142
145
|
// run the calibration at different gain values provided by the user
|
|
143
146
|
for (let i = 0; i < trialIterations; i++) {
|
|
144
147
|
//convert gain to DB and add to inDB
|
|
@@ -152,31 +155,37 @@ class Volume extends AudioCalibrator {
|
|
|
152
155
|
this.#playCalibrationAudio,
|
|
153
156
|
this.#createCalibrationToneWithGainValue,
|
|
154
157
|
this.#sendToServerForProcessing,
|
|
155
|
-
gainValues[i]
|
|
158
|
+
gainValues[i],
|
|
159
|
+
lCalib //todo make this a class parameter
|
|
156
160
|
);
|
|
157
161
|
} while (this.outDBSPL === null);
|
|
162
|
+
outDBSPL1000Values.push(this.outDBSPL1000);
|
|
163
|
+
thdValues.push(this.THD);
|
|
158
164
|
outDBSPLValues.push(this.outDBSPL);
|
|
159
|
-
|
|
165
|
+
|
|
160
166
|
this.outDBSPL = null;
|
|
161
|
-
this.
|
|
167
|
+
this.outDBSPL1000 = null;
|
|
168
|
+
this.THD = null;
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
// get the volume calibration parameters from the server
|
|
165
172
|
const parameters = await this.pyServerAPI
|
|
166
|
-
.getVolumeCalibrationParameters({
|
|
173
|
+
.getVolumeCalibrationParameters({
|
|
174
|
+
inDBValues: inDBValues,
|
|
175
|
+
outDBSPLValues: outDBSPL1000Values,
|
|
176
|
+
lCalib: lCalib,
|
|
177
|
+
})
|
|
167
178
|
.then(res => {
|
|
168
|
-
// console.log(res);
|
|
169
179
|
return res;
|
|
170
180
|
});
|
|
171
|
-
// console.log('Parameters: ', parameters);
|
|
172
|
-
// return soundGainDBSPLValues;
|
|
173
181
|
const result = {
|
|
174
182
|
parameters: parameters,
|
|
175
183
|
inDBValues: inDBValues,
|
|
176
184
|
outDBSPLValues: outDBSPLValues,
|
|
177
|
-
|
|
185
|
+
outDBSPL1000Values: outDBSPL1000Values,
|
|
186
|
+
thdValues: thdValues,
|
|
178
187
|
};
|
|
179
|
-
|
|
188
|
+
|
|
180
189
|
return result;
|
|
181
190
|
};
|
|
182
191
|
}
|