Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dshimo/SpeechScrubber
Browse files Browse the repository at this point in the history
  • Loading branch information
neuwerk committed Nov 8, 2018
2 parents 0f0f73b + 70f662d commit 8ab26d9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/webapp/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ p {
margin-bottom: 50px;
}

#audio {
width: 100%;
}

/* Transcript */
#transcript_section {

Expand Down
68 changes: 61 additions & 7 deletions src/main/webapp/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ $(document).ready(function() {
$('#audio_status').removeClass('hidden');
$('#audio_text').removeClass('hidden');
$('#audio_text').text("Uploading audio file...");
$('#audio').removeClass('hidden');

var formData = new FormData();
formData.append('data', file);
formData.append('filename', file.name);
$.ajax({
url: upload_url,
type: "POST",
Expand All @@ -22,10 +23,11 @@ $(document).ready(function() {
processData: false,
success: function(response){
// Insert the uploaded audio file in the audio portion.
$('#audio').removeClass('hidden');
// $('#audio').removeClass('hidden');
if(response.id !== null){
// ID from the job comes back. Need to keep polling to determine when the job is done/failed.
deferred.resolve(response.id);
// deferred.resolve(response.id);
deferred.resolve(result.id);
} else {
deferred.reject();
}
Expand All @@ -41,23 +43,75 @@ $(document).ready(function() {
return deferred;
};

var pollForTranscript = function() {
var pollForTranscript = function(id, num_tries) {
var deferred = $.Deferred();
var done = false;
if(num_tries > 0) {
num_tries--;
$.ajax({
url: "rest/speech/check/" + id,
type: "GET",
data: formData,
async: false,
processData: false,
success: function(response){
// Insert the uploaded audio file in the audio portion.
deferred.resolve(id);
},
error: function(jqXHR){
// deferred.reject(jqXHR);
if(num_tries == 0){
deferred.reject();
}
else {
return pollForTranscript(id, num_tries-1);
}
}
});
}
return deferred;
};

var retrieveTranscript = function(id) {
var deferred = $.deferred();
$.ajax({
url: "rest/speech/" + id + "/transcript",
type: "GET",
async: true,
success: function(response){
if(response.transcript !== null){
deferred.resolve(response.transcript);
} else {
deferred.reject();
}
},
error: function(jqXHR){
deferred.reject(jqXHR);
}
});
return deferred;
};

$('#file_browse').on('change', function(){
$('#file_browse').on('change', function(){
var audio = document.getElementById('audio');
var reader = new FileReader();
reader.onload = function(event) {
audio.src = this.result;
audio.controls = true;
};
reader.readAsDataURL(this.files[0]);
uploadFile(this.files[0]).then(function(jobID){
uploadFile(this.files[0]).then(function(id){
// Poll for updates using the token
pollForTranscript(id).then(function(id){
// Retrieve the transcript
retrieveTranscript(id).then(function(){

}).fail(function(){


});
}).fail(function(){

});
// Show pills for each word in the transcript of the audio file.
}).fail(function(error){
// Display error that no transcription was found.
Expand Down

0 comments on commit 8ab26d9

Please sign in to comment.