Skip to content

Commit 6e6b2ae

Browse files
committed
chore(Text to Speech): Apply manual changes
This reverts commit 320c319.
1 parent 01a95d4 commit 6e6b2ae

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/developer_cloud/text_to_speech/v1/TextToSpeech.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@
3939
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.VoiceModels;
4040
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Voices;
4141
import com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words;
42+
import com.ibm.watson.developer_cloud.text_to_speech.v1.websocket.SynthesizeCallback;
43+
import com.ibm.watson.developer_cloud.text_to_speech.v1.websocket.TextToSpeechWebSocketListener;
4244
import com.ibm.watson.developer_cloud.util.GsonSingleton;
4345
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
4446
import com.ibm.watson.developer_cloud.util.Validator;
47+
import okhttp3.HttpUrl;
48+
import okhttp3.OkHttpClient;
49+
import okhttp3.Request;
50+
import okhttp3.WebSocket;
51+
4552
import java.io.InputStream;
4653

4754
/**
@@ -265,6 +272,29 @@ public ServiceCall<InputStream> synthesize(SynthesizeOptions synthesizeOptions)
265272
return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream());
266273
}
267274

275+
public WebSocket synthesizeUsingWebSocket(SynthesizeOptions synthesizeOptions, SynthesizeCallback callback) {
276+
Validator.notNull(synthesizeOptions, "synthesizeOptions cannot be null");
277+
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/developer_cloud/text_to_speech/v1/model/SynthesizeOptions.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.ibm.watson.developer_cloud.service.model.GenericModel;
1616
import com.ibm.watson.developer_cloud.util.Validator;
1717

18+
import java.util.List;
19+
1820
/**
1921
* The synthesize options.
2022
*/
@@ -94,6 +96,7 @@ public interface Voice {
9496
private String accept;
9597
private String voice;
9698
private String customizationId;
99+
private List<String> timings;
97100

98101
/**
99102
* Builder.
@@ -103,12 +106,14 @@ public static class Builder {
103106
private String accept;
104107
private String voice;
105108
private String customizationId;
109+
private List<String> timings;
106110

107111
private Builder(SynthesizeOptions synthesizeOptions) {
108112
text = synthesizeOptions.text;
109113
accept = synthesizeOptions.accept;
110114
voice = synthesizeOptions.voice;
111115
customizationId = synthesizeOptions.customizationId;
116+
timings = synthesizeOptions.timings;
112117
}
113118

114119
/**
@@ -178,6 +183,17 @@ public Builder customizationId(String customizationId) {
178183
this.customizationId = customizationId;
179184
return this;
180185
}
186+
187+
/**
188+
* Set the timings.
189+
*
190+
* @param timings the timings
191+
* @return the SynthesizeOptions builder
192+
*/
193+
public Builder timings(List<String> timings) {
194+
this.timings = timings;
195+
return this;
196+
}
181197
}
182198

183199
private SynthesizeOptions(Builder builder) {
@@ -186,6 +202,7 @@ private SynthesizeOptions(Builder builder) {
186202
accept = builder.accept;
187203
voice = builder.voice;
188204
customizationId = builder.customizationId;
205+
timings = builder.timings;
189206
}
190207

191208
/**
@@ -247,4 +264,20 @@ public String voice() {
247264
public String customizationId() {
248265
return customizationId;
249266
}
267+
268+
/**
269+
* Gets the timings.
270+
*
271+
* An array that specifies whether the service is to return word timing information for all strings of the input
272+
* text. Specify `words` as the element of the array to request word timing information. The service returns the
273+
* start and end time of each word of the input. Specify an empty array or omit the parameter to receive no word
274+
* timing information. Not supported for Japanese input text.
275+
*
276+
* NOTE: This parameter only works for the `synthesizeUsingWebSocket` method.
277+
*
278+
* @return the timings
279+
*/
280+
public List<String> timings() {
281+
return timings;
282+
}
250283
}

0 commit comments

Comments
 (0)