From 3264dade725ad2bec301beefb9d0e45b52ee753a Mon Sep 17 00:00:00 2001 From: steven1046 Date: Thu, 8 Nov 2018 10:50:42 -0600 Subject: [PATCH] Update polling and transcript fetch --- src/main/webapp/js/main.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index c26db0d..5f74b87 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -45,9 +45,7 @@ $(document).ready(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", @@ -55,11 +53,12 @@ $(document).ready(function() { async: false, processData: false, success: function(response){ - // Insert the uploaded audio file in the audio portion. - deferred.resolve(id); + // Insert the uploaded audio file in the audio portion. + num_tries--; + deferred.resolve(response); }, - error: function(jqXHR){ - // deferred.reject(jqXHR); + error: function(){ + num_tries--; if(num_tries == 0){ deferred.reject(); } @@ -69,6 +68,9 @@ $(document).ready(function() { } }); } + else { + deferred.reject(); + } return deferred; }; @@ -104,13 +106,19 @@ $(document).ready(function() { // Poll for updates using the token pollForTranscript(id).then(function(id){ // Retrieve the transcript - retrieveTranscript(id).then(function(){ - - }).fail(function(){ - + retrieveTranscript(id).then(function(response){ + // Show the transcript on the page. + var transcript = response.split('\s'); + for(var word in transcript){ + var span = $(span); + span.innerText = word; + $('#transcript').append(span); + } + }).fail(function(error){ + $('#audio_status').text('Unable to retrieve transcript from Rev.ai'); }); - }).fail(function(){ - + }).fail(function(error){ + $('#audio_status').text('The transcript was unable to be created.'); }); // Show pills for each word in the transcript of the audio file. }).fail(function(error){ @@ -154,7 +162,7 @@ $(document).ready(function() { timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; - }; + } var doSearch = debounce(function(search) { $.ajax({