speaker-calibration 2.2.79 → 2.2.81
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
package/src/config/firebase.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Import the functions you need from the SDKs you need
|
|
2
2
|
import {initializeApp} from 'firebase/app';
|
|
3
3
|
import {getDatabase} from 'firebase/database';
|
|
4
|
-
|
|
4
|
+
import {getFirestore} from 'firebase/firestore';
|
|
5
5
|
// TODO: Add SDKs for Firebase products that you want to use
|
|
6
6
|
// https://firebase.google.com/docs/web/setup#available-libraries
|
|
7
7
|
|
|
@@ -20,6 +20,7 @@ const firebaseConfig = {
|
|
|
20
20
|
|
|
21
21
|
// Initialize Firebase
|
|
22
22
|
const app = initializeApp(firebaseConfig);
|
|
23
|
-
const database = getDatabase();
|
|
23
|
+
// const database = getDatabase();
|
|
24
|
+
const database = getFirestore(app);
|
|
24
25
|
|
|
25
26
|
export default database;
|
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
CalibrationTimedOutError,
|
|
8
8
|
} from './peerErrors';
|
|
9
9
|
|
|
10
|
-
import database from '../config/firebase';
|
|
11
|
-
import {ref, set, get, child} from 'firebase/database';
|
|
12
10
|
import {phrases} from '../../dist/example/i18n';
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -48,25 +46,6 @@ class Speaker extends AudioPeer {
|
|
|
48
46
|
this.peer.on('disconnected', this.#onPeerDisconnected);
|
|
49
47
|
this.peer.on('error', this.#onPeerError);
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
static getMicrophoneNamesFromDatabase = async () => {
|
|
53
|
-
const dbRef = ref(database);
|
|
54
|
-
const snapshot = await get(child(dbRef, 'Microphone'));
|
|
55
|
-
if (snapshot.exists()) {
|
|
56
|
-
return Object.keys(snapshot.val());
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
static doesMicrophoneExist = async (speakerID, OEM) => {
|
|
62
|
-
const dbRef = ref(database);
|
|
63
|
-
const snapshot = await get(child(dbRef, `Microphone2/${OEM}/${speakerID}`));
|
|
64
|
-
if (snapshot.exists()) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
return false;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
49
|
/**
|
|
71
50
|
* Async factory method that creates the Speaker object, and returns a promise that resolves to the result of the calibration.
|
|
72
51
|
*
|
|
@@ -116,6 +95,7 @@ class Speaker extends AudioPeer {
|
|
|
116
95
|
params.calibrateSoundBurstSec,
|
|
117
96
|
params.calibrateSoundBurstsWarmup,
|
|
118
97
|
params.calibrateSoundHz,
|
|
98
|
+
params.calibrateSoundIRSec,
|
|
119
99
|
params.calibrateSoundIIRSec,
|
|
120
100
|
params.calibrateSound1000HzPreSec,
|
|
121
101
|
params.calibrateSound1000HzSec,
|
|
@@ -275,7 +275,8 @@ class PythonServerAPI {
|
|
|
275
275
|
componentIRFreqs,
|
|
276
276
|
num_periods,
|
|
277
277
|
sampleRate,
|
|
278
|
-
calibrateSoundBurstDb
|
|
278
|
+
calibrateSoundBurstDb,
|
|
279
|
+
irLength
|
|
279
280
|
}) => {
|
|
280
281
|
const task = 'component-inverse-impulse-response';
|
|
281
282
|
let res = null;
|
|
@@ -293,7 +294,8 @@ class PythonServerAPI {
|
|
|
293
294
|
componentIRFreqs,
|
|
294
295
|
num_periods,
|
|
295
296
|
sampleRate,
|
|
296
|
-
calibrateSoundBurstDb
|
|
297
|
+
calibrateSoundBurstDb,
|
|
298
|
+
irLength
|
|
297
299
|
});
|
|
298
300
|
|
|
299
301
|
await axios({
|
|
@@ -424,7 +426,8 @@ class PythonServerAPI {
|
|
|
424
426
|
componentIRFreqs,
|
|
425
427
|
num_periods,
|
|
426
428
|
sampleRate,
|
|
427
|
-
calibrateSoundBurstDb
|
|
429
|
+
calibrateSoundBurstDb,
|
|
430
|
+
irLength
|
|
428
431
|
}) => {
|
|
429
432
|
let retryCount = 0;
|
|
430
433
|
let response = null;
|
|
@@ -441,7 +444,8 @@ class PythonServerAPI {
|
|
|
441
444
|
componentIRFreqs,
|
|
442
445
|
num_periods,
|
|
443
446
|
sampleRate,
|
|
444
|
-
calibrateSoundBurstDb
|
|
447
|
+
calibrateSoundBurstDb,
|
|
448
|
+
irLength
|
|
445
449
|
});
|
|
446
450
|
// If the request is successful, break out of the loop
|
|
447
451
|
break;
|
|
@@ -3,6 +3,7 @@ import AudioCalibrator from '../audioCalibrator';
|
|
|
3
3
|
import {sleep, csvToArray, saveToCSV, saveToJSON, findMinValue, findMaxValue} from '../../utils';
|
|
4
4
|
import database from '../../config/firebase';
|
|
5
5
|
import {ref, set, get, child} from 'firebase/database';
|
|
6
|
+
import {doc, getDoc, collection, addDoc, updateDoc, setDoc} from 'firebase/firestore';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
@@ -161,6 +162,8 @@ class Combination extends AudioCalibrator {
|
|
|
161
162
|
|
|
162
163
|
iirLength = 0;
|
|
163
164
|
|
|
165
|
+
irLength = 0;
|
|
166
|
+
|
|
164
167
|
componentInvertedImpulseResponseNoBandpass = [];
|
|
165
168
|
|
|
166
169
|
componentIRInTimeDomain = [];
|
|
@@ -293,6 +296,7 @@ class Combination extends AudioCalibrator {
|
|
|
293
296
|
const mls = this.#mls;
|
|
294
297
|
const lowHz = this.#lowHz;
|
|
295
298
|
const iirLength = this.iirLength;
|
|
299
|
+
const irLength = this.irLength;
|
|
296
300
|
const num_periods = this.numMLSPerCapture + this.num_mls_to_skip;
|
|
297
301
|
const highHz = this.#highHz;
|
|
298
302
|
this.stepNum += 1;
|
|
@@ -312,6 +316,7 @@ class Combination extends AudioCalibrator {
|
|
|
312
316
|
num_periods,
|
|
313
317
|
sampleRate: this.sourceSamplingRate || 96000,
|
|
314
318
|
calibrateSoundBurstDb: this._calibrateSoundBurstDb,
|
|
319
|
+
irLength
|
|
315
320
|
})
|
|
316
321
|
.then(res => {
|
|
317
322
|
console.log(res);
|
|
@@ -1808,6 +1813,23 @@ class Combination extends AudioCalibrator {
|
|
|
1808
1813
|
return result;
|
|
1809
1814
|
};
|
|
1810
1815
|
|
|
1816
|
+
writeFrqGainToFirestore = async (speakerID, frq, gain, OEM, documentID) => {
|
|
1817
|
+
// freq and gain are too large to take samples 1 in every 100 samples
|
|
1818
|
+
|
|
1819
|
+
const sampledFrq = [];
|
|
1820
|
+
const sampledGain = [];
|
|
1821
|
+
for (let i = 0; i < frq.length; i += 100) {
|
|
1822
|
+
sampledFrq.push(frq[i]);
|
|
1823
|
+
sampledGain.push(gain[i]);
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
const data = {Freq: sampledFrq, Gain: sampledGain};
|
|
1827
|
+
// update Microphone/OEM/speakerID/default/linear
|
|
1828
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1829
|
+
await updateDoc(docRef, {
|
|
1830
|
+
linear: data,
|
|
1831
|
+
});
|
|
1832
|
+
};
|
|
1811
1833
|
// function to write frq and gain to firebase database given speakerID
|
|
1812
1834
|
writeFrqGain = async (speakerID, frq, gain, OEM) => {
|
|
1813
1835
|
// freq and gain are too large to take samples 1 in every 100 samples
|
|
@@ -1826,7 +1848,16 @@ class Combination extends AudioCalibrator {
|
|
|
1826
1848
|
|
|
1827
1849
|
// Function to Read frq and gain from firebase database given speakerID
|
|
1828
1850
|
// returns an array of frq and gain if speakerID exists, returns null otherwise
|
|
1851
|
+
readFrqGainFromFirestore = async (speakerID, OEM, documentID) => {
|
|
1852
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1853
|
+
const docSnap = await getDoc(docRef);
|
|
1829
1854
|
|
|
1855
|
+
if (docSnap.exists()) {
|
|
1856
|
+
return docSnap.data().linear;
|
|
1857
|
+
} else {
|
|
1858
|
+
return null;
|
|
1859
|
+
}
|
|
1860
|
+
};
|
|
1830
1861
|
readFrqGain = async (speakerID, OEM) => {
|
|
1831
1862
|
const dbRef = ref(database);
|
|
1832
1863
|
const snapshot = await get(child(dbRef, `Microphone2/${OEM}/${speakerID}/linear`));
|
|
@@ -1835,6 +1866,16 @@ class Combination extends AudioCalibrator {
|
|
|
1835
1866
|
}
|
|
1836
1867
|
return null;
|
|
1837
1868
|
};
|
|
1869
|
+
readGainat1000HzFromFirestore = async (speakerID, OEM, documentID) => {
|
|
1870
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1871
|
+
const docSnap = await getDoc(docRef);
|
|
1872
|
+
|
|
1873
|
+
if (docSnap.exists()) {
|
|
1874
|
+
return docSnap.data().Gain1000;
|
|
1875
|
+
} else {
|
|
1876
|
+
return null;
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1838
1879
|
|
|
1839
1880
|
readGainat1000Hz = async (speakerID, OEM) => {
|
|
1840
1881
|
const dbRef = ref(database);
|
|
@@ -1845,16 +1886,58 @@ class Combination extends AudioCalibrator {
|
|
|
1845
1886
|
return null;
|
|
1846
1887
|
};
|
|
1847
1888
|
|
|
1889
|
+
writeGainat1000HzToFirestore = async (speakerID, gain, OEM, documentID) => {
|
|
1890
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1891
|
+
|
|
1892
|
+
await updateDoc(docRef, {
|
|
1893
|
+
Gain1000: gain,
|
|
1894
|
+
});
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1848
1897
|
writeGainat1000Hz = async (speakerID, gain, OEM) => {
|
|
1849
|
-
const data = {Gain: gain};
|
|
1850
1898
|
await set(ref(database, `Microphone2/${OEM}/${speakerID}/Gain1000`), gain);
|
|
1851
1899
|
};
|
|
1852
1900
|
|
|
1901
|
+
writeIsSmartPhoneToFirestore = async (speakerID, isSmartPhone, OEM) => {
|
|
1902
|
+
// if Microphone/OEM/speakerID/default exists, leave it alone and create a new document at Microphone/OEM/speakerID and return the id of the new document
|
|
1903
|
+
|
|
1904
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, 'default');
|
|
1905
|
+
const docSnap = await getDoc(docRef);
|
|
1906
|
+
|
|
1907
|
+
if (docSnap.exists()) {
|
|
1908
|
+
// add new document
|
|
1909
|
+
const collectionRef = collection(database, 'Microphone', OEM, speakerID);
|
|
1910
|
+
// add the new document and return the id
|
|
1911
|
+
const docRef = await addDoc(collectionRef, {isSmartPhone: isSmartPhone});
|
|
1912
|
+
return docRef.id;
|
|
1913
|
+
} else {
|
|
1914
|
+
// create document at Microphone/OEM/speakerID/default
|
|
1915
|
+
await setDoc(docRef, {isSmartPhone: isSmartPhone});
|
|
1916
|
+
return 'default';
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
|
|
1853
1920
|
writeIsSmartPhone = async (speakerID, isSmartPhone, OEM) => {
|
|
1854
1921
|
const data = {isSmartPhone: isSmartPhone};
|
|
1855
1922
|
await set(ref(database, `Microphone2/${OEM}/${speakerID}/isSmartPhone`), isSmartPhone);
|
|
1856
1923
|
};
|
|
1857
1924
|
|
|
1925
|
+
writeMicrophoneInfoToFirestore = async (speakerID, micInfo, OEM, documentID) => {
|
|
1926
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1927
|
+
await updateDoc(docRef, {
|
|
1928
|
+
info: micInfo,
|
|
1929
|
+
});
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
doesMicrophoneExistInFirestore = async (speakerID, OEM, documentID) => {
|
|
1933
|
+
const docRef = doc(database, 'Microphone', OEM, speakerID, documentID);
|
|
1934
|
+
const docSnap = await getDoc(docRef);
|
|
1935
|
+
if (docSnap.exists()) {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
return false;
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1858
1941
|
doesMicrophoneExist = async (speakerID, OEM) => {
|
|
1859
1942
|
const dbRef = ref(database);
|
|
1860
1943
|
const snapshot = await get(child(dbRef, `Microphone2/${OEM}/${speakerID}`));
|
|
@@ -1943,6 +2026,7 @@ class Combination extends AudioCalibrator {
|
|
|
1943
2026
|
_calibrateSoundBurstsWarmup = 1,
|
|
1944
2027
|
_calibrateSoundHz = 48000,
|
|
1945
2028
|
_calibrateSoundIIRSec = 0.2,
|
|
2029
|
+
_calibrateSoundIRSec = 0.05,
|
|
1946
2030
|
calibrateSound1000HzPreSec = 3.5,
|
|
1947
2031
|
calibrateSound1000HzSec = 1.0,
|
|
1948
2032
|
calibrateSound1000HzPostSec = 0.5,
|
|
@@ -1959,6 +2043,7 @@ class Combination extends AudioCalibrator {
|
|
|
1959
2043
|
this.calibrateSound1000HzSec = calibrateSound1000HzSec;
|
|
1960
2044
|
this.calibrateSound1000HzPostSec = calibrateSound1000HzPostSec;
|
|
1961
2045
|
this.iirLength = Math.floor(_calibrateSoundIIRSec * this.sourceSamplingRate);
|
|
2046
|
+
this.irLength = Math.floor(_calibrateSoundIRSec * this.sourceSamplingRate);
|
|
1962
2047
|
console.log('device info:', this.deviceInfo);
|
|
1963
2048
|
this.numMLSPerCapture = _calibrateSoundBurstRepeats;
|
|
1964
2049
|
this.desired_time_per_mls = _calibrateSoundBurstSec;
|
|
@@ -1997,15 +2082,20 @@ class Combination extends AudioCalibrator {
|
|
|
1997
2082
|
}
|
|
1998
2083
|
}
|
|
1999
2084
|
|
|
2000
|
-
this.
|
|
2085
|
+
// this.writeMicrophoneInfoToFirestore(ID, micInfo, OEM, 'default');
|
|
2086
|
+
// this.addMicrophoneInfo(ID, OEM, micInfo);
|
|
2001
2087
|
if (componentIR == null) {
|
|
2002
2088
|
//mode 'ir'
|
|
2003
2089
|
//global variable this.componentIR must be set
|
|
2004
|
-
this.componentIR = await this.
|
|
2090
|
+
this.componentIR = await this.readFrqGainFromFirestore(ID, OEM, 'default').then(data => {
|
|
2005
2091
|
return data;
|
|
2006
2092
|
});
|
|
2093
|
+
// await this.readFrqGain(ID, OEM).then(data => {
|
|
2094
|
+
// return data;
|
|
2095
|
+
// });
|
|
2007
2096
|
|
|
2008
|
-
lCalib = await this.readGainat1000Hz(ID, OEM);
|
|
2097
|
+
// lCalib = await this.readGainat1000Hz(ID, OEM);
|
|
2098
|
+
lCalib = await this.readGainat1000HzFromFirestore(ID, OEM, 'default');
|
|
2009
2099
|
micInfo['gainDBSPL'] = lCalib;
|
|
2010
2100
|
// this.componentGainDBSPL = this.convertToDB(lCalib);
|
|
2011
2101
|
this.componentGainDBSPL = lCalib;
|
|
@@ -2021,7 +2111,7 @@ class Combination extends AudioCalibrator {
|
|
|
2021
2111
|
lCalib = this.findGainatFrequency(this.componentIR.Freq, this.componentIR.Gain, 1000);
|
|
2022
2112
|
// this.componentGainDBSPL = this.convertToDB(lCalib);
|
|
2023
2113
|
this.componentGainDBSPL = lCalib;
|
|
2024
|
-
await this.writeIsSmartPhone(ID, isSmartPhone, OEM);
|
|
2114
|
+
// await this.writeIsSmartPhone(ID, isSmartPhone, OEM);
|
|
2025
2115
|
}
|
|
2026
2116
|
|
|
2027
2117
|
this.oldComponentIR = this.componentIR;
|
|
@@ -2043,10 +2133,19 @@ class Combination extends AudioCalibrator {
|
|
|
2043
2133
|
// impulseResponseResults.component.ir.Gain,
|
|
2044
2134
|
// OEM
|
|
2045
2135
|
// );
|
|
2136
|
+
const id = await this.writeIsSmartPhoneToFirestore(ID, isSmartPhone, OEM);
|
|
2137
|
+
await this.writeMicrophoneInfoToFirestore(ID, micInfo, OEM, id);
|
|
2138
|
+
await this.writeFrqGainToFirestore(
|
|
2139
|
+
ID,
|
|
2140
|
+
impulseResponseResults.component.ir.Freq,
|
|
2141
|
+
impulseResponseResults.component.ir.Gain,
|
|
2142
|
+
OEM,
|
|
2143
|
+
id
|
|
2144
|
+
);
|
|
2145
|
+
await this.writeGainat1000HzToFirestore(ID, micInfo['gainDBSPL'], OEM, id);
|
|
2046
2146
|
micInfo['gainDBSPL'] = impulseResponseResults.component.gainDBSPL;
|
|
2047
2147
|
// await this.writeGainat1000Hz(ID, micInfo['gainDBSPL'], OEM);
|
|
2048
2148
|
}
|
|
2049
|
-
|
|
2050
2149
|
const total_results = {...volumeResults, ...impulseResponseResults};
|
|
2051
2150
|
total_results['filteredMLSRange'] = this.filteredMLSRange;
|
|
2052
2151
|
total_results['micInfo'] = micInfo;
|