use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testSynthesize.
/**
* Test synthesize.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@SuppressWarnings("resource")
@Test
public void testSynthesize() throws IOException, InterruptedException {
final File audio = new File("src/test/resources/text_to_speech/sample1.wav");
final Buffer buffer = new Buffer().write(Files.toByteArray(audio));
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.AUDIO_WAV).setBody(buffer));
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(text).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(HttpMediaType.AUDIO_PCM + "; rate=16000").build();
final InputStream in = service.synthesize(synthesizeOptions).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(SynthesizeOptions.Voice.EN_US_LISAVOICE, requestUrl.queryParameter("voice"));
assertEquals(HttpMediaType.AUDIO_PCM + "; rate=16000", request.getHeader("Accept"));
assertNotNull(in);
writeInputStreamToOutputStream(in, new FileOutputStream("build/output.wav"));
}
use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testWithVoiceAsWav.
/**
* Test with voice as AudioFormat.WAV.
*/
// @Test
public void testWithVoiceAsWav() {
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(text).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(SynthesizeOptions.Accept.AUDIO_WAV).build();
final InputStream is = service.synthesize(synthesizeOptions).execute();
assertNotNull(is);
try {
writeInputStreamToOutputStream(is, new FileOutputStream("target/output.wav"));
} catch (final FileNotFoundException e) {
Assert.fail(e.getMessage());
}
}
use of com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions in project java-sdk by watson-developer-cloud.
the class TextToSpeechTest method testSynthesizeWebM.
/**
* 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));
SynthesizeOptions synthesizeOptions = new SynthesizeOptions.Builder().text(text).voice(SynthesizeOptions.Voice.EN_US_LISAVOICE).accept(SynthesizeOptions.Accept.AUDIO_WEBM).build();
final InputStream in = service.synthesize(synthesizeOptions).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(SynthesizeOptions.Voice.EN_US_LISAVOICE, requestUrl.queryParameter("voice"));
assertEquals(HttpMediaType.AUDIO_WEBM, request.getHeader("Accept"));
assertNotNull(in);
writeInputStreamToOutputStream(in, new FileOutputStream("build/output.webm"));
}
Aggregations