I currently have a website that can record audio using Matt Diamond recorder.js + getUserMedia (web audio API). After the client has finished writing, I upload the data (in .wav) via the ajax post to the file system. Then my java server side processes data.wav in other formats. It works great.
However, I am concerned about performance / bandwidth issues with the ajax message and you want to explore the possibility of streaming data directly to java code or the file system. Does anyone have any suggestions on how to pass this client-side audio clip stream (opened with getUserMedia) to server-side Java? If that matters, we use the spring framework.
Thank.
EDIT:
Here is the requested code:
I added this to recorder.js
this.upload = function () {
var data = new FormData();
data.append('file', blob);
$j.ajax({
url : "/Your_Path/To_PHP/action/UploadAudio/",
type: 'POST',
data: data,
contentType: false,
processData: false,
success: function(data) {
alert("Success");
},
error: function() {
alert("uploadFail");
}
});
}
And in the PHP code:
if($_GET['action'] == 'UploadAudio') {
if (!file_exists('/audioArchiveDestination/subDirectory/')) {
mkdir('/audioArchiveDestination/subDirectory/', 0777, true);
}
$filePath = "/audioArchiveDestination/subDirectory/";
$filename = $_SESSION['member_id'].'_'.time();
$fileExtension = "wav";
$uploadSuccess = move_uploaded_file($_FILES['file']['tmp_name'], $filePath.$filename.".wav");
if($uploadSuccess) {
$results = json_encode(array("filename" => $filename));
echo $results;
}
}
source
share