Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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