A lightweight, modern, modular audio engine that provides playback, filters, queue management, events, and extensibility through plugins. Works in both Node.js and browser environments.
- 🎵 Unified Audio Engine: Cross-environment abstraction using Web Audio API
- 📋 Queue Management: Add, remove, shuffle, jump, and loop modes
- 🎛️ Audio Filters: Bassboost, nightcore, vaporwave, 8D rotate, pitch/speed adjustment, reverb
- 🔌 Plugin System: Extensible architecture with lifecycle hooks
- 📡 Event-Driven: Comprehensive event system for all operations
- 🌐 Multi-Source Support: Local files, remote URLs, YouTube, SoundCloud, Spotify, Lavalink
- 🛠️ Developer-Friendly: TypeScript declarations, ESM/CJS builds
npm install @students-dev/audify-js<!DOCTYPE html>
<html>
<head>
<title>audify-js Demo</title>
</head>
<body>
<script type="module">
import { AudioEngine } from '@students-dev/audify-js';
const engine = new AudioEngine();
engine.on('ready', () => {
console.log('Audio engine ready!');
engine.add('https://example.com/audio.mp3');
engine.play();
});
engine.on('trackStart', (track) => {
console.log('Now playing:', track.title);
});
</script>
</body>
</html>import { AudioEngine } from '@students-dev/audify-js';
const engine = new AudioEngine();
engine.on('ready', () => {
engine.add('/path/to/audio.mp3');
engine.play();
});The main class that orchestrates all audio functionality.
const engine = new AudioEngine(options);// Initialize Spotify provider
engine.initSpotify({
clientId: 'your_client_id',
clientSecret: 'your_client_secret'
});
// Search tracks
const results = await engine.searchSpotifyTracks('query', { token: 'access_token' });
// Load track
const track = await engine.loadSpotifyTrack('track_id', { token: 'access_token' });// Connect to Lavalink server
await engine.connectLavalink({
host: 'localhost',
port: 2333,
password: 'youshallnotpass'
});
// Load track from Lavalink
const track = await engine.loadLavalinkTrack('ytsearch:query');
// Get Lavalink player for Discord bots
const player = engine.getLavalinkPlayer('guild_id', 'channel_id');play(track?): Play a track or resume current playbackpause(): Pause playbackstop(): Stop playbackseek(time): Seek to specific time (seconds)setVolume(volume): Set volume (0-1)
add(tracks): Add track(s) to queueremove(identifier): Remove track by index or IDnext(): Skip to next trackprevious(): Go to previous trackshuffle(): Shuffle the queueclear(): Clear the queuejump(index): Jump to track at index
applyFilter(type, options): Apply audio filterremoveFilter(type): Remove audio filter
setLoopMode(mode): Set loop mode (LOOP_MODES.OFF,LOOP_MODES.TRACK,LOOP_MODES.QUEUE)
getState(): Get current engine state
ready: Engine initializedplay: Playback startedpause: Playback pausedstop: Playback stoppederror: Error occurredqueueEmpty: Queue became emptytrackStart: Track started playingtrackEnd: Track endedfilterApplied: Filter appliedtrackAdd: Track added to queuetrackRemove: Track removed from queueshuffle: Queue shuffledclear: Queue cleared
Manages the audio playback queue.
const queue = engine.queue;
// Add tracks
queue.add('track.mp3');
queue.add(['track1.mp3', 'track2.mp3']);
// Navigate
queue.next();
queue.previous();
queue.jump(5);
// Modify
queue.shuffle();
queue.clear();Represents an audio track.
import { Track } from '@students-dev/audify-js';
const track = new Track('https://example.com/audio.mp3', {
title: 'My Song',
artist: 'Artist Name',
duration: 180
});Apply audio effects.
// Bass boost
engine.applyFilter('bassboost', { gain: 1.5 });
// Nightcore
engine.applyFilter('nightcore', { rate: 1.2 });
// 8D Audio
engine.applyFilter('8d');
// Remove filter
engine.removeFilter('bassboost');Available filters:
bassboost: Boost low frequenciesnightcore: Speed up and pitch upvaporwave: Slow down and pitch down8d: 8D audio rotation effectpitch: Adjust pitchspeed: Adjust playback speedreverb: Add reverb effect
Extend functionality with plugins.
import { Plugin } from '@students-dev/audify-js';
class MyPlugin extends Plugin {
constructor() {
super('my-plugin', '1.0.0');
}
onLoad(engine) {
console.log('Plugin loaded!');
}
beforePlay(track) {
console.log('About to play:', track.title);
}
}
// Load plugin
const plugin = new MyPlugin();
engine.pluginManager.load(plugin);
engine.pluginManager.enable('my-plugin');Fetch metadata from different sources.
import { YouTubeProvider, SoundCloudProvider, LocalProvider, SpotifyProvider, LavalinkProvider } from '@students-dev/audify-js';
// YouTube
const ytInfo = await YouTubeProvider.getInfo('https://youtube.com/watch?v=VIDEO_ID');
// SoundCloud
const scInfo = await SoundCloudProvider.getInfo('https://soundcloud.com/artist/track');
// Local file (Node.js only)
const localInfo = await LocalProvider.getInfo('/path/to/file.mp3');
// Spotify (requires access token)
const spotify = new SpotifyProvider({ clientId: 'your_client_id' });
spotify.setAccessToken('access_token');
const trackInfo = await spotify.getTrack('track_id');
// Lavalink (requires Lavalink server)
const lavalink = new LavalinkProvider({ host: 'localhost', port: 2333, password: 'password' });
await lavalink.connect();
const lavalinkTrack = await lavalink.loadTrack('ytsearch:query');Utility functions for common tasks.
import { TimeUtils, MetadataUtils, ProbeUtils } from '@students-dev/audify-js';
// Time formatting
TimeUtils.format(125); // "02:05"
// Metadata extraction
const metadata = MetadataUtils.extract('https://example.com/song.mp3');
// Audio probing
const probe = await ProbeUtils.probe(audioBuffer);The examples/ directory contains comprehensive examples demonstrating various features:
browser-example.html- Interactive browser demo with UI controlsnodejs-example.js- Node.js usage with event handlingqueue-example.js- Queue management operationsplugin-examples.js- Custom plugin implementationsspotify-example.js- Spotify API integrationlavalink-example.js- Lavalink server integration
import { AudioEngine } from '@students-dev/audify-js';
const engine = new AudioEngine();
engine.on('ready', async () => {
// Add tracks
engine.add([
'track1.mp3',
'track2.mp3',
'https://example.com/track3.mp3'
]);
// Start playing
await engine.play();
// Apply filter
engine.applyFilter('bassboost');
});
// Handle events
engine.on('trackStart', (track) => {
console.log(`Playing: ${track.title}`);
});
engine.on('error', (error) => {
console.error('Playback error:', error);
});// Add multiple tracks
engine.add([
{ url: 'song1.mp3', title: 'Song One' },
{ url: 'song2.mp3', title: 'Song Two' }
]);
// Navigation
engine.next();
engine.previous();
engine.jump(2); // Jump to track at index 2
// Modify queue
engine.shuffle();
engine.clear();
// Remove specific track
engine.remove(0); // Remove by index
engine.remove('track-id'); // Remove by ID// Bass boost
engine.applyFilter('bassboost', { gain: 1.5 });
// Nightcore effect
engine.applyFilter('nightcore', { rate: 1.2 });
// Vaporwave effect
engine.applyFilter('vaporwave', { rate: 0.8 });
// 8D Audio
engine.applyFilter('8d');
// Pitch adjustment
engine.applyFilter('pitch', { pitch: 1.1 });
// Speed adjustment
engine.applyFilter('speed', { speed: 1.25 });
// Reverb
engine.applyFilter('reverb', { preset: 'hall' });
// Remove filter
engine.removeFilter('bassboost');import { Plugin } from '@students-dev/audify-js';
class LoggerPlugin extends Plugin {
constructor() {
super('logger');
}
beforePlay(track) {
console.log(`[Logger] Starting playback: ${track.title}`);
}
afterPlay(track) {
console.log(`[Logger] Finished playback: ${track.title}`);
}
trackEnd(track) {
console.log(`[Logger] Track ended: ${track.title}`);
}
}
// Register plugin
const loggerPlugin = new LoggerPlugin();
engine.pluginManager.load(loggerPlugin);
engine.pluginManager.enable('logger');<!DOCTYPE html>
<html>
<head>
<title>audify-js Demo</title>
</head>
<body>
<button id="playBtn">Play</button>
<button id="bassBtn">Bass Boost</button>
<script type="module">
import { AudioEngine } from '@students-dev/audify-js';
const engine = new AudioEngine();
engine.on('ready', () => {
engine.add('audio.mp3');
document.getElementById('playBtn').onclick = () => engine.play();
document.getElementById('bassBtn').onclick = () =>
engine.applyFilter('bassboost');
});
</script>
</body>
</html># Browser example
# Open examples/browser-example.html in your browser
# Node.js examples
node examples/nodejs-example.js
node examples/queue-example.js- Chrome 14+
- Firefox 25+
- Safari 6+
- Edge 12+
- Node.js 14+
For audio playback in Node.js, additional setup may be required for actual audio output.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see the LICENSE file for details.
Ensure you're handling user interaction requirements for Web Audio API:
// Resume AudioContext on user interaction
document.addEventListener('click', () => {
if (engine.audioContext.state === 'suspended') {
engine.audioContext.resume();
}
});When loading audio from different domains, ensure proper CORS headers are set on the server.
For actual audio playback in Node.js, you may need additional packages like speaker or node-speaker.
Some filters require AudioWorklet support in modern browsers. Check browser compatibility.
- Added Spotify integration with client-side API support
- Added Lavalink integration for server-based audio streaming
- Updated dependencies for better performance and security
- Enhanced TypeScript type definitions
- Added comprehensive examples for new integrations
- Initial release
- Core audio engine
- Queue management
- Audio filters
- Plugin system
- Event system
- Provider abstractions
- Utility functions