chaimu
v1.1.0
Published
✨ Chaimu is an audio player that synchronizes audio with video
Readme
Chaimu is an audio player that synchronizes audio with video.
Usage
import Chaimu from "chaimu";
const videoEl = document.querySelector("video");
const chaimu = new Chaimu({
url: "https://s3.toil.cc/vot/translated.mp3",
video: videoEl,
});
await chaimu.init();This links the external audio to the video. Playback, seeking, and speed changes are synchronized from the video element.
When the browser supports the Web Audio API, Chaimu selects ChaimuPlayer; otherwise, it falls back to AudioPlayer. To always use AudioPlayer, set preferAudio:
const chaimu = new Chaimu({
url: "https://s3.toil.cc/vot/translated.mp3",
video: videoEl,
preferAudio: true,
});
await chaimu.init();The initial url is optional. You can initialize Chaimu first and assign a source later:
const chaimu = new Chaimu({ video: videoEl });
await chaimu.init();
chaimu.player.src = "https://s3.toil.cc/vot/translated.mp3";Use replaceVideo() when switching video elements. It keeps the current player, audio source, volume, and AudioContext:
await chaimu.replaceVideo(nextVideoEl);Call destroy() when Chaimu is no longer needed. Destruction is permanent for that instance:
await chaimu.destroy();Demo
Run the demo page against the current source checkout:
bun run demoThen open http://127.0.0.1:4174.
Install
Installation via Bun:
bun add chaimuInstallation via NPM:
npm install chaimuBuild
To build, you must have:
Don't forget to install the dependencies:
bun installRun the build:
bun run build:bun