Installation
This utility package provides a few ways in which you can record audios from the browser.
Install the recording package: You can install the utility package via npm by running the following command in your terminal:
npm install @vocale/recording
Import the Recorder: Once installed, you can import the recorders into your JavaScript files as follows:
import { Recorder } from '@vocale/recording';Recorder Usage: The Recorder is a simple utility to manage audio recording directly from the browser. It provides methods for recording and events to monitor the recording process.
Creating a Recorder Instance
To use the Recorder, create a new instance:
const recorder = new Recorder();
Event Listeners
The Recorder emits events during its lifecycle that you can listen to for updates:
- start: Triggered when the recording starts.
recorder.addEventListener('start', () => {
console.log('Recording started');
});
- volumechange: Triggered when there's a change in the recording volume, providing a volume parameter.
recorder.addEventListener('volumechange', ({ volume }) => {
console.log('Current volume:', volume);
});
- stop: Triggered when the recording stops, providing the recorded audio as a blob.
recorder.addEventListener('stop', ({ blob }) => {
console.log('Recording stopped. Audio Blob:', blob);
});
Starting and Stopping a Recording
To begin recording, use the startRecording method. Once done, stop the recording using the stopRecording method:
await recorder.startRecording(); // Starts the recording process recorder.stopRecording(); // Stops the recording and triggers the 'stop' event