Skip to content

Commit

Permalink
🆕 Add new format to text-to-speech
Browse files Browse the repository at this point in the history
Add the web format to AudioFormat in text-to-speech, and add the unit
test
  • Loading branch information
mamoonraja committed Apr 18, 2017
1 parent c74cd03 commit 07a375e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public class AudioFormat {
/** WAV format (value is "audio/wav"). */
public static final AudioFormat WAV = new AudioFormat(HttpMediaType.AUDIO_WAV);

/** WAV format (value is "audio/webm"). */
public static final AudioFormat WEBM = new AudioFormat(HttpMediaType.AUDIO_WEBM);

/** WAV format (value is "audio/webm; codecs=vorbis"). */
public static final AudioFormat WEBM_VORBIS = new AudioFormat(HttpMediaType.AUDIO_WEBM_VORBIS);

/** WAV format (value is "audio/webm; codecs=opus"). */
public static final AudioFormat WEBM_OPUS = new AudioFormat(HttpMediaType.AUDIO_WEBM_OPUS);

/**
* Linear 16-bit Pulse-Code Modulation (PCM) format (value is "audio/l16").
* This format must have a sampling rate set before use, see {@link #getPCM(int)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,34 @@ public void testSynthesize() throws IOException, InterruptedException {
}


/**
* Test synthesize for WebM.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@SuppressWarnings("resource")
@Test
public void testSynthesizeWebM() throws IOException, InterruptedException {
final File audio = new File("src/test/resources/text_to_speech/sample1.webm");
final Buffer buffer = new Buffer().write(Files.toByteArray(audio));

server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.AUDIO_WEBM).setBody(buffer));

final InputStream in =
service.synthesize(text, Voice.EN_LISA, AudioFormat.WEBM).execute();
final RecordedRequest request = server.takeRequest();
final HttpUrl requestUrl = HttpUrl.parse("http://www.example.com" + request.getPath());

assertEquals(request.getBody().readUtf8(), "{\"text\":\"" + text + "\"}");
assertEquals(SYNTHESIZE_PATH, requestUrl.encodedPath());
assertEquals(Voice.EN_LISA.getName(), requestUrl.queryParameter("voice"));
assertEquals(HttpMediaType.AUDIO_WEBM, requestUrl.queryParameter("accept"));
assertNotNull(in);

writeInputStreamToOutputStream(in, new FileOutputStream("build/output.webm"));
}

/**
* Test with voice as AudioFormat.WAV.
*/
Expand All @@ -223,7 +251,6 @@ public void testWithVoiceAsWav() {

}


/**
* Test the fix wave header not having the size due to be streamed.
*
Expand Down
Binary file not shown.

0 comments on commit 07a375e

Please sign in to comment.