Untitled
unknown
plain_text
7 months ago
1.2 kB
2
Indexable
Never
function createAudioFingerprint() { var audioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext; var context = new audioContext(1, 44100, 44100); var oscillator = context.createOscillator(); oscillator.type = 'triangle'; oscillator.frequency.value = 10000; var compressor = context.createDynamicsCompressor(); ['threshold', 'knee', 'ratio', 'reduction', 'attack', 'release'].forEach(function(prop) { if (compressor[prop] instanceof AudioParam) { compressor[prop].value = Math.random(); } }); oscillator.connect(compressor); compressor.connect(context.destination); oscillator.start(0); context.startRendering(); return new Promise(function(resolve, reject) { context.oncomplete = function(event) { var fingerprint = ''; for (var i = 0; i < event.renderedBuffer.length; i++) { fingerprint += String.fromCharCode(event.renderedBuffer[i]); } resolve(btoa(fingerprint)); }; }); } createAudioFingerprint().then(function(fingerprint) { console.log(fingerprint); });