speaker-calibration 2.1.0 → 2.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speaker-calibration",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -112,6 +112,44 @@ class PythonServerAPI {
112
112
 
113
113
  return res.data[task];
114
114
  };
115
+
116
+ getVolumeCalibrationParameters = async ({inDBValues, outDBSPLValues}) => {
117
+ const task = 'volume-parameters';
118
+ let res = null;
119
+
120
+ const data = JSON.stringify({
121
+ task,
122
+ inDBValues,
123
+ outDBSPLValues,
124
+ });
125
+
126
+ await axios({
127
+ method: 'post',
128
+ baseURL: PythonServerAPI.PYTHON_SERVER_URL, //server
129
+ url: `/task/${task}`,
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ },
133
+ data,
134
+ })
135
+ .then(response => {
136
+ res = response;
137
+ })
138
+ .catch(error => {
139
+ throw error;
140
+ });
141
+
142
+ // console.log(res.data[task]);
143
+ //below is an example of res.data[task]
144
+ //{
145
+ // R: 16.56981076554259,
146
+ // T: -47.79799120884434,
147
+ // W: 61.0485247483732,
148
+ // backgroundDBSPL: 43.88233142069752,
149
+ // gainDBSPL: -128.24742161208985
150
+ //}
151
+ return res.data[task];
152
+ };
115
153
  }
116
154
 
117
155
  export default PythonServerAPI;
@@ -1,5 +1,5 @@
1
1
  import AudioCalibrator from '../audioCalibrator';
2
-
2
+ import axios from 'axios';
3
3
  import {sleep} from '../../utils';
4
4
 
5
5
  /**
@@ -26,6 +26,7 @@ class Volume extends AudioCalibrator {
26
26
 
27
27
  /** @private */
28
28
  soundGainDBSPL = null;
29
+ outDBSPL = null;
29
30
 
30
31
  handleIncomingData = data => {
31
32
  console.log('Received data: ', data);
@@ -121,8 +122,9 @@ class Volume extends AudioCalibrator {
121
122
  payload: this.#getTruncatedSignal(),
122
123
  })
123
124
  .then(res => {
124
- if (this.soundGainDBSPL === null) {
125
- this.soundGainDBSPL = res;
125
+ if (this.outDBSPL === null) {
126
+ this.outDBSPL = res['outDbSPL'];
127
+ this.soundGainDBSPL = res['soundGainDbSPL'];
126
128
  }
127
129
  })
128
130
  .catch(err => {
@@ -133,10 +135,17 @@ class Volume extends AudioCalibrator {
133
135
  startCalibration = async (stream, gainValues) => {
134
136
  const trialIterations = gainValues.length;
135
137
  const soundGainDBSPLValues = [];
138
+ const inDBValues = [];
139
+ let inDB = 0;
140
+ const outDBSPLValues = [];
141
+
136
142
  // run the calibration at different gain values provided by the user
137
143
  for (let i = 0; i < trialIterations; i++) {
144
+ //convert gain to DB and add to inDB
145
+ inDB = Math.log10(gainValues[i]) * 20;
146
+ inDBValues.push(inDB);
147
+
138
148
  do {
139
- // console.log('Processing gain value: ', gainValues[i]);
140
149
  // eslint-disable-next-line no-await-in-loop
141
150
  await this.volumeCalibrationSteps(
142
151
  stream,
@@ -145,12 +154,30 @@ class Volume extends AudioCalibrator {
145
154
  this.#sendToServerForProcessing,
146
155
  gainValues[i]
147
156
  );
148
- } while (this.soundGainDBSPL === null);
157
+ } while (this.outDBSPL === null);
158
+ outDBSPLValues.push(this.outDBSPL);
149
159
  soundGainDBSPLValues.push(this.soundGainDBSPL);
160
+ this.outDBSPL = null;
150
161
  this.soundGainDBSPL = null;
151
162
  }
152
- // return this.soundGainDBSPL;
153
- return soundGainDBSPLValues;
163
+
164
+ // get the volume calibration parameters from the server
165
+ const parameters = await this.pyServerAPI
166
+ .getVolumeCalibrationParameters({inDBValues: inDBValues, outDBSPLValues: outDBSPLValues})
167
+ .then(res => {
168
+ // console.log(res);
169
+ return res;
170
+ });
171
+ // console.log('Parameters: ', parameters);
172
+ // return soundGainDBSPLValues;
173
+ const result = {
174
+ parameters: parameters,
175
+ inDBValues: inDBValues,
176
+ outDBSPLValues: outDBSPLValues,
177
+ soundGainDBSPLValues: soundGainDBSPLValues,
178
+ };
179
+ // console.log('Result: ', result);
180
+ return result;
154
181
  };
155
182
  }
156
183