speaker-calibration 2.2.23 → 2.2.25

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.2.23",
3
+ "version": "2.2.25",
4
4
  "description": "Speaker calibration library for auditory testing",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
@@ -32,7 +32,7 @@ class AudioRecorder extends MyEventEmitter {
32
32
  * @private
33
33
  * @example
34
34
  */
35
- #saveRecording = async (checkRec) => {
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
- console.log("Loudest 1000-Hz recording: " + dbLevel + " with " + numberOfUniqueValues + " unique values.")
51
- }else if (checkRec == 'allhz'){
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
- console.log("All Hz Recording: " + dbLevel + " with " + numberOfUniqueValues + " unique values.")
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
@@ -1079,6 +1079,15 @@ class Combination extends AudioCalibrator {
1079
1079
  return false;
1080
1080
  };
1081
1081
 
1082
+ addMicrophoneInfo = async (speakerID, OEM, micInfo) => {
1083
+ // add to database if /info does not exist
1084
+ const dbRef = ref(database);
1085
+ const snapshot = await get(child(dbRef, `Microphone2/${OEM}/${speakerID}/info`));
1086
+ if (!snapshot.exists()) {
1087
+ await set(ref(database, `Microphone2/${OEM}/${speakerID}/info`), micInfo);
1088
+ }
1089
+ };
1090
+
1082
1091
  convertToDB = gain => {
1083
1092
  return Math.log10(gain) * 20;
1084
1093
  };
@@ -1152,6 +1161,17 @@ class Combination extends AudioCalibrator {
1152
1161
  //based on zeroing of 1000hz, search for "*1000Hz"
1153
1162
  const ID = isSmartPhone ? micModelNumber : micSerialNumber;
1154
1163
  const OEM = isSmartPhone ? this.deviceInfo.OEM : micManufacturer;
1164
+ const micInfo = {
1165
+ OEM: OEM,
1166
+ ID: ID,
1167
+ HardwareName: isSmartPhone ? this.deviceInfo.hardwarename : micModelName,
1168
+ hardwareFamily: isSmartPhone ? this.deviceInfo.hardwarefamily : micModelName,
1169
+ HardwareModel: isSmartPhone ? this.deviceInfo.hardwaremodel : micModelName,
1170
+ PlatformName: isSmartPhone ? this.deviceInfo.platformname : 'N/A',
1171
+ PlatformVersion: isSmartPhone ? this.deviceInfo.platformversion : 'N/A',
1172
+ DeviceType: isSmartPhone ? this.deviceInfo.devicetype : 'N/A',
1173
+ };
1174
+ this.addMicrophoneInfo(ID, OEM, micInfo);
1155
1175
  if (componentIR == null) {
1156
1176
  //mode 'ir'
1157
1177
  //global variable this.componentIR must be set
@@ -1208,7 +1228,7 @@ class Combination extends AudioCalibrator {
1208
1228
  micModelName: micModelName,
1209
1229
  ID: ID,
1210
1230
  OEM: OEM,
1211
- micInfo: this.deviceInfo,
1231
+ micInfo: micInfo,
1212
1232
  };
1213
1233
  console.log('total results');
1214
1234
  console.log(total_results);