Skip to content

Commit 5ae0d24

Browse files
TTS Synthesize using POST, fixes #635 and #602
1 parent bd29fc2 commit 5ae0d24

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

text-to-speech/src/main/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TextToSpeech.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919

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

219-
String modifiedText = text.replace(";", "%3B");
220-
final RequestBuilder request = RequestBuilder.get(PATH_SYNTHESIZE);
221-
request.query(TEXT, modifiedText);
220+
final RequestBuilder request = RequestBuilder.post(PATH_SYNTHESIZE);
221+
222+
JsonObject jsonText = new JsonObject();
223+
jsonText.addProperty(TEXT, text);
224+
request.bodyJson(jsonText);
225+
222226
request.query(VOICE, voice.getName());
223227
request.query(ACCEPT, audioFormat != null ? audioFormat : AudioFormat.WAV);
224228

text-to-speech/src/test/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TextToSpeechIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testGetVoice() {
102102
*/
103103
@Test
104104
public void testSynthesize() throws IOException {
105-
String text = "This is an integration test";
105+
String text = "This is an integration test; 1,2 !, @, #, $, %, ^, 20.";
106106
InputStream result = service.synthesize(text, Voice.EN_LISA, AudioFormat.WAV).execute();
107107
writeInputStreamToFile(result, File.createTempFile("tts-audio", "wav"));
108108
}

text-to-speech/src/test/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TextToSpeechTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ public void testSynthesize() throws IOException, InterruptedException {
196196
service.synthesize(text, Voice.EN_LISA, new AudioFormat(HttpMediaType.AUDIO_PCM + "; rate=16000")).execute();
197197
final RecordedRequest request = server.takeRequest();
198198
final HttpUrl requestUrl = HttpUrl.parse("http://www.example.com" + request.getPath());
199-
String modifiedText = text.replace(";", "%3B");
200199

200+
assertEquals(request.getBody().readUtf8(),"{\"text\":\""+text+"\"}");
201201
assertEquals(SYNTHESIZE_PATH, requestUrl.encodedPath());
202-
assertEquals(modifiedText, requestUrl.queryParameter("text"));
203202
assertEquals(Voice.EN_LISA.getName(), requestUrl.queryParameter("voice"));
204203
assertEquals(HttpMediaType.AUDIO_PCM + "; rate=16000", requestUrl.queryParameter("accept"));
205204
assertNotNull(in);

0 commit comments

Comments
 (0)