Open
Description
At the moment Spectro just builds to a demo. It should be turned into a library, with the existing demo being moved into a demo
or examples
folder.
I imagine the API looking something like this:
// Creates a spectrogram attached to the given canvas, provides automatic handling
// of when the canvas is resized
const canvas = document.getElementById('spectrogram-canvas');
const spectrogram = new Spectrogram(canvas);
// Change display parameters of the spectrogram
spectrogram.updateRenderSettings({
zoom: 1.5,
minFrequencyHz: 0,
maxFrequencyHz: 12000,
scale: 'mel',
color: /* object representing a color gradient */
});
// Start recording from mic, will prompt for permissions and return a promise once
// recording has started
await spectrogram.recordFromMic();
// Play audio file, can take URL or File object with option to mute output
await spectrogram.playAudioFile(file, mute = true);
// Manual API where audio data is streamed to the spectrogram
const renderAudioBuffer = await spectrogram.streamAudio();
// Call renderAudioBuffer() each time there is an audio buffer to render, returns a
// promise
// Calling renderAudioBuffer() after a call to stop() is an error
// Stop recording from mic or playing audio file
await spectrogram.stop();
// Add event listener to handle state changes
spectrogram.addStateChangeEventListener((state) => {
// state can be one of 'stopped', 'playing-mic', 'playing-file', or
// 'playing-custom'
});
Metadata
Metadata
Assignees
Labels
No labels