Skip to content

Commit 7b7b138

Browse files
committed
chore(Text to Speech): Apply manual changes
1 parent e2dae74 commit 7b7b138

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
import com.ibm.watson.text_to_speech.v1.model.VoiceModels;
4343
import com.ibm.watson.text_to_speech.v1.model.Voices;
4444
import com.ibm.watson.text_to_speech.v1.model.Words;
45+
import com.ibm.watson.text_to_speech.v1.websocket.SynthesizeCallback;
46+
import com.ibm.watson.text_to_speech.v1.websocket.TextToSpeechWebSocketListener;
47+
import okhttp3.HttpUrl;
48+
import okhttp3.OkHttpClient;
49+
import okhttp3.Request;
50+
import okhttp3.WebSocket;
51+
4552
import java.io.InputStream;
4653
import java.util.Map;
4754
import java.util.Map.Entry;
@@ -265,6 +272,29 @@ public ServiceCall<InputStream> synthesize(SynthesizeOptions synthesizeOptions)
265272
return createServiceCall(builder.build(), responseConverter);
266273
}
267274

275+
public WebSocket synthesizeUsingWebSocket(SynthesizeOptions synthesizeOptions, SynthesizeCallback callback) {
276+
com.ibm.cloud.sdk.core.util.Validator.notNull(synthesizeOptions, "synthesizeOptions cannot be null");
277+
com.ibm.cloud.sdk.core.util.Validator.notNull(callback, "callback cannot be null");
278+
279+
HttpUrl.Builder urlBuilder = HttpUrl.parse(getEndPoint() + "/v1/synthesize").newBuilder();
280+
281+
if (synthesizeOptions.voice() != null) {
282+
urlBuilder.addQueryParameter("voice", synthesizeOptions.voice());
283+
}
284+
if (synthesizeOptions.customizationId() != null) {
285+
urlBuilder.addQueryParameter("customization_id", synthesizeOptions.customizationId());
286+
}
287+
288+
String url = urlBuilder.toString().replace("https://", "wss://");
289+
Request.Builder builder = new Request.Builder().url(url);
290+
291+
setAuthentication(builder);
292+
setDefaultHeaders(builder);
293+
294+
OkHttpClient client = configureHttpClient();
295+
return client.newWebSocket(builder.build(), new TextToSpeechWebSocketListener(synthesizeOptions, callback));
296+
}
297+
268298
/**
269299
* Get pronunciation.
270300
*

text-to-speech/src/main/java/com/ibm/watson/text_to_speech/v1/model/SynthesizeOptions.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1616

17+
import java.util.List;
18+
1719
/**
1820
* The synthesize options.
1921
*/
@@ -119,6 +121,7 @@ public interface Voice {
119121
private String accept;
120122
private String voice;
121123
private String customizationId;
124+
private List<String> timings;
122125

123126
/**
124127
* Builder.
@@ -128,12 +131,14 @@ public static class Builder {
128131
private String accept;
129132
private String voice;
130133
private String customizationId;
134+
private List<String> timings;
131135

132136
private Builder(SynthesizeOptions synthesizeOptions) {
133137
this.text = synthesizeOptions.text;
134138
this.accept = synthesizeOptions.accept;
135139
this.voice = synthesizeOptions.voice;
136140
this.customizationId = synthesizeOptions.customizationId;
141+
this.timings = synthesizeOptions.timings;
137142
}
138143

139144
/**
@@ -203,6 +208,17 @@ public Builder customizationId(String customizationId) {
203208
this.customizationId = customizationId;
204209
return this;
205210
}
211+
212+
/**
213+
* Set the timings.
214+
*
215+
* @param timings the timings
216+
* @return the SynthesizeOptions builder
217+
*/
218+
public Builder timings(List<String> timings) {
219+
this.timings = timings;
220+
return this;
221+
}
206222
}
207223

208224
private SynthesizeOptions(Builder builder) {
@@ -212,6 +228,7 @@ private SynthesizeOptions(Builder builder) {
212228
accept = builder.accept;
213229
voice = builder.voice;
214230
customizationId = builder.customizationId;
231+
timings = builder.timings;
215232
}
216233

217234
/**
@@ -271,4 +288,20 @@ public String voice() {
271288
public String customizationId() {
272289
return customizationId;
273290
}
291+
292+
/**
293+
* Gets the timings.
294+
*
295+
* An array that specifies whether the service is to return word timing information for all strings of the input
296+
* text. Specify `words` as the element of the array to request word timing information. The service returns the
297+
* start and end time of each word of the input. Specify an empty array or omit the parameter to receive no word
298+
* timing information. Not supported for Japanese input text.
299+
*
300+
* NOTE: This parameter only works for the `synthesizeUsingWebSocket` method.
301+
*
302+
* @return the timings
303+
*/
304+
public List<String> getTimings() {
305+
return timings;
306+
}
274307
}

0 commit comments

Comments
 (0)