diff --git a/core/src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java b/core/src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java index 5609b7266fb..67fd54f8304 100644 --- a/core/src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java +++ b/core/src/main/java/com/ibm/watson/developer_cloud/http/HttpMediaType.java @@ -89,6 +89,11 @@ private HttpMediaType() { */ public static final String AUDIO_WAV = "audio/wav"; + /** + * Field AUDIO_WEBM. (value is "audio/webm") + */ + public static final String AUDIO_WEBM = "audio/webm"; + /** * Field AUDIO_PCM. (value is "audio/l16") */ diff --git a/speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/util/MediaTypeUtils.java b/speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/util/MediaTypeUtils.java index 2fa76d8289b..0d95f25be9e 100644 --- a/speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/util/MediaTypeUtils.java +++ b/speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/util/MediaTypeUtils.java @@ -36,6 +36,7 @@ public final class MediaTypeUtils { MEDIA_TYPES.put(".oga", HttpMediaType.AUDIO_OGG); MEDIA_TYPES.put(".flac", HttpMediaType.AUDIO_FLAC); MEDIA_TYPES.put(".raw", HttpMediaType.AUDIO_RAW); + MEDIA_TYPES.put(".webm", HttpMediaType.AUDIO_WEBM); } private MediaTypeUtils() { diff --git a/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java b/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java index 283e2fbe07d..83320fc2510 100755 --- a/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java +++ b/speech-to-text/src/test/java/com/ibm/watson/developer_cloud/speech_to_text/v1/SpeechToTextTest.java @@ -94,6 +94,7 @@ public class SpeechToTextTest extends WatsonServiceUnitTest { private static final String PATH_WORD = "/v1/customizations/%s/words/%s"; private static final File SAMPLE_WAV = new File("src/test/resources/speech_to_text/sample1.wav"); + private static final File SAMPLE_WEBM = new File("src/test/resources/speech_to_text/sample1.webm"); private SpeechToText service; private SpeechSession session; @@ -271,6 +272,40 @@ public void testRecognize() throws URISyntaxException, InterruptedException { assertEquals(HttpMediaType.AUDIO_WAV, request.getHeader(CONTENT_TYPE)); } + /** + * Test recognize WebM for WebM audio format. + * + * @throws URISyntaxException the URI syntax exception + * @throws InterruptedException the interrupted exception + */ + @Test + public void testRecognizeWebM() throws URISyntaxException, InterruptedException { + + final SpeechResults speechResults = new SpeechResults(); + speechResults.setResultIndex(0); + final Transcript transcript = new Transcript(); + transcript.setFinal(true); + final SpeechAlternative speechAlternative = new SpeechAlternative(); + speechAlternative.setTranscript("thunderstorms could produce large hail isolated tornadoes and heavy rain"); + + final List speechAlternatives = ImmutableList.of(speechAlternative); + transcript.setAlternatives(speechAlternatives); + + final List transcripts = ImmutableList.of(transcript); + speechResults.setResults(transcripts); + + server.enqueue( + new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(speechResults))); + + final SpeechResults result = service.recognize(SAMPLE_WEBM).execute(); + final RecordedRequest request = server.takeRequest(); + + assertNotNull(result); + assertEquals(result, speechResults); + assertEquals("POST", request.getMethod()); + assertEquals(PATH_RECOGNIZE, request.getPath()); + assertEquals(HttpMediaType.AUDIO_WEBM, request.getHeader(CONTENT_TYPE)); + } /** * Test diarization. diff --git a/speech-to-text/src/test/resources/speech_to_text/sample1.webm b/speech-to-text/src/test/resources/speech_to_text/sample1.webm new file mode 100644 index 00000000000..d1a6112468d Binary files /dev/null and b/speech-to-text/src/test/resources/speech_to_text/sample1.webm differ