Gathering detailed insights and metrics for opus-media-recorder
Gathering detailed insights and metrics for opus-media-recorder
Gathering detailed insights and metrics for opus-media-recorder
Gathering detailed insights and metrics for opus-media-recorder
@dmk-dark/opus-media-recorder-fork
MedialRecorer polyfill for Opus recording using WebAssembly
@silver-zepp/easy-media
EasyMedia - Sound Player and Recorder Library for ZeppOS.
opus-media-recorder-ts
MedialRecorer polyfill for Opus recording using WebAssembly
@dongzeli95/opus-media-recorder
MedialRecorer polyfill for Opus recording using WebAssembly
npm install opus-media-recorder
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
opus-media-recorder
is a MediaRecorder API polyfill written in ES6 and WebAssembly. It aims for cross-browser Opus codec support with various audio formats such as Ogg and WebM. opus-media-recorder
can be used as a polyfill, or it can replace the built-in MediaRecorder since opus-media-recorder
supports more MIME types.
opus-media-recorder
uses WebAssembly compiled from popular libraries (e.g libopus, libogg, libwebm, and speexdsp) to ensure good performance and standards-compliance.
opus-media-recorder | Chrome | Firefox | iOS | Edge | |
---|---|---|---|---|---|
audio/ogg | O | X | O | X | X |
audio/webm | O | O | X | X | X |
audio/wav | O | X | X | X | X |
* Both audio/ogg
and audio/webm
refer containers for Opus audio codec.
Currently the MediaRecorder API suffers from the two problems:
opus-media-recorder
tackles these problems by supporting all major modern browsers (Chrome, Firefox, iOS, and Edge) and by providing various formats.
By taking advantages of WebAssembly and Web Workers, opus-media-recorder
tries to have minimum performace penalties of running encoders in a browser.
opus-media-recorder is compatible with the Mediastream Recording API standard.
mimeType
is not specified a default encoder is loaded depending on OS:
audio/webm
audio/ogg
audio/webm
audio/wave
- because they cannot play Opus at all.For standard usages of MediaRecorder
, see the MDN reference and other online resources. Our testing website and example section may be useful as well.
1npm install --save-dev opus-media-recorder
Because opus-media-recorder
needs to load a dedicated web worker and .wasm
binaries, special configurations are necessary. In general:
1import OpusMediaRecorder from 'opus-media-recorder'; 2// Choose desired format like audio/webm. Default is audio/ogg 3const options = { mimeType: 'audio/ogg' } 4// Web worker and .wasm configuration. Note: This is NOT a part of W3C standard. 5const workerOptions = { 6 encoderWorkerFactory: function () { 7 // UMD should be used if you don't use a web worker bundler for this. 8 return new Worker('.../path/to/opus-media-recorder/encoderWorker.umd.js') 9 }, 10 OggOpusEncoderWasmPath: '.../path/to/opus-media-recorder/OggOpusEncoder.wasm', 11 WebMOpusEncoderWasmPath: '.../path/to/opus-media-recorder/WebMOpusEncoder.wasm' 12}; 13 14window.MediaRecorder = OpusMediaRecorder; 15recorder = new MediaRecorder(stream, options, workerOptions);
1import MediaRecorder from 'opus-media-recorder'; 2// Use worker-loader 3import EncoderWorker from 'worker-loader!opus-media-recorder/encoderWorker.js'; 4// You should use file-loader in webpack.config.js. 5// See webpack example link in the above section for more detail. 6import OggOpusWasm from 'opus-media-recorder/OggOpusEncoder.wasm'; 7import WebMOpusWasm from 'opus-media-recorder/WebMOpusEncoder.wasm'; 8 9// Non-standard options 10const workerOptions = { 11 encoderWorkerFactory: _ => new EncoderWorker(), 12 OggOpusEncoderWasmPath: OggOpusWasm, 13 WebMOpusEncoderWasmPath: WebMOpusWasm 14}; 15 16let recorder; 17 18function startRecording () { 19 navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => { 20 let options = { mimeType: 'audio/ogg' }; 21 // Start recording 22 recorder = new MediaRecorder(stream, options, workerOptions); 23 recorder.start(); 24 // Set record to <audio> when recording will be finished 25 recorder.addEventListener('dataavailable', (e) => { 26 audioElement.src = URL.createObjectURL(e.data); 27 }); 28 }); 29} 30 31// Recording should be started in user-initiated event like buttons 32recordButton.addEventListener('click', startRecording); 33 34// Stop recording 35stopButton.addEventListener('click', () => { 36 recorder.stop(); 37 // Remove “recording” icon from browser tab 38 recorder.stream.getTracks().forEach(i => i.stop()); 39})
<script>
tagThe OpusMediaRecorder
object is available in the global namespace using UMD.
1<!-- load OpusMediaRecorder.umd.js. OpusMediaRecorder will be loaded. --> 2<script src="https://cdn.jsdelivr.net/npm/opus-media-recorder@latest/OpusMediaRecorder.umd.js"></script> 3<!-- load encoderWorker.umd.js. This should be after OpusMediaRecorder. --> 4<!-- This script tag will create OpusMediaRecorder.encoderWorker. --> 5<script src="https://cdn.jsdelivr.net/npm/opus-media-recorder@latest/encoderWorker.umd.js"></script> 6 7<script> 8... 9// If you already load encoderWorker.js using <script> tag, 10// you don't need to define encoderWorkerFactory. 11const workerOptions = { 12 OggOpusEncoderWasmPath: 'https://cdn.jsdelivr.net/npm/opus-media-recorder@latest/OggOpusEncoder.wasm', 13 WebMOpusEncoderWasmPath: 'https://cdn.jsdelivr.net/npm/opus-media-recorder@latest/WebMOpusEncoder.wasm' 14}; 15 16// Replace MediaRecorder 17window.MediaRecorder = OpusMediaRecorder; 18let recorder = new MediaRecorder(stream, {}, workerOptions); 19... 20</script>
1// Check if MediaRecorder available. 2if (!window.MediaRecorder) { 3 window.MediaRecorder = OpusMediaRecorder; 4} 5// Check if a target format (e.g. audio/ogg) is supported. 6else if (!window.MediaRecorder.isTypeSupported('audio/ogg;codecs=opus')) { 7 window.MediaRecorder = OpusMediaRecorder; 8}
Supported:
Browsers with issues:
audio/webm
audio/webm; codecs=opus
audio/ogg
audio/ogg; codecs=opus
audio/wav
or audio/wave
opus-media-recorder
throws generic Error objects instead of native DOMException.audio/wav
is not designed for streaming, when mimeType
is audio/wav
, each dataavailabe
events produces a complete and separated .wav
file that cannot be concatenated together unlike Ogg and WebM. Therefore, it is recommended not to use timeslice
option when calling start()
, unless you know what the implication is.SecurityError
case implemented. (WIP)To build from the source, you need Emscripten, yarn, Python 2.7 or higher, and basic C program build systems such as GNU Make.
yarn install
to install JavaScript dependencies.
yarn run build
to build. yarn run build:production
to build files for distribution.
yarn run serve
to run a test web server locally. Default URL is https://localhost:9000
(It has to be HTTPS). You might have to change DEV_SERVER_URL
and DEV_SERVER_PORT
to change the address of the local test server.
yarn run clean
to clean up build files.
See CHANGELOG.md.
No vulnerabilities found.
No security vulnerabilities found.