Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to render array buffer binary audio js

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
var delayTime = 0;
var init = 0;
var audioStack = [];
var nextTime = 0;

client.on('stream', function(stream, meta){
    stream.on('data', function(data) {
        context.decodeAudioData(data, function(buffer) {
            audioStack.push(buffer);
            if ((init!=0) || (audioStack.length > 10)) { // make sure we put at least 10 chunks in the buffer before starting
                init++;
                scheduleBuffers();
            }
        }, function(err) {
            console.log("err(decodeAudioData): "+err);
        });
    });
});

function scheduleBuffers() {
    while ( audioStack.length) {
        var buffer = audioStack.shift();
        var source    = context.createBufferSource();
        source.buffer = buffer;
        source.connect(context.destination);
        if (nextTime == 0)
            nextTime = context.currentTime + 0.05;  /// add 50ms latency to work well across systems - tune this if you like
        source.start(nextTime);
        nextTime+=source.buffer.duration; // Make the next buffer wait the length of the last buffer before being played
    };
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: extract image in p5.js 
Javascript :: pass a callback funcion into an async function node js 
Javascript :: jquery on mouseover and mouseout 
Javascript :: .loads with whole json file 
Javascript :: p5.js sketch 
Javascript :: how to add another model into type of model in mongodb schema 
Javascript :: ongobd add key value to record 
Javascript :: js how to shuffle array algoritm. The Fisher-Yates algorith 
Javascript :: docker containerize node app 
Javascript :: Nyadorera 
Javascript :: infinite typing effect react 
Javascript :: javascript vuelidate identical passwords only if checkbox is ticked 
Javascript :: AngularJS Graphs & Charts - Mix of solid & dotted 
Javascript :: angularjs No alignment and missing item in a vertical menu 
Javascript :: show user profile nodejs pug 
Javascript :: Calling $http.post in batches and chaining promises 
Javascript :: How to query a button with specific text with react native testing library 
Javascript :: Difficulties handling asynchronous taks using image-picker and copying files in react-native 
Javascript :: ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AuthModule)[AuthService - AuthService - AngularFirestore - InjectionToken 
Javascript :: sending api with limited fields in express 
Javascript :: assign-only-if-property-exists-in-target-object 
Javascript :: react text editor snippet 
Javascript :: “Line Splicing in C++” 
Javascript :: phaser rotate matrix 180 
Javascript :: react native text input allow only numbers 
Javascript :: react router how to prevent navlink from two classes 
Javascript :: react antd modal with quill 
Javascript :: save to text or html file very good 
Javascript :: var oddOrEven = function(num) {}; 
Javascript :: docker healthcheck express 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =