Skip to content

Commit 54fd47d

Browse files
jeff-arnapaparazzi0329
authored andcommitted
feat(text to speech): update based on api definitions
adds the params 'ratePercentage' and 'pitchPercentage' to 'synthesize' function
1 parent a743cb7 commit 54fd47d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+390
-185
lines changed

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

Lines changed: 48 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -12,7 +12,7 @@
1212
*/
1313

1414
/*
15-
* IBM OpenAPI SDK Code Generator Version: 3.53.0-9710cac3-20220713-193508
15+
* IBM OpenAPI SDK Code Generator Version: 3.64.1-cee95189-20230124-211647
1616
*/
1717

1818
package com.ibm.watson.text_to_speech.v1;
@@ -62,17 +62,11 @@
6262
import com.ibm.watson.text_to_speech.v1.model.Voice;
6363
import com.ibm.watson.text_to_speech.v1.model.Voices;
6464
import com.ibm.watson.text_to_speech.v1.model.Words;
65-
import com.ibm.watson.text_to_speech.v1.websocket.SynthesizeCallback;
66-
import com.ibm.watson.text_to_speech.v1.websocket.TextToSpeechWebSocketListener;
6765
import java.io.InputStream;
6866
import java.util.HashMap;
6967
import java.util.Map;
7068
import java.util.Map.Entry;
71-
import okhttp3.HttpUrl;
7269
import okhttp3.MultipartBody;
73-
import okhttp3.OkHttpClient;
74-
import okhttp3.Request;
75-
import okhttp3.WebSocket;
7670

