Tentative workaround for sampleRate chrome bug

[fixes #59]
This commit is contained in:
Stefano Brilli 2021-08-25 23:13:33 +02:00
parent cd24b40e3c
commit e19a909710
1 changed files with 12 additions and 2 deletions

View File

@ -38,10 +38,20 @@ export class MediaRecorderService {
deviceId: deviceId,
echoCancellation: false,
noiseSuppression: false,
sampleRate: 44100,
sampleRate: { min: 44100, max: 44100, ideal: 44100 }, // CAVEAT: it looks like this is the only way to get 44100Hz as sampling rate for some devices in chrome
highpassFilter: false,
};
try {
this.stream = await navigator.mediaDevices.getUserMedia({ audio: recordConstraints });
} catch (err) {
if (err instanceof OverconstrainedError && err.constraint === 'sampleRate') {
console.log('Cannot obtain a sampleRate of 44100Hz. Falling back to default value...');
this.stream = await navigator.mediaDevices.getUserMedia({ audio: { ...recordConstraints, sampleRate: undefined } }); // fallback to default sampleRate
} else {
throw err;
}
}
// Dump recording settings
const audioTracks = this.stream.getAudioTracks();