Coder Social home page Coder Social logo

node-audio-slicer's Introduction

node-audio-slicer

Read, slice, and write back audio files to disk (supported formats: .wav and .mp3). Used e.g. for streaming service to prepare audio chunks for greedy clients.

Installation

npm install:

$ npm install --save node-audio-slicer

This package relies on node-lame for mp3 encoding. Check the repository for requirements (no windows + lame installed at the moment).

Supported Formats

Slice [.wav] to [.wav or .mp3]

Examples

Slice wav file into .mp3 chunks

load demo.wav, slice it into mp3 chunks saved in a myAudioFile directory created beside the myAudioFile.wav file.

const Slicer = require("node-audio-slicer").Slicer;
let slicer = new Slicer({compress:true});
slicer.slice('myAudioFile.wav', (chunkList) => {
    console.log('done', chunkList);
});

node-audio-slicer's People

Contributors

dependabot[bot] avatar pyrapple avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

monz111 top-kat

node-audio-slicer's Issues

wav chunks miss headers (Error: Header chunk size does not match file size)

Hi, I noticed that generated wav "slices" doesn't have a valid wav header.

For example, a wav reader lib has thrown me that error: Header chunk size does not match file size.

Is there a reason why the chunk are outputted as raw PCM data (without wav header) ?

I have created a merge request to fix this: #2

Here options.generateChunksWavHeader can be passed to unable this behavior and it is true by default.

Great lib by the way :) Thanks!

Excited when I saw this, but the tests come back as failures

Anyone able to get this repo back in shape. Buy you a beer!

$ yarn test
yarn run v1.6.0
$ ./node_modules/.bin/mocha


  Reader
TypeError: callback is not a function
    at Reader.loadBuffer (/Users/seanshadmand/Downloads/slicer/dist/Slicer.js:215:9)
    at Context.assertions (/Users/seanshadmand/Downloads/slicer/test/tests.js:28:19)
    at callFn (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runnable.js:348:21)
    at Test.Runnable.run (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runnable.js:340:7)
    at Runner.runTest (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:443:10)
    at /Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:549:12
    at next (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:361:14)
    at /Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:371:7
    at next (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:295:14)
    at Immediate.<anonymous> (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:339:5)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
    1) Read .wav file

  Slicer
    Slice .wav file to mp3
      2) should slice wav into mp3 chunks
    Slice .wav file to wav
      3) should slice wav into wav chunks
    Slice 4ch .wav + auto detect
{ Error: ENOENT: no such file or directory, open './test/example4ch.wav'
    at Object.fs.openSync (fs.js:646:18)
    at Object.fs.readFileSync (fs.js:551:33)
    at Reader.loadBuffer (/Users/seanshadmand/Downloads/slicer/dist/Slicer.js:214:25)
    at Slicer.slice (/Users/seanshadmand/Downloads/slicer/dist/Slicer.js:43:19)
    at Context.it (/Users/seanshadmand/Downloads/slicer/test/tests.js:75:14)
    at callFnAsync (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runnable.js:371:21)
    at Test.Runnable.run (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runnable.js:318:7)
    at Runner.runTest (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:443:10)
    at /Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:549:12
    at next (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:361:14)
    at /Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:371:7
    at next (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:295:14)
    at Immediate.<anonymous> (/Users/seanshadmand/Downloads/slicer/node_modules/mocha/lib/runner.js:339:5)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: './test/example4ch.wav' }
      4) should slice wav into wav chunks


  0 passing (6s)
  4 failing

  1) Reader Read .wav file:
     TypeError: Cannot read property 'then' of undefined
      at Context.assertions (test/tests.js:29:7)

  2) Slicer Slice .wav file to mp3 should slice wav into mp3 chunks:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  

  3) Slicer Slice .wav file to wav should slice wav into wav chunks:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  

  4) Slicer Slice 4ch .wav + auto detect should slice wav into wav chunks:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
  



error Command failed with exit code 4.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.