Skip to content

Instantly share code, notes, and snippets.

@diversen
Created October 20, 2017 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diversen/d85f77638221455adbd4235c74e8d4c9 to your computer and use it in GitHub Desktop.
Save diversen/d85f77638221455adbd4235c74e8d4c9 to your computer and use it in GitHub Desktop.
var samplePromise = require('get-audio-sample-promise');
var rand = require('random-float');
var waveSurfer = require('wavesurfer.js')
// let [foo, bar] = await Promise.all([getFoo(), getBar()]);
// let audiobuf = await samplePromise(ctx, 'raven.mp3');
function randomDoubleFromInterval(min, max){
return Math.random()*(max-min);
}
let promise = samplePromise(ctx, 'raven.mp3').then(function(instrument){
// console.log('loaded');
// Promise success. You have a simple audioBufferInstrument
// Which you can get and connect
var audioBuf = instrument.get();
console.log(audioBuf);
var length = audioBuf.buffer.duration;
console.log(length);
var random = rand(0, length);
console.log(random);
//audioBuf.connect(ctx.destination);
// audioBuf.start(2);
}).catch(function(err){
console.log(err)
});
var wavesurfer = WaveSurfer.create({
container: '#waveform'
});
wavesurfer.load('http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3');
wavesurfer.on('ready', function () {
// wavesurfer.play();
console.log('ok');
});
wavesurfer.on('audioprocess', function (e) {
// console.log(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment