From 49dcaee8af285104b0354faa8f8fa4cc1eb5f34a Mon Sep 17 00:00:00 2001 From: dshimo Date: Thu, 8 Nov 2018 12:20:10 -0600 Subject: [PATCH 1/3] change main's url and rev speech output format --- src/main/java/com/speechscrubber/RevSpeechService.java | 8 +++++--- src/main/webapp/js/main.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/speechscrubber/RevSpeechService.java b/src/main/java/com/speechscrubber/RevSpeechService.java index 4aed3df..100299c 100644 --- a/src/main/java/com/speechscrubber/RevSpeechService.java +++ b/src/main/java/com/speechscrubber/RevSpeechService.java @@ -45,10 +45,12 @@ public JsonObject getTranscript(@PathParam("id") String id) throws Exception { @GET @Path("/{id}/timestamps") - @Produces(MediaType.APPLICATION_JSON) - public List getTimeStamps(@PathParam("id") String id, @QueryParam("phrase") String phrase) throws Exception { + @Produces(MediaType.TEXT_PLAIN) + public String getTimeStamps(@PathParam("id") String id, @QueryParam("phrase") String phrase) throws Exception { + System.out.println("Just entered getTimeStamps in revSpeech"); TimeStampJSONParser tsParser = new TimeStampJSONParser(jc.getTranscript(id), phrase); - return tsParser.getTimeStamps(); + System.out.println("About to enter getTimeStamps from Parser"); + return tsParser.getTimeStamps().toString(); } // @POST diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index e344b25..b76cf33 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -174,8 +174,8 @@ $(document).ready(function() { var doSearch = debounce(function(search) { $.ajax({ - url: "rest/speech/" + jobID + "/timestamps/search?phrase=" + search, - type: "POST", + url: "rest/speech/" + jobID + "/timestamps?phrase=" + search, + type: "GET", success: function(response){ console.log(response); if(response.id !== null){ From a2fe44dad0784943b5bb5769ed87e61d07c2d5e7 Mon Sep 17 00:00:00 2001 From: Adam Yoho Date: Thu, 8 Nov 2018 12:22:06 -0600 Subject: [PATCH 2/3] tmp --- .../com/speechscrubber/RevSpeechService.java | 8 +++----- src/main/webapp/js/main.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/speechscrubber/RevSpeechService.java b/src/main/java/com/speechscrubber/RevSpeechService.java index 4aed3df..c3b07d5 100644 --- a/src/main/java/com/speechscrubber/RevSpeechService.java +++ b/src/main/java/com/speechscrubber/RevSpeechService.java @@ -1,7 +1,5 @@ package com.speechscrubber; -import java.util.List; - import javax.json.JsonObject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -45,10 +43,10 @@ public JsonObject getTranscript(@PathParam("id") String id) throws Exception { @GET @Path("/{id}/timestamps") - @Produces(MediaType.APPLICATION_JSON) - public List getTimeStamps(@PathParam("id") String id, @QueryParam("phrase") String phrase) throws Exception { + @Produces(MediaType.TEXT_PLAIN) + public String getTimeStamps(@PathParam("id") String id, @QueryParam("phrase") String phrase) throws Exception { TimeStampJSONParser tsParser = new TimeStampJSONParser(jc.getTranscript(id), phrase); - return tsParser.getTimeStamps(); + return tsParser.getTimeStamps().toString(); } // @POST diff --git a/src/main/webapp/js/main.js b/src/main/webapp/js/main.js index 908f8c7..60530c6 100644 --- a/src/main/webapp/js/main.js +++ b/src/main/webapp/js/main.js @@ -55,7 +55,16 @@ $(document).ready(function() { success: function(response){ // Insert the uploaded audio file in the audio portion. num_tries--; - deferred.resolve(response); + // Insert the uploaded audio file in the audio portion. + num_tries--; + if(response.indexOf('false') > -1){ + setTimeout(function(){ + return pollForTranscript(id, num_tries); + }, 3000); + } + else{ + deferred.resolve(id); + } }, error: function(){ num_tries--; @@ -106,7 +115,7 @@ $(document).ready(function() { reader.readAsDataURL(this.files[0]); uploadFile(this.files[0]).then(function(id){ // Poll for updates using the token - pollForTranscript(id).then(function(id){ + pollForTranscript(id, 50).then(function(id){ // Retrieve the transcript retrieveTranscript(id).then(function(response){ // Show the transcript on the page. @@ -169,8 +178,8 @@ $(document).ready(function() { var doSearch = debounce(function(search) { $.ajax({ - url: "rest/speech/" + jobID + "/timestamps/search?phrase=" + search, - type: "POST", + url: "rest/speech/" + jobID + "/timestamps?phrase=" + search, + type: "GET", success: function(response){ console.log(response); if(response.id !== null){ From 4a78100d6c1363deb4fb60e76201705003a3fd6b Mon Sep 17 00:00:00 2001 From: Adam Yoho Date: Thu, 8 Nov 2018 12:45:51 -0600 Subject: [PATCH 3/3] Updates to TimeStampJSONParser for JSON APIs --- .../parser/TimeStampJSONParser.java | 202 +++++++++--------- 1 file changed, 105 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java b/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java index 67e2629..90ba9c7 100644 --- a/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java +++ b/src/main/java/com/speechscrubber/parser/TimeStampJSONParser.java @@ -1,105 +1,113 @@ package com.speechscrubber.parser; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; -import javax.json.JsonObject; - -import com.ibm.json.java.JSONArray; -import com.ibm.json.java.JSONObject; -import com.ibm.json.java.OrderedJSONObject; +import javax.json.JsonArray; +import javax.json.JsonObject; public class TimeStampJSONParser { - - private static List times = new ArrayList(); - - public TimeStampJSONParser(JsonObject transcript, String searchString) { - - OrderedJSONObject jsonObject = (OrderedJSONObject) transcript; - - if(jsonObject == null) - return; - - JSONArray monologues = (JSONArray) jsonObject.get("monologues"); - - if(monologues == null) - return; - - // TODO: Handle more than one speaker - JSONObject speaker = (JSONObject) monologues.get(0); - - if(speaker == null) - return; - - JSONArray elements = (JSONArray) speaker.get("elements"); - - if(elements == null) - return; - - String[] sentenceArray = searchString.split(" "); - Double time = null; - boolean done = false; - int count = 0; - - if(elements.size() > sentenceArray.length) { - for(int i = 0; i < sentenceArray.length; i++) { - for(int j = 0; j < elements.size(); j++) { - JSONObject element = (JSONObject) elements.get(j); - String type = (String) element.get("type"); - - String value = (String) element.get("value"); - - if(sentenceArray[i].equals(value)) { - if(time == null) { - - time = Double.valueOf((Double) element.get("ts")); - break; - - } - else { - break; - - } - - } - else if (!sentenceArray[i].equals(value)) { - - if(time != null) { - if(elements.size() == (j + 1)) { - if( (count + 1) == times.size()) { - times.remove(count); - time = null; - done = true; - } - else if (count > times.size()) { - times.remove(count); - } - } - } - else if (time == null && elements.size() == (j + 1) && i == 0) { - done = true; - } - } - } - if(done == true) - break; - if(time != null) { - if(times.isEmpty()) { - times.add(count, time); - } - if(times.get(count) < time) { - time = null; - } - } - - } - } else { - } - } - - public static List getTimeStamps() { - return times; - } -} + private static List times = new ArrayList(); + + public TimeStampJSONParser(JsonObject transcript, String searchString) { + + JsonObject jsonObject = transcript; + + if (jsonObject == null) + return; + + JsonArray monologues = jsonObject.getJsonArray("monologues"); + System.out.println("Monologues: " + monologues); + + if (monologues == null) + return; + + // TODO: Handle more than one speaker + JsonObject speaker = (JsonObject) monologues.get(0); + System.out.println("speaker: " + speaker); + + if (speaker == null) + return; + + JsonArray elements = speaker.getJsonArray("elements"); + System.out.println("elements: " + elements); + + if (elements == null) + return; + + String[] sentenceArray = searchString.split(" "); + Double time = null; + boolean done = false; + int count = 0; + + System.out.println(); + if (elements.size() > sentenceArray.length) { + for (int i = 0; i < sentenceArray.length; i++) { + for (int j = 0; j < elements.size(); j++) { + JsonObject element = (JsonObject) elements.get(j); + System.out.println("Checking element: " + element); + String type = element.getString("type"); + System.out.println("\ttype: " + type); + + String value = element.getString("value"); + System.out.println("\tvalue: " + value); + + if (sentenceArray[i].equals(value)) { + System.out.println("\tFound matching word"); + if (time == null) { + System.out.println("\t\tAssociated time: " + time); + + time = element.getJsonNumber("ts").doubleValue(); + break; + + } else { + System.out.println("\t\tNada"); + break; + + } + + } else if (!sentenceArray[i].equals(value)) { + + System.out.println("\tNo match"); + if (time != null) { + if (elements.size() == (j + 1)) { + if ((count + 1) == times.size()) { + System.out.println("\t\t(1) Removing count [" + count + "] from times"); + times.remove(count); + time = null; + done = true; + } else if (count > times.size()) { + System.out.println("\t\t(2) Removing count [" + count + "] from times"); + times.remove(count); + } + } + } else if (time == null && elements.size() == (j + 1) && i == 0) { + System.out.println("\tDone! Right...?"); + done = true; + } + } + } + if (done == true) + break; + if (time != null) { + if (times.isEmpty()) { + System.out.println("Times is empty, so adding stuff..."); + times.add(count, time); + } + System.out.println("Checking times"); + if (times.get(count) < time) { + time = null; + } + } + + } + } else { + System.out.println("No man's land"); + } + } + + public static List getTimeStamps() { + return times; + } +}