https://github.com/shinich39/beat-js
A library for analyze audio data using javascript.
https://github.com/shinich39/beat-js
beat-detection
Last synced: about 2 months ago
JSON representation
A library for analyze audio data using javascript.
- Host: GitHub
- URL: https://github.com/shinich39/beat-js
- Owner: shinich39
- License: mit
- Created: 2024-12-08T04:36:01.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-09T16:06:46.000Z (6 months ago)
- Last Synced: 2024-12-21T00:19:35.127Z (5 months ago)
- Topics: beat-detection
- Language: JavaScript
- Homepage:
- Size: 1.69 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# beat-js
A library for analyze audio data using javascript.
## Demo
[Testing with visualization](https://shinich39.github.io/beat-js/)
## Usage
```js
import { Beat } from "beat-js";
import fs from "node:fs";
import path from "node:path";const buffer = fs.readFileSync(path.join("./test/test.wav"));
const b = new Beat(buffer);const channel = 0;
const step = b.sampleRate * 0.2;
const peaks = b.getPeaks(channel, step);
console.log(peaks);
// [
// 6450, 17431, 23049, 34151, 40030, 50550,
// 56116, 67149, 70580, 79971, 89169, 100216,
// 111249, 122182, 128230, 138750, 144316, 155349,
// ...
// ]const fftSize = 1024;
const treshold = 1.2;
const beats = b.getBeats(channel, fftSize, treshold);
console.log(beats);
// [
// 512, 1024, 1536, 2048, 6144, 6656, 7168, 7680,
// 8192, 8704, 11776, 12288, 12800, 13312, 13824, 14336,
// 17408, 17920, 18432, 18944, 19456, 19968, 24064, 24576,
// ...
// ]const time = b.getTime(peaks[0]);
console.log(time);
// 0.14625850340136054const tempos = b.getTempos(peaks);
console.log(tempos);
// [
// 120, 160, 96, 137, 148, 107, 144, 121, 119, 159, 118,
// 161, 173, 128, 135, 164, 132, 103, 92, 109, 174, 156,
// ...
// ]const temp = tempos[0];
console.log(temp);
// 120
```## References
- [nodejs](https://nodejs.org/)
- [tsconfig](https://www.typescriptlang.org/tsconfig/)
- [beats-audio-api](https://github.com/JMPerez/beats-audio-api/)
- [beat-detection-using-web-audio](http://joesul.li/van/beat-detection-using-web-audio/)## Acknowledgements
- [esbuild](https://esbuild.github.io/)
- [prettier](https://prettier.io/)
- [eslint](https://eslint.org/)
- [tsx](https://tsx.is/)
- [wav.js](https://github.com/ffdead/wav.js/)
- [fft.js](https://github.com/indutny/fft.js)