micSpeakerRecorder.js
JavaScript Library for Mic and/or Speaker Recorder
# Setup
Using NPM Pakacge:
npm i mic-speaker-recorder
import MicSpeakerRecorder from "micSpeakerRecorder";
Or using bundle file, download MicSpeakerRecorder.bundle.min.js file and include to your pages.
<script src="MicSpeakerRecorder.bundle.min.js"></script>
# Usage
const micSpeakerRecorder = new MicSpeakerRecorder(
{
speaker: true, // enable recording speaker
mic: true, // enable recording mic
},
function () {
// Recording callback here!
},
function (blobData) {
// Stop recording callback here!
},
function () {
// Error callback here!
}
);
// Start recording
micSpeakerRecorder.start();
// Stop recording
micSpeakerRecorder.stop();
# Example
Full example example/index.html
const $audio = $("audio");
const $startRecording = $("#btn-start-recording");
const $stopRecording = $("#btn-stop-recording");
const $title = $("h1");
const config = {
speaker: true,
mic: true,
};
const micSpeakerRecorder = new MicSpeakerRecorder(
config,
function () {
$startRecording.attr("disabled", true);
$stopRecording.attr("disabled", false);
console.log("Recording callback here!");
},
function (blobData) {
$startRecording.attr("disabled", false);
$stopRecording.attr("disabled", true);
$audio.attr("src", URL.createObjectURL(blobData));
console.log("Stop recording callback here!");
},
function () {
$startRecording.attr("disabled", false);
$stopRecording.attr("disabled", true);
console.log("Error callback here!");
}
);
$startRecording.on("click", () => {
micSpeakerRecorder.start();
});
$stopRecording.on("click", () => {
micSpeakerRecorder.stop();
});