Skip to content

Commit

Permalink
Little bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ms@Nicro authored and ms@Nicro committed Jan 13, 2024
1 parent 87c50a0 commit dff936f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
14 changes: 12 additions & 2 deletions src/main/java/model/service/exercise/SpeechRecognition.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ else if (speechRecognitionResult.getReason() == ResultReason.NoMatch){
if (cancellation.getReason() == CancellationReason.Error) {
System.out.println("CANCELED: ErrorCode=" + cancellation.getErrorCode());
System.out.println("CANCELED: ErrorDetails=" + cancellation.getErrorDetails());
System.out.println("CANCELED: Did you set the speech resource key and region values?");
}
}

speechRecognizer.close();
return result;

}

public String generateFile(InputStream inputAudio) throws IOException {
Expand All @@ -75,7 +76,7 @@ public String generateFile(InputStream inputAudio) throws IOException {
//Controlla che non esista già un file
try {
// Use the delete method from Files class to delete the file
Files.delete(Paths.get(path));
Files.delete(outputPath);
} catch (FileNotFoundException e){
System.err.println("File not found");
} catch (IOException e) {
Expand Down Expand Up @@ -109,6 +110,15 @@ public String generateFile(InputStream inputAudio) throws IOException {
e.printStackTrace();
}

try {
// Use the delete method from Files class to delete the file
Files.delete(Path.of(tempFile.toURI()));
} catch (FileNotFoundException e){
System.err.println("File not found");
} catch (IOException e) {
System.err.println("Error deleting the file: " + e.getMessage());
}

return path;
}

Expand Down
50 changes: 22 additions & 28 deletions src/main/webapp/JS/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,6 @@ function loadRightText(initialState){
// Salvataggio dell'esecuzione
//----------------------------------------------------------------------------------------------------------------------

//Read Text e Read Images
function saveReadExercise(execution){
saveAudioExecution(execution);
}

//Images to text
function saveITT(n) {
let execution = {};
Expand Down Expand Up @@ -518,43 +513,42 @@ function saveCT(n){
function saveExecution(execution){
$("#buttonDiv > button").prop("disabled", true).text("Esercizio Inviato!");


$.ajax({
type: "POST",
$.post({
url: "../exerciseLogger",
data: JSON.stringify(execution),
contentType: "application/json",
error: function (error) {
console.error("Errore durante l'invio dell'esecuzione alla servlet:", error);
redirect("500.html")
}
});
setTimeout(()=> {
contentType: "application/json"
})
.done(function(response) {
redirect("home");
}, 3000);
})
.fail(function(error) {
console.error("Error during execution submission to the servlet:", error);
redirect("500.html");
});

}

function saveAudioExecution(execution){
//Read Text e Read Images
function saveReadExercise(execution){
if(execution != null){

let formData = new FormData();
formData.append("audioFile", execution);

$.ajax({
type: "POST",
$.post({
url: "../exerciseLogger",
data: formData,
processData: false,
contentType: false,
cache: false,
success: function (){
redirect("home");
},
error: function(xhr, status, error) {
console.error("Errore durante l'invio dell'audio alla servlet:", error);
console.log(xhr.responseText);
redirect("500.html");
}
cache: false
})
.done(function() {
redirect("home");
})
.fail(function(xhr, status, error) {
console.error("Errore durante l'invio dell'audio alla servlet:", error);
console.log(xhr.responseText);
redirect("500.html");
});
}
}

0 comments on commit dff936f

Please sign in to comment.