Skip to content

Commit

Permalink
🆕 Add new audio format to speech-to-text
Browse files Browse the repository at this point in the history
Add the audio format WebM to the Media type in speech-to-text and add a
unittest
  • Loading branch information
mamoonraja committed Apr 10, 2017
1 parent c168101 commit 1c93196
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SpeechAlternative> speechAlternatives = ImmutableList.of(speechAlternative);
transcript.setAlternatives(speechAlternatives);

final List<Transcript> 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.
Expand Down
Binary file not shown.

0 comments on commit 1c93196

Please sign in to comment.