I'm trying to record audio but the files as they are stored on server are only 10kb or less.
The file is being saved to server, and has the correct name, but is 10 kb or less.
In the browser the audio file is capable of being reviewed and plays as expected.
Server side python 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()
JavaScript code excerpts:
// 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);
}
};