英文:
How do I capture only Audio from mediaDevices.getDisplayMedia?
问题
const desktopStream = await navigator.mediaDevices.getDisplayMedia({
preferCurrentTab: true,
video: true,
audio: true,
});
..
const rec = new MediaRecorder(stream, {
mimeType: 'audio/webm; codecs=opus',
});
...
const blob = new Blob(blobs, { type: 'audio/mpeg-3; codecs=opus' });
I'm trying to capture the mic and desktop audio to create an mp3 file. But the files that come are very large in size, so I'm trying to reduce the bloat.
Turning the video boolean false makes the whole thing non-operational.
英文:
const desktopStream = await navigator.mediaDevices.getDisplayMedia({
preferCurrentTab: true,
video: true,
audio: true,
});
..
const rec = new MediaRecorder(stream, {
mimeType: 'audio/webm; codecs=opus',
});
...
const blob = new Blob(blobs, { type: 'audio/mpeg-3; codecs=opus' });
I'm trying to capture the mic and desktop audio to create an mp3 file. But the files that come are very large in size, so I'm trying to reduce the bloat.
Turning the video boolean false makes the whole thing non-operational.
答案1
得分: 1
Never mind. I just get all the audio tracks from the stream and put it into a brand new stream.
const stream = new MediaStream(tracks);
console.log('Stream', stream);
const audioStream = new MediaStream();
for (const track of stream.getAudioTracks()) {
audioStream.addTrack(track);
}
for (const track of stream.getVideoTracks()) {
track.stop();
}
// eventually converted -> mpeg -> mp3
const rec = new MediaRecorder(audioStream, {
mimeType: 'audio/webm; codecs=opus',
});
Files that used to be 10-40MB are now like 1-3MBs.
英文:
Never mind. I just get all the audio tracks from the stream and put it into a brand new stream.
const stream = new MediaStream(tracks);
console.log('Stream', stream);
const audioStream = new MediaStream();
for (const track of stream.getAudioTracks()) {
audioStream.addTrack(track);
}
for (const track of stream.getVideoTracks()) {
track.stop();
}
// eventually converted -> mpeg -> mp3
const rec = new MediaRecorder(audioStream, {
mimeType: 'audio/webm; codecs=opus',
});
Files that used to be 10-40MB are now like 1-3MBs.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论