Skip to content

Commit

Permalink
Update polling and transcript fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
steven1046 committed Nov 8, 2018
1 parent 7baf325 commit 3264dad
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/main/webapp/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,20 @@ $(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",
data: formData,
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();
}
Expand All @@ -69,6 +68,9 @@ $(document).ready(function() {
}
});
}
else {
deferred.reject();
}
return deferred;
};

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -154,7 +162,7 @@ $(document).ready(function() {
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
}

var doSearch = debounce(function(search) {
$.ajax({
Expand Down

0 comments on commit 3264dad

Please sign in to comment.