|
@@ -139,6 +139,43 @@ export class WavAdapter extends RecordingAdapter {
|
139
|
139
|
return Promise.resolve();
|
140
|
140
|
}
|
141
|
141
|
|
|
142
|
+ /**
|
|
143
|
+ * Implements {@link RecordingAdapter#setMicDevice()}.
|
|
144
|
+ *
|
|
145
|
+ * @inheritdoc
|
|
146
|
+ */
|
|
147
|
+ setMicDevice(micDeviceId) {
|
|
148
|
+ return this._replaceMic(micDeviceId);
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ /**
|
|
152
|
+ * Replaces the current microphone MediaStream.
|
|
153
|
+ *
|
|
154
|
+ * @param {*} micDeviceId - New microphone ID.
|
|
155
|
+ * @returns {Promise}
|
|
156
|
+ */
|
|
157
|
+ _replaceMic(micDeviceId) {
|
|
158
|
+ if (this._audioContext && this._audioProcessingNode) {
|
|
159
|
+ return new Promise((resolve, reject) => {
|
|
160
|
+ this._getAudioStream(micDeviceId).then(newStream => {
|
|
161
|
+ const newSource = this._audioContext
|
|
162
|
+ .createMediaStreamSource(newStream);
|
|
163
|
+
|
|
164
|
+ this._audioSource.disconnect();
|
|
165
|
+ newSource.connect(this._audioProcessingNode);
|
|
166
|
+ this._stream = newStream;
|
|
167
|
+ this._audioSource = newSource;
|
|
168
|
+ resolve();
|
|
169
|
+ })
|
|
170
|
+ .catch(() => {
|
|
171
|
+ reject();
|
|
172
|
+ });
|
|
173
|
+ });
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ return Promise.resolve();
|
|
177
|
+ }
|
|
178
|
+
|
142
|
179
|
/**
|
143
|
180
|
* Creates a WAVE file header.
|
144
|
181
|
*
|
|
@@ -209,7 +246,9 @@ export class WavAdapter extends RecordingAdapter {
|
209
|
246
|
this._getAudioStream(micDeviceId)
|
210
|
247
|
.then(stream => {
|
211
|
248
|
this._stream = stream;
|
212
|
|
- this._audioContext = new AudioContext();
|
|
249
|
+ this._audioContext = new AudioContext({
|
|
250
|
+ sampleRate: WAV_SAMPLE_RATE
|
|
251
|
+ });
|
213
|
252
|
this._audioSource
|
214
|
253
|
= this._audioContext.createMediaStreamSource(stream);
|
215
|
254
|
this._audioProcessingNode
|
|
@@ -255,7 +294,7 @@ export class WavAdapter extends RecordingAdapter {
|
255
|
294
|
*
|
256
|
295
|
* @private
|
257
|
296
|
* @param {*} buffers - The stored buffers.
|
258
|
|
- * @param {*} length - Total length (in bytes).
|
|
297
|
+ * @param {*} length - Total length (number of samples).
|
259
|
298
|
* @returns {Blob}
|
260
|
299
|
*/
|
261
|
300
|
_exportMonoWAV(buffers, length) {
|
|
@@ -265,7 +304,7 @@ export class WavAdapter extends RecordingAdapter {
|
265
|
304
|
// ...
|
266
|
305
|
// buffers[n] = Float32Array object (audio data)
|
267
|
306
|
|
268
|
|
- const dataLength = length * 2; // why multiply by 2 here?
|
|
307
|
+ const dataLength = length * 2; // each sample = 16 bit = 2 bytes
|
269
|
308
|
const buffer = new ArrayBuffer(44 + dataLength);
|
270
|
309
|
const view = new DataView(buffer);
|
271
|
310
|
|