Skip to content

Commit

Permalink
TTS Synthesize using POST, fixes #635 and #602
Browse files Browse the repository at this point in the history
  • Loading branch information
germanattanasio committed Apr 7, 2017
1 parent bd29fc2 commit 5ae0d24
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.http.RequestBuilder;
Expand Down Expand Up @@ -216,9 +217,12 @@ public ServiceCall<InputStream> synthesize(final String text, final Voice voice,
Validator.isTrue((text != null) && !text.isEmpty(), "text cannot be null or empty");
Validator.isTrue(voice != null, "voice cannot be null or empty");

String modifiedText = text.replace(";", "%3B");
final RequestBuilder request = RequestBuilder.get(PATH_SYNTHESIZE);
request.query(TEXT, modifiedText);
final RequestBuilder request = RequestBuilder.post(PATH_SYNTHESIZE);

JsonObject jsonText = new JsonObject();
jsonText.addProperty(TEXT, text);
request.bodyJson(jsonText);

request.query(VOICE, voice.getName());
request.query(ACCEPT, audioFormat != null ? audioFormat : AudioFormat.WAV);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testGetVoice() {
*/
@Test
public void testSynthesize() throws IOException {
String text = "This is an integration test";
String text = "This is an integration test; 1,2 !, @, #, $, %, ^, 20.";
InputStream result = service.synthesize(text, Voice.EN_LISA, AudioFormat.WAV).execute();
writeInputStreamToFile(result, File.createTempFile("tts-audio", "wav"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ public void testSynthesize() throws IOException, InterruptedException {
service.synthesize(text, Voice.EN_LISA, new AudioFormat(HttpMediaType.AUDIO_PCM + "; rate=16000")).execute();
final RecordedRequest request = server.takeRequest();
final HttpUrl requestUrl = HttpUrl.parse("http://www.example.com" + request.getPath());
String modifiedText = text.replace(";", "%3B");

assertEquals(request.getBody().readUtf8(),"{\"text\":\""+text+"\"}");
assertEquals(SYNTHESIZE_PATH, requestUrl.encodedPath());
assertEquals(modifiedText, requestUrl.queryParameter("text"));
assertEquals(Voice.EN_LISA.getName(), requestUrl.queryParameter("voice"));
assertEquals(HttpMediaType.AUDIO_PCM + "; rate=16000", requestUrl.queryParameter("accept"));
assertNotNull(in);
Expand Down

0 comments on commit 5ae0d24

Please sign in to comment.