mohayonao / ciseaux

JavaScript utility to chop an audio buffer
http://mohayonao.github.io/ciseaux/
82 stars 9 forks source link

Buffer and ArrayBuffer problem #29

Open ayapi opened 6 years ago

ayapi commented 6 years ago

on nodejs, couldn't write wav file correctly. (I have not try on Browser)

node v9.11.1 Arch Linux x86_64 Kernel Release 4.12.0.2-ARCH

npm test
  135 passing (129ms)
  1 failing

  1) node-interface render(tape: JSON, numberOfChannels: number = 0): Promise<Buffer> works:

      AssertionError [ERR_ASSERTION]:   # test/node-interface.js:161

  assert(buffer instanceof Buffer)
         |      |          |      
         |      false      #function#
         ArrayBuffer{}            

      + expected - actual

      -false
      +true

      at Decorator._callFunc (node_modules/empower-core/lib/decorator.js:110:20)
      at Decorator.concreteAssert (node_modules/empower-core/lib/decorator.js:103:17)
      at decoratedAssert (node_modules/empower-core/lib/decorate.js:49:30)
      at powerAssert (node_modules/empower-core/index.js:63:32)
      at node-interface.js:161:9
      at <anonymous>

I don't know the details, but I found the workaround.

workaround

it works fine with arraybuffer-to-buffer

const { promisify } = require('util');
const fs = require('fs');
const writeFilePromise = promisify(fs.writeFile);
const arrayBufferToBuffer = require('arraybuffer-to-buffer');

const Ciseaux = require("ciseaux/node");

(async () => {
  const src = await Ciseaux.from('/path/to/audio.wav')
  const arrayBuffer = await Ciseaux.concat([ src.slice(10, 1), src.slice(2, 3) ]).loop(4).render()
  await writeFilePromise("/path/to/ciseauxed.wav", arrayBufferToBuffer(arrayBuffer))
})()

@mohayonao さん、すばらしぃモジュールをぃっもぁりがとござぃます

augustnmonteiro commented 5 years ago

I have tried to use this workaround, but it doesn't work, all the files are being saved with 44 bytes. and nothing plays