audiojs / audio

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

.load is not a function #41

Closed phil-andrews closed 6 years ago

phil-andrews commented 6 years ago
const audio = require('audio')

const newAudio = new audio()
newAudio.load('https://s3.amazonaws.com/philandrews/hardwell.mp3').then(audio => { 
    console.log(audio)
}, error => {
    console.log(error)
})

Error: newAudio.load is not a function

What am I missing here?

natesilva commented 6 years ago

The published module seems to be extremely outdated, and is just a single ~100 line file.

Could the maintainers please publish what’s in Git? This looks like a great project, and I’d love to try it out.

dy commented 6 years ago

@natesilva I am working hard on making MVP before release, I'll announce & publish once ready, for now please stay tuned and use github repo as a dependency - highly experimental and unstable!

daniamurad commented 6 years ago

I am also having the same issue and not sure how to work around with it. I want to use the .slice function

dy commented 6 years ago

@daniamurad @phil-andrews use

let Audio = require('audio')
Audio.load('https://s3.amazonaws.com/philandrews/hardwell.mp3').then(audio => {
audio.trim().save()
})
daniamurad commented 6 years ago

@dfcreative I just tried and it says: Audio.load is not a function I used npm install audio .. but I dont know if it downloaded the completed library or not ..

dy commented 6 years ago

@daniamurad please install npm i audiojs/audio for now. It is not published in npm yet. Please also note that it is highly experimental now, release is coming soon.

daniamurad commented 6 years ago

I got this now .. speaker package was not found. Using audio-sink instead.

And error: UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: this.buffer.fill is not a function

dy commented 6 years ago

@daniamurad simple wav loading/slicing test should work now:

Audio.load('./file.wav').then(audio => {
  audio.slice(.5, 1)
  audio.save('chunk.wav')
})

Unfortunately it cannot handle mp3 for now, figuring out the reason.

daniamurad commented 6 years ago

Thanks alot it is working for slicing the audio file. However if I try to slice same audio file two times for two different duration and save as different names, I get the following error on the second one: (node:22448) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'getChannelData' of undefined Or sometimes: (node:1244) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Use audio.read(...) instead of audio.getChannelData(...)

dy commented 6 years ago

@daniamurad ok, this should work with https://github.com/audiojs/audio/commit/d685ad8c80c62c3d8707be4756e96201caebfc4a

Audio.load(localWav).then(a => a.slice(0, 1).save('x.wav'))
Audio.load(localWav, (err, audio) => {
  audio.slice(1, 2).save('y.wav')
})

Also I modified slice method to make it immutable (return a new fragment), so you can also do

Audio.load(localWav, (err, a) => {
  a.slice(1, 2).save('x.wav')
  a.slice(2, 3).save('y.wav')
})
daniamurad commented 6 years ago

Thanks alot @dfcreative its working great !

dy commented 6 years ago

@daniamurad my pleasure, glad it helped!