audiojs / audio

Class for high-level audio manipulations [NOT MAINTAINED]
MIT License
240 stars 9 forks source link

Saved as [object ArrayBuffer] #64

Open haylinmoore opened 5 years ago

haylinmoore commented 5 years ago

My code is simply

const Audio = require('audio');

Audio.load('./test.mp3', (err, audio) => {
    //repeat slowed down fragment
    //audio.remove(3, 4.1)

    audio.save('edited-record.mp3')
})

and it causes the edited-record.mp3 to be just a text file with [object ArrayBuffer] as the contents. Node version is v10.15.3 on windows 10

redraskal commented 5 years ago

I've had little success with mp3 files on Windows at least and end up with the same result as you.

In case you're still wondering on how to fix this issue, I would first only load wav files and convert the mp3 files to wav beforehand. You'll want to save them as wav files since loading them as mp3's will result in really messed up files that are slowed down in speed. I found my answer from looking at the save function in the code and from the answer on this Stack Overflow page: https://stackoverflow.com/questions/46623517/write-a-wav-file-in-node-js-from-an-audiobuffer.

const Audio = require('audio')
const toWav = require('audiobuffer-to-wav')
const fs = require('fs')

Audio.load('./test.wav').then(audio => {
  audio.normalize()

  let buffer = audio.read({
    format: 'audiobuffer'
  })
  let wav = toWav(buffer)

  fs.appendFileSync('test2.wav', new Buffer(wav))
})

Hopefully this helps you and anyone else experiencing this problem!