Hello im trying to make an app that records audio when you press a button, and then send it to nuance for ASR.
So far i am just trying to upload it to my own local host for testing how ever i cant seem to get the file uploaded.
I am using an android 4.4.2 tablet for testing.
File has been recorded and can be found on the tablet when connected to the computer, but not in an folder for the app (No clue if thats important or not)
I hope someone can help me figure this out
Controller:
.controller('MainCtrl', function ($scope, $cordovaFileTransfer) {
var src = "myrecording.amr";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(Media);
}
// play audio
$scope.PlayAudio = function () {
console.log("try to start music");
// Play the audio file at url
var my_media = new Media(src,
// success callback
function () {
console.log("playAudio():Audio Success");
},
// error callback
function (err) {
console.log("playAudio():Audio Error: " + err);
}
);
// Play audio
my_media.play();
}
// Record audio
//
$scope.RecordAudio = function () {
console.log("Records");
var mediaRec = new Media(src,
// success callback
function () {
console.log("recordAudio():Audio Success");
},
// error callback
function (err) {
console.log("recordAudio():Audio Error: " + JSON.stringify(err.code));
}
);
// Record audio
mediaRec.startRecord();
// Stop recording after 10 seconds
setTimeout(function () {
mediaRec.stopRecord();
console.log("Stop recording");
}, 10000);
}
$scope.SendAudio = function () {
var options = {
fileKey: "fileToUpload",
fileName: "myrecording.amr",
chunkedMode: false,
mimeType: "audio/AMR",
httpMethod: "post"
};
$cordovaFileTransfer.upload("http://172.30.1.206/test/asr/post.php", src, options).then(function (result) {
console.log("SUCCESS: " + JSON.stringify(result));
}, function (err) {
console.log("ERROR: " + JSON.stringify(err));
}, function (progress) {
// constant progress updates
});
}
})
ERROR:
{"code":1,"source":"myrecording.amr","target":"http://172.30.1.206/test/asr/post.php","http_status":200,"body":null,"exception":"/myrecording.amr: open failed: ENOENT (No such file or directory)"}
PHP:
<?php
//header('content-type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
$target_dir = "sound/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$response = array();
$response['success'] = 1;
// Check if image file is a actual image or fake image
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$response['success'] = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$response['success'] = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$response['errorMsg'] = "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$response['successMsg'] = "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
$response['successMsg'] = "Sorry, there was an error uploading your file.";
}
}
if (isset($_GET['callback'])) {
echo $_GET['callback'] . '('.json_encode($response).')';
} else {
echo json_encode($response,JSON_PRETTY_PRINT);
}
?>