npm install @beat-parser/coreyarn add @beat-parser/coreimport { BeatParser } from '@beat-parser/core';
const parser = new BeatParser();
const result = await parser.parseBuffer(audioData);
console.log('Beats found:', result.beats.length);const parser = new BeatParser({
sampleRate: 44100,
minTempo: 80,
maxTempo: 160,
confidenceThreshold: 0.6
});- Node.js 18.0.0 or higher
- npm 8.0.0 or higher
- TypeScript 5.0+ (for TypeScript projects)
- Chrome 66+
- Firefox 60+
- Safari 13.1+
- Edge 79+
Supported formats via audio-decode library:
- WAV - Uncompressed audio
- MP3 - MPEG audio compression
- FLAC - Lossless compression
- OGG - Open source compression
- OPUS - Low-latency compression
Types are included automatically:
import { BeatParser, ParseResult, Beat } from '@beat-parser/core';
const parser: BeatParser = new BeatParser();
const result: ParseResult = await parser.parseBuffer(audioData);For non-blocking processing:
import { BeatParserWorkerClient } from '@beat-parser/core';
const client = new BeatParserWorkerClient();
const result = await client.parseBuffer(audioData, {
progressCallback: (progress) => console.log(`${progress}%`)
});
await client.terminate();// Always cleanup after processing
const parser = new BeatParser();
try {
const result = await parser.parseBuffer(audioData);
} finally {
await parser.cleanup();
}For files >30 seconds, use streaming:
const result = await parser.parseStream(audioStream, {
progressCallback: (processed) => console.log(`Processed: ${processed}`)
});try {
const result = await parser.parseFile('./music.mp3');
} catch (error) {
console.error('File not found:', error.message);
}// Check supported formats
const formats = BeatParser.getSupportedFormats();
console.log('Supported:', formats); // ['wav', 'mp3', 'flac', 'ogg', 'opus']- Use Web Workers for large files
- Enable streaming for files >2 minutes
- Always call cleanup() after processing
- Process files in batches if handling many files
If workers not supported:
try {
const client = new BeatParserWorkerClient();
} catch (error) {
// Fallback to main thread
const parser = new BeatParser();
}git clone https://github.com/username/beat-parser.git
cd beat-parser
npm install
npm run build
npm testnpm run test:quick # Quick tests
npm run test:music # Full music file tests
npm run test:all # Complete test suiteimport { BeatParser } from '@beat-parser/core';
async function processAudioFile(filePath: string) {
const parser = new BeatParser({
confidenceThreshold: 0.7
});
try {
const result = await parser.parseFile(filePath, {
targetPictureCount: 16,
selectionMethod: 'adaptive'
});
console.log(`Found ${result.beats.length} beats`);
console.log(`Tempo: ${result.tempo?.bpm} BPM`);
return result;
} finally {
await parser.cleanup();
}
}async function processMusicLibrary(files: string[]) {
const parser = new BeatParser();
const results = [];
try {
for (const file of files) {
const result = await parser.parseFile(file);
results.push(result);
}
return results;
} finally {
await parser.cleanup();
}
}For complete API documentation, see API.md.