diff --git a/codekit/pom.xml b/codekit/pom.xml index 91e36c2..635a065 100644 --- a/codekit/pom.xml +++ b/codekit/pom.xml @@ -4,7 +4,7 @@ com.att.api codekit - 1.0 + 1.0.1 jar codekit diff --git a/codekit/src/main/java/com/att/api/rest/RESTClient.java b/codekit/src/main/java/com/att/api/rest/RESTClient.java index be75ae5..cab7cd9 100644 --- a/codekit/src/main/java/com/att/api/rest/RESTClient.java +++ b/codekit/src/main/java/com/att/api/rest/RESTClient.java @@ -558,6 +558,21 @@ public APIResponse httpPost(String body) throws RESTException { } } + /** + * Sends an http POST request with the POST body set to the file. + * + *

+ * NOTE: Any parameters set using + * addParameter() or setParameter() will be + * ignored. + *

+ * + * @param file file to use as POST body@return api response + * @throws RESTException if POST was unsuccessful + */ + public APIResponse httpPost(File file) throws RESTException { + return httpPost(file, null); + } /** * Sends an http POST request with the POST body set to the file. * @@ -568,20 +583,23 @@ public APIResponse httpPost(String body) throws RESTException { *

* * @param file file to use as POST body + * @param mimeType mime type to use with the file (null for auto-detection) * @return api response * @throws RESTException if POST was unsuccessful */ - public APIResponse httpPost(File file) throws RESTException { + public APIResponse httpPost(File file, String mimeType) throws RESTException { HttpResponse response = null; try { HttpClient httpClient = createClient(); HttpPost httpPost = new HttpPost(url); addInternalHeaders(httpPost); + if (mimeType == null) { + // detect the mime type + mimeType = this.getMIMEType(file); + } - String contentType = this.getMIMEType(file); - - httpPost.setEntity(new FileEntity(file, contentType)); + httpPost.setEntity(new FileEntity(file, mimeType)); return buildResponse(httpClient.execute(httpPost)); } catch (Exception e) { @@ -673,6 +691,7 @@ private String getMIMEType(File file) throws IOException { contentType = "audio/amr"; } } + } catch (IOException ioe) { throw ioe; // pass along exception } finally { diff --git a/codekit/src/main/java/com/att/api/speech/service/SpeechService.java b/codekit/src/main/java/com/att/api/speech/service/SpeechService.java index e647f99..eb9073b 100644 --- a/codekit/src/main/java/com/att/api/speech/service/SpeechService.java +++ b/codekit/src/main/java/com/att/api/speech/service/SpeechService.java @@ -92,6 +92,24 @@ public SpeechResponse speechToText(File audio, String xArgs, */ public SpeechResponse speechToText(File audio, String xArgs, String speechContext, String subContext) throws RESTException { + + return speechToText(audio, null, xArgs, speechContext, subContext ); + } + /** + * Sends the request to the server. + * + * @param audio audio file to convert to text + * @param mimeType for audio file (null for auto-detection) + * @param xArgs Special information about the request + * @param speechContext additional context information about the audio + * @param subContext speechContext additional information + * + * @return SpeechResponse object + * @throws RESTException + * @see SpeechResponse + */ + public SpeechResponse speechToText(File audio, String mimeType, String xArgs, + String speechContext, String subContext ) throws RESTException { final String endpoint = getFQDN() + "/speech/v3/speechToText"; RESTClient restClient = new RESTClient(endpoint) @@ -108,7 +126,9 @@ public SpeechResponse speechToText(File audio, String xArgs, && speechContext.equals("Gaming")) { restClient.addHeader("X-SpeechSubContext", subContext); } - APIResponse apiResponse = restClient.httpPost(audio); + + APIResponse apiResponse = restClient.httpPost(audio, mimeType); + try { return SpeechResponse.valueOf( new JSONObject(apiResponse.getResponseBody()));