Changeset 35248 for gs3-extensions
- Timestamp:
- 2021-08-04T11:30:42+12:00 (3 years ago)
- Location:
- gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/TranscriptionServlet.java
r35247 r35248 78 78 throws ServletException, IOException 79 79 { 80 logger.trace("POST request received.");81 82 response.setContentType("application/json; charset=UTF-8");83 PrintWriter writer = response.getWriter();84 85 String audioFileKeysParameter = request.getParameter("audioFileKeys");86 if (audioFileKeysParameter == null) {87 response.sendError(400, "Form data was incorrect: missing audioFileKeys part.");88 return;89 }90 String[] audioFileKeys = audioFileKeysParameter.split("\\|");91 92 // Create our own representation of each part93 ArrayList<AudioFilePart> audioFileParts = new ArrayList<AudioFilePart>(audioFileKeys.length);94 for (String audioFileKey : audioFileKeys)95 {96 Part p = request.getPart(audioFileKey);97 AudioFilePart audioFilePart = AudioFilePart.fromPart(p);98 audioFileParts.add(audioFilePart);99 }100 101 80 try 102 81 { 82 logger.trace("POST request received."); 83 84 response.setContentType("application/json; charset=UTF-8"); 85 PrintWriter writer = response.getWriter(); 86 87 // Attempt to get the key of every audio file part 88 String audioFileKeysParameter = request.getParameter("audioFileKeys"); 89 if (audioFileKeysParameter == null) 90 { 91 response.sendError(400, "Form data was incorrect: missing audioFileKeys part."); 92 logger.trace("Request rejected due: Form data was missing the audioFileKeys part."); 93 return; 94 } 95 String[] audioFileKeys = audioFileKeysParameter.split("\\|"); 96 97 // Create our own representation of each part 98 ArrayList<AudioFilePart> audioFileParts = new ArrayList<AudioFilePart>(audioFileKeys.length); 99 for (String audioFileKey : audioFileKeys) 100 { 101 // Attempt to get the part that this key specifies should be present 102 Part p = request.getPart(audioFileKey); 103 if (p == null) { 104 response.sendError(400, "Form data was incorrect: a part key listed in the audioFileKeys was not found."); 105 logger.trace("Request rejected due: Form data was missing a client-specified part."); 106 return; 107 } 108 109 AudioFilePart audioFilePart = AudioFilePart.fromPart(p); 110 audioFileParts.add(audioFilePart); 111 } 112 113 // Transcribe each part 103 114 List<AudioFilePart> results = transcriptionService.getTranscriptions(audioFileParts); 104 115 116 // Transform the Tuhituhi response into our own format 105 117 List<MyTranscriptionResponse> responses = new ArrayList<MyTranscriptionResponse>(results.size()); 106 118 for (AudioFilePart result : results) { … … 108 120 } 109 121 122 // Send our result to the client 110 123 String json = jsonSerialiser.toJson(responses, transcriptionListType); 111 124 writer.append(json); -
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/models/AudioFilePart.java
r35241 r35248 11 11 12 12 public final String fileName; 13 public final InputStream dataStream; 13 public final InputStream dataStream; // TODO: Use a buffered input stream here? Need to check docs on what type of stream a Part uses 14 14 15 15 public AudioFilePart(String fileName, InputStream dataStream) -
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/services/ReoTuhituhiApiService.java
r35246 r35248 1 1 package org.atea.nlptools.koreromaoriinterface.services; 2 2 3 import java.io.IOException; 3 4 import java.io.InputStream; 4 5 import java.util.LinkedList; … … 67 68 */ 68 69 public TranscriptionResult getTranscription(InputStream audioStream) 69 throws HttpRequestException, JsonSyntaxException, ReoTuhituhiException 70 throws HttpRequestException, JsonSyntaxException, ReoTuhituhiException, IOException 70 71 { 72 logger.trace("Performing request to tuhituhi API. Audio bytes available to pass through: " + audioStream.available()); 73 71 74 HttpRequestService request = HttpRequestService 72 75 .post(apiEndpoint) … … 100 103 } 101 104 105 logger.trace("Tuhituhi API returned a successful result. Beginning deserialisation..."); 106 102 107 TranscriptionResult res = jsonSerialiser.fromJson(request.body(), TranscriptionResult.class); 108 109 logger.trace("Tuhituhi response successfully deserialised"); 103 110 104 111 return res; -
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/webapp/WEB-INF/log4j2.xml
r35247 r35248 9 9 </Appenders> 10 10 <Loggers> 11 <Root level=" debug">11 <Root level="trace"> 12 12 <AppenderRef ref="FileOutput"/> 13 13 </Root>
Note:
See TracChangeset
for help on using the changeset viewer.