<commit_before>function button_onclick(e) {
    // $('#status').removeClass('idling playing')
    // $('#status').addClass('talking')

    jQuery.ajax('connect.php', {
        'data': {
            'username': $('#username').val()
        },
        'method': 'POST',
        'error': function(jqXHR, textStatus, errorThrown) {
            $('#status').removeClass('idling playing talking')
            $('#status').addClass('gray')
            alert(textStatus + "\n" + errorThrown + "\n" + jqXHR.responseText)
        },
    }).done(function(data) {
        $('#status').removeClass('gray')
        $('#status').addClass('idling')
        console.log('active users:')
        console.log(data)
    })
}

var playbackCtx,
    dontAskForMore = false

function init_voip()
{
    var session = {
audio: true,
       video: false
    }
    var recordRTC = null
    navigator.webkitGetUserMedia(session, initializeRecorder, onError)

    var audioContext = window.AudioContext
    playbackCtx = new AudioContext()

    setInterval(function() {
        if(dontAskForMore) return
        if(getState() != 'silence') return
        var request = new XMLHttpRequest();
        request.open('GET', 'listen.php', true);
        request.responseType = 'arraybuffer';

        // Decode asynchronously
        request.onload = function() {
            if(request.response.byteLength == 0) return
            console.log('received ' + request.response.byteLength)
            var source = playbackCtx.createBufferSource()
            source.onended = function() {
                dontAskForMore = false
            }
            //buffer = playbackCtx.createBuffer(1, request.response.byteLength, playbackCtx.sampleRate);
            buffer = playbackCtx.createBuffer(1, request.response.byteLength, playbackCtx.sampleRate);
            if(request.response.byteLength % 4 != 0) {
                var len = Math.floor(request.response.byteLength / 4) * 4
                if(len % 4 != 0) alert('wtf')
                request.response = request.response.slice(0, len)
            }
            var f32 = new Float32Array(request.response)
            buffer.copyToChannel(f32, 0)
            source.buffer = buffer
            source.connect(playbackCtx.destination)
            source.loop = false
            source.connect(playbackCtx.destination)
            source.start()
            dontAskForMore = true
        }
        request.onerror = function(e) {
            alert(e.target.status + "\n" + e.target.responseText)
        }
        request.send();
    }, 100)
}

function initializeRecorder(stream) {
    var audioContext = window.AudioContext
    var context = new audioContext()
    var audioInput = context.createMediaStreamSource(stream)
    var bufferSize = 2048
    // create a javascript node
    var recorder = context.createScriptProcessor(bufferSize, 1, 1)
    // specify the processing function
    recorder.onaudioprocess = recorderProcess<commit_msg>works now<commit_after>function button_onclick(e) {
    // $('#status').removeClass('idling playing')
    // $('#status').addClass('talking')

    jQuery.ajax('connect.php', {
        'data': {
            'username': $('#username').val()
        },
        'method': 'POST',
        'error': function(jqXHR, textStatus, errorThrown) {
            $('#status').removeClass('idling playing talking')
            $('#status').addClass('gray')
            alert(textStatus + "\n" + errorThrown + "\n" + jqXHR.responseText)
        },
    }).done(function(data) {
        $('#status').removeClass('gray')
        $('#status').addClass('idling')
        console.log('active users:')
        console.log(data)
    })
}

var playbackCtx,
    dontAskForMore = false

function init_voip()
{
    var session = {
audio: true,
       video: false
    }
    var recordRTC = null
    navigator.webkitGetUserMedia(session, initializeRecorder, onError)

    var audioContext = window.AudioContext
    playbackCtx = new AudioContext()

    setInterval(function() {
        if(dontAskForMore) return
        if(getState() != 'silence') return
        var request = new XMLHttpRequest();
        request.open('GET', 'listen.php', true);
        request.responseType = 'arraybuffer';

        // Decode asynchronously
        request.onload = function() {
            if(request.response.byteLength == 0) return
            console.log('received ' + request.response.byteLength)
            var source = playbackCtx.createBufferSource()
            source.onended = function() {
                dontAskForMore = false
            }
            //buffer = playbackCtx.createBuffer(1, request.response.byteLength, playbackCtx.sampleRate);
            buffer = playbackCtx.createBuffer(1, request.response.byteLength, playbackCtx.sampleRate);
            var len = Math.floor(request.response.byteLength / 4)
            var f32 = new Float32Array(request.response, 0, len)
            buffer.copyToChannel(f32, 0)
            source.buffer = buffer
            source.connect(playbackCtx.destination)
            source.loop = false
            source.connect(playbackCtx.destination)
            source.start()
            dontAskForMore = true
        }
        request.onerror = function(e) {
            alert(e.target.status + "\n" + e.target.responseText)
        }
        request.send();
    }, 100)
}

function initializeRecorder(stream) {
    var audioContext = window.AudioContext
    var context = new audioContext()
    var audioInput = context.createMediaStreamSource(stream)
    var bufferSize = 2048
    // create a javascript node
    var recorder = context.createScriptProcessor(bufferSize, 1, 1)
    // specify the processing function
    recorder.onaudioprocess = recorderProcess
{'fraction_non_alphanumeric': 0.12371493291514202, 'fraction_numerical': 0.008189580066213627, 'mean_word_length': 2.348891481913652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2292367', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1563, 'n_words': 311}