7771
/**
7872
* The IBM Watson™ Text to Speech service provides APIs that use IBM's speech-synthesis
@@ -98,11 +92,10 @@
9892
* also define speaker models to improve the quality of your custom prompts. The service support
9993
* custom prompts only for US English custom models and voices.
10094
*
101-
* <p>Effective 31 March 2022, all neural voices are deprecated. The deprecated voices remain
95+
* <p>Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated voices remain
10296
* available to existing users until 31 March 2023, when they will be removed from the service and
103-
* the documentation. The neural voices are supported only for IBM Cloud; they are not available for
104-
* IBM Cloud Pak for Data. All enhanced neural voices remain available to all users. For more
105-
* information, see the [31 March 2022 service
97+
* the documentation. *No enhanced neural voices or expressive neural voices are deprecated.* For
98+
* more information, see the [31 March 2022 service
10699
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
107100
* in the release notes for {{site.data.keyword.texttospeechshort}} for
108101
* {{site.data.keyword.cloud_notm}}.{: deprecated}.
@@ -111,8 +104,10 @@
111104
*/
112105
public class TextToSpeech extends BaseService {
113106

107+
/** Default service name used when configuring the `TextToSpeech` client. */
114108
public static final String DEFAULT_SERVICE_NAME = "text_to_speech";
115109

110+
/** Default service endpoint URL. */
116111
public static final String DEFAULT_SERVICE_URL =
117112
"https://api.us-south.text-to-speech.watson.cloud.ibm.com";
118113

@@ -167,16 +162,15 @@ public TextToSpeech(String serviceName, Authenticator authenticator) {
167162
* change from call to call; do not rely on an alphabetized or static list of voices. To see
168163
* information about a specific voice, use the [Get a voice](#getvoice).
169164
*
170-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
171-
* remain available to existing users until 31 March 2023, when they will be removed from the
172-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
173-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
174-
* For more information, see the [31 March 2022 service
165+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
166+
* voices remain available to existing users until 31 March 2023, when they will be removed from
167+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
168+
* deprecated.* For more information, see the [31 March 2022 service
175169
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
176170
* in the release notes.
177171
*
178-
* <p>**See also:** [Listing all available
179-
* voices](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices#listVoices).
172+
* <p>**See also:** [Listing all
173+
* voices](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices-list#list-all-voices).
180174
*
181175
* @param listVoicesOptions the {@link ListVoicesOptions} containing the options for the call
182176
* @return a {@link ServiceCall} with a result of type {@link Voices}
@@ -203,16 +197,15 @@ public ServiceCall<Voices> listVoices(ListVoicesOptions listVoicesOptions) {
203197
* change from call to call; do not rely on an alphabetized or static list of voices. To see
204198
* information about a specific voice, use the [Get a voice](#getvoice).
205199
*
206-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
207-
* remain available to existing users until 31 March 2023, when they will be removed from the
208-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
209-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
210-
* For more information, see the [31 March 2022 service
200+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
201+
* voices remain available to existing users until 31 March 2023, when they will be removed from
202+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
203+
* deprecated.* For more information, see the [31 March 2022 service
211204
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
212205
* in the release notes.
213206
*
214-
* <p>**See also:** [Listing all available
215-
* voices](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices#listVoices).
207+
* <p>**See also:** [Listing all
208+
* voices](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices-list#list-all-voices).
216209
*
217210
* @return a {@link ServiceCall} with a result of type {@link Voices}
218211
*/
@@ -229,13 +222,12 @@ public ServiceCall<Voices> listVoices() {
229222
* about all available voices, use the [List voices](#listvoices) method.
230223
*
231224
* <p>**See also:** [Listing a specific
232-
* voice](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices#listVoice).
225+
* voice](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-voices-list#list-specific-voice).
233226
*
234-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
235-
* remain available to existing users until 31 March 2023, when they will be removed from the
236-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
237-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
238-
* For more information, see the [31 March 2022 service
227+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
228+
* voices remain available to existing users until 31 March 2023, when they will be removed from
229+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
230+
* deprecated.* For more information, see the [31 March 2022 service
239231
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
240232
* in the release notes.
241233
*
@@ -278,11 +270,10 @@ public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
278270
* <p>**See also:** [The HTTP
279271
* interface](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-usingHTTP#usingHTTP).
280272
*
281-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
282-
* remain available to existing users until 31 March 2023, when they will be removed from the
283-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
284-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
285-
* For more information, see the [31 March 2022 service
273+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
274+
* voices remain available to existing users until 31 March 2023, when they will be removed from
275+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
276+
* deprecated.* For more information, see the [31 March 2022 service
286277
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
287278
* in the release notes.
288279
*
@@ -322,6 +313,12 @@ public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
322313
* some of the formats, see [Using audio
323314
* formats](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-audio-formats).
324315
*
316+
* <p>**Note:** By default, the service returns audio in the Ogg audio format with the Opus codec
317+
* (`audio/ogg;codecs=opus`). However, the Ogg audio format is not supported with the Safari
318+
* browser. If you are using the service with the Safari browser, you must use the `Accept`
319+
* request header or the `accept` query parameter specify a different format in which you want the
320+
* service to return the audio.
321+
*
325322
* <p>### Warning messages
326323
*
327324
* <p>If a request includes invalid query parameters, the service returns a `Warnings` response
@@ -354,60 +351,19 @@ public ServiceCall<InputStream> synthesize(SynthesizeOptions synthesizeOptions)
354351
if (synthesizeOptions.spellOutMode() != null) {
355352
builder.query("spell_out_mode", String.valueOf(synthesizeOptions.spellOutMode()));
356353
}
354+
if (synthesizeOptions.ratePercentage() != null) {
355+
builder.query("rate_percentage", String.valueOf(synthesizeOptions.ratePercentage()));
356+
}
357+
if (synthesizeOptions.pitchPercentage() != null) {
358+
builder.query("pitch_percentage", String.valueOf(synthesizeOptions.pitchPercentage()));
359+
}
357360
final JsonObject contentJson = new JsonObject();
358361
contentJson.addProperty("text", synthesizeOptions.text());
359362
builder.bodyJson(contentJson);
360363
ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
361364
return createServiceCall(builder.build(), responseConverter);
362365
}
363366

364-
/**
365-
* Synthesize audio.
366-
*
367-
* <p>Synthesizes text to audio that is spoken in the specified voice. The service bases its
368-
* understanding of the language for the input text on the specified voice. Use a voice that
369-
* matches the language of the input text.
370-
*
371-
* <p>The method accepts a maximum of 5 KB of input text in the body of the request, and 8 KB for
372-
* the URL and headers. The 5 KB limit includes any SSML tags that you specify. The service
373-
* returns the synthesized audio stream as an array of bytes.
374-
*
375-
* <p>### Audio formats (accept types)
376-
*
377-
* <p>For more information about specifying an audio format, including additional details about
378-
* some of the formats, see [Audio
379-
* formats](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-audioFormats#audioFormats).
380-
*
381-
* @param synthesizeOptions the {@link SynthesizeOptions} containing the options for the call
382-
* @param callback the {@link SynthesizeCallback} callback
383-
* @return a {@link WebSocket} instance
384-
*/
385-
public WebSocket synthesizeUsingWebSocket(
386-
SynthesizeOptions synthesizeOptions, SynthesizeCallback callback) {
387-
com.ibm.cloud.sdk.core.util.Validator.notNull(
388-
synthesizeOptions, "synthesizeOptions cannot be null");
389-
com.ibm.cloud.sdk.core.util.Validator.notNull(callback, "callback cannot be null");
390-
391-
HttpUrl.Builder urlBuilder = HttpUrl.parse(getServiceUrl() + "/v1/synthesize").newBuilder();
392-
393-
if (synthesizeOptions.voice() != null) {
394-
urlBuilder.addQueryParameter("voice", synthesizeOptions.voice());
395-
}
396-
if (synthesizeOptions.customizationId() != null) {
397-
urlBuilder.addQueryParameter("customization_id", synthesizeOptions.customizationId());
398-
}
399-
400-
String url = urlBuilder.toString().replace("https://", "wss://");
401-
Request.Builder builder = new Request.Builder().url(url);
402-
403-
setAuthentication(builder);
404-
setDefaultHeaders(builder);
405-
406-
OkHttpClient client = configureHttpClient();
407-
return client.newWebSocket(
408-
builder.build(), new TextToSpeechWebSocketListener(synthesizeOptions, callback));
409-
}
410-
411367
/**
412368
* Get pronunciation.
413369
*
@@ -416,11 +372,10 @@ public WebSocket synthesizeUsingWebSocket(
416372
* default translation for the language of that voice or for a specific custom model to see the
417373
* translation for that model.
418374
*
419-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
420-
* remain available to existing users until 31 March 2023, when they will be removed from the
421-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
422-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
423-
* For more information, see the [31 March 2022 service
375+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
376+
* voices remain available to existing users until 31 March 2023, when they will be removed from
377+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
378+
* deprecated.* For more information, see the [31 March 2022 service
424379
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
425380
* in the release notes.
426381
*
@@ -469,11 +424,10 @@ public ServiceCall<Pronunciation> getPronunciation(
469424
* <p>**See also:** [Creating a custom
470425
* model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-customModels#cuModelsCreate).
471426
*
472-
* <p>**Note:** Effective 31 March 2022, all neural voices are deprecated. The deprecated voices
473-
* remain available to existing users until 31 March 2023, when they will be removed from the
474-
* service and the documentation. The neural voices are supported only for IBM Cloud; they are not
475-
* available for IBM Cloud Pak for Data. All enhanced neural voices remain available to all users.
476-
* For more information, see the [31 March 2022 service
427+
* <p>**Note:** Effective **31 March 2022**, all *neural voices* are deprecated. The deprecated
428+
* voices remain available to existing users until 31 March 2023, when they will be removed from
429+
* the service and the documentation. *No enhanced neural voices or expressive neural voices are
430+
* deprecated.* For more information, see the [31 March 2022 service
477431
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
478432
* in the release notes.
479433
*

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2021, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -33,6 +33,11 @@ public static class Builder {
3333
private PromptMetadata metadata;
3434
private InputStream file;
3535

36+
/**
37+
* Instantiates a new Builder from an existing AddCustomPromptOptions instance.
38+
*
39+
* @param addCustomPromptOptions the instance to initialize the Builder with
40+
*/
3641
private Builder(AddCustomPromptOptions addCustomPromptOptions) {
3742
this.customizationId = addCustomPromptOptions.customizationId;
3843
this.promptId = addCustomPromptOptions.promptId;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2018, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -73,6 +73,11 @@ public static class Builder {
7373
private String translation;
7474
private String partOfSpeech;
7575

76+
/**
77+
* Instantiates a new Builder from an existing AddWordOptions instance.
78+
*
79+
* @param addWordOptions the instance to initialize the Builder with
80+
*/
7681
private Builder(AddWordOptions addWordOptions) {
7782
this.customizationId = addWordOptions.customizationId;
7883
this.word = addWordOptions.word;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2018, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -27,6 +27,11 @@ public static class Builder {
2727
private String customizationId;
2828
private List<Word> words;
2929

30+
/**
31+
* Instantiates a new Builder from an existing AddWordsOptions instance.
32+
*
33+
* @param addWordsOptions the instance to initialize the Builder with
34+
*/
3035
private Builder(AddWordsOptions addWordsOptions) {
3136
this.customizationId = addWordsOptions.customizationId;
3237
this.words = addWordsOptions.words;

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -73,6 +73,11 @@ public static class Builder {
7373
private String language;
7474
private String description;
7575

76+
/**
77+
* Instantiates a new Builder from an existing CreateCustomModelOptions instance.
78+
*
79+
* @param createCustomModelOptions the instance to initialize the Builder with
80+
*/
7681
private Builder(CreateCustomModelOptions createCustomModelOptions) {
7782
this.name = createCustomModelOptions.name;
7883
this.language = createCustomModelOptions.language;
@@ -155,7 +160,13 @@ public Builder newBuilder() {
155160
/**
156161
* Gets the name.
157162
*
158-
* <p>The name of the new custom model.
163+
* <p>The name of the new custom model. Use a localized name that matches the language of the
164+
* custom model. Use a name that describes the purpose of the custom model, such as `Medical
165+
* custom model` or `Legal custom model`. Use a name that is unique among all custom models that
166+
* you own.
167+
*
168+
* <p>Include a maximum of 256 characters in the name. Do not use backslashes, slashes, colons,
169+
* equal signs, ampersands, or question marks in the name.
159170
*
160171
* @return the name
161172
*/
@@ -179,7 +190,8 @@ public String language() {
179190
/**
180191
* Gets the description.
181192
*
182-
* <p>A description of the new custom model. Specifying a description is recommended.
193+
* <p>A recommended description of the new custom model. Use a localized description that matches
194+
* the language of the custom model. Include a maximum of 128 characters in the description.
183195
*
184196
* @return the description
185197
*/

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2021, 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -29,6 +29,11 @@ public static class Builder {
2929
private String speakerName;
3030
private InputStream audio;
3131

32+
/**
33+
* Instantiates a new Builder from an existing CreateSpeakerModelOptions instance.
34+
*
35+
* @param createSpeakerModelOptions the instance to initialize the Builder with
36+
*/
3237
private Builder(CreateSpeakerModelOptions createSpeakerModelOptions) {
3338
this.speakerName = createSpeakerModelOptions.speakerName;
3439
this.audio = createSpeakerModelOptions.audio;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2020, 2021.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -34,6 +34,8 @@ public class CustomModel extends GenericModel {
3434
protected List<Word> words;
3535
protected List<Prompt> prompts;
3636

37+
protected CustomModel() {}
38+
3739
/**
3840
* Gets the customizationId.
3941
*

0 commit comments

Comments
 (0)