本文介绍了媒体记录器跨浏览器以 WAV 格式保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Media Recorder 对我来说非常好用与 Mozilla 上记录的 Web Audio API 的其余部分一起做一个相当复杂的过程.然而.除非我可以让它以波形格式始终如一地录制音频,否则它对我来说毫无用处.我曾尝试在许多浏览器上设置 MimeType,这些浏览器似乎在 Mozilla 不了解的情况下已被弃用,即使使用文档中的示例也尝试设置 mimeType 此处,不适用于任何代码.

The Media Recorder Was working fantastically for me to do a fairly complicated process along with the rest of Web Audio API documented on Mozilla. However. It is useless to me unless I can get it to record audio consistently in wave format. I have attempted to set the MimeType on many browsers which appears to be deprecated without the knowledge of Mozilla, any attempt to set the mimeType even using the example from the docs here, is not working in any code.

如果有人有任何方法可以使用前端处理(不使用服务器中介)将此文件保存为 wave,我将非常感激.

If anyone has any way that this file can be saved as a wave using front-end processing (without the use of a server intermediary) I will be very grateful to hear about it.

可能值得注意的是,只要文件编码为 wav,ogg 格式以前就对我有用.这个例子源代码 几天前在我的浏览器(Brave/Chrome)上工作,之后它开始保存为 webm 格式.

It might be worth noting that the ogg format has worked previously for me as long as the file encoding was wav. This example with source code worked until a few days ago on my browser(Brave/Chrome) after which it started saving as webm format.

另外,值得注意的是,只要我能够在录制后使用 WebAudioAPI 获取通道数据进行处理,我就不会为这个项目使用 MediaRecorder API.

Also, Worth Noting, I am not married to using MediaRecorder API for this project as long as I am able to get the channel data for processing using the WebAudioAPI after recording.

推荐答案

我构建了一个包,它应该完全符合您的要求.它被称为 extendable-media-recorder.它提供与本机 MediaRecorder 相同的接口,但允许扩展"它带有自定义编解码器.示例编解码器是 wav.

I built a package which should do exactly what you want. It's called extendable-media-recorder. It offers the same interface as the native MediaRecorder but allows to "extend" it with custom codecs. The example codec is wav.

以下是如何使用它来记录来自 getUserMedia() 的流:

Here is how you could use it to record a stream coming from getUserMedia():

import { MediaRecorder, register } from 'extendable-media-recorder';
import { connect } from 'extendable-media-recorder-wav-encoder';

await register(await connect());

const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const mediaRecoder = new MediaRecorder(stream, { mimeType: 'audio/wav' });

它将使用内置的 MediaRecorder 在 Chrome 中记录 pcm 数据.在 Firefox 和 Safari 中,Web Audio API 用于获取 pcm 数据.检索到数据后,它会发送给工作人员,工作人员将其解码为 wav.

It will use the built-in MediaRecorder to record pcm data in Chrome. In Firefox and Safari the Web Audio API is used to get the pcm data. Once the data has been retrieved it gets send to a worker which decodes it as wav.

这篇关于媒体记录器跨浏览器以 WAV 格式保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:58