Webrtc audio recording in python

I am trying to record audio, but the files stored on the server are only 10KB or less.

The file is saved on the server and has the correct name, but is 10 KB or less.

In the browser, the audio file can be viewed and played as expected.

Server side ping code :

def save_file(file, filename, path=''):
  ''' Little helper to save a file
  '''
  fd = open('%s/%s' % ('/root/ws911/media/', str(path) + str(filename)), 'wb')
  #for chunk in file.chunks():
  # fd.write(chunk)
  fd.write(file)
  fd.close()

      

Snippets of JavaScript code :

// PostBlob method uses XHR2 and FormData to submit 
// recorded blob to the PHP server
function PostBlob(blob, fileType, fileName) {
    // FormData
    var formData = new FormData();
    formData.append(fileType + '-filename', fileName);
    formData.append(fileType + '-blob', blob);

    // POST the Blob using XHR2
    xhr('xxxxxxxxxxxxxx/get_json/', formData, function(fileURL) {

    });
}

var container = document.getElementById('container');

// var legalBufferValues = [256, 512, 1024, 2048, 4096, 8192, 16384];
// sample-rates in at least the range 22050 to 96000.
recordAudio = RecordRTC(stream, {
    //bufferSize: 16384,
    //sampleRate: 45000,
    onAudioProcessStarted: function() {
        if (!isFirefox) {
            recordVideo.startRecording();
        }
    }
});

recordAudio.startRecording();

stop.disabled = false;
},

function(error) {
    alert(JSON.stringify(error, null, '\t'));
});
};

 var fileName;
 stop.onclick = function() {
     record.disabled = false;
     stop.disabled = true;

     preview.src = '';

     fileName = Math.round(Math.random() * 99999999) + 99999999;

     recordAudio.stopRecording(function(url) {
         preview.src = url;
         PostBlob(recordAudio.getBlob(), 'video', fileName + '.webm');
     });

     function xhr(url, data, callback) {
         var request = new XMLHttpRequest();
         request.onreadystatechange = function() {
             if (request.readyState == 4 && request.status == 200) {
                 callback(request.responseText);
             }
         };

      

+3


source to share





All Articles