1
1
/*
2
- * (C) Copyright IBM Corp. 2019, 2022 .
2
+ * (C) Copyright IBM Corp. 2023 .
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5
5
* the License. You may obtain a copy of the License at
12
12
*/
13
13
14
14
/*
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
16
16
*/
17
17
18
18
package com .ibm .watson .text_to_speech .v1 ;
62
62
import com .ibm .watson .text_to_speech .v1 .model .Voice ;
63
63
import com .ibm .watson .text_to_speech .v1 .model .Voices ;
64
64
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 ;
67
65
import java .io .InputStream ;
68
66
import java .util .HashMap ;
69
67
import java .util .Map ;
70
68
import java .util .Map .Entry ;
71
- import okhttp3 .HttpUrl ;
72
69
import okhttp3 .MultipartBody ;
73
- import okhttp3 .OkHttpClient ;
74
- import okhttp3 .Request ;
75
- import okhttp3 .WebSocket ;
76
70
77
71
/**
78
72
* The IBM Watson™ Text to Speech service provides APIs that use IBM's speech-synthesis
98
92
* also define speaker models to improve the quality of your custom prompts. The service support
99
93
* custom prompts only for US English custom models and voices.
100
94
*
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
102
96
* 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
106
99
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
107
100
* in the release notes for {{site.data.keyword.texttospeechshort}} for
108
101
* {{site.data.keyword.cloud_notm}}.{: deprecated}.
111
104
*/
112
105
public class TextToSpeech extends BaseService {
113
106
107
+ /** Default service name used when configuring the `TextToSpeech` client. */
114
108
public static final String DEFAULT_SERVICE_NAME = "text_to_speech" ;
115
109
110
+ /** Default service endpoint URL. */
116
111
public static final String DEFAULT_SERVICE_URL =
117
112
"https://api.us-south.text-to-speech.watson.cloud.ibm.com" ;
118
113
@@ -167,16 +162,15 @@ public TextToSpeech(String serviceName, Authenticator authenticator) {
167
162
* change from call to call; do not rely on an alphabetized or static list of voices. To see
168
163
* information about a specific voice, use the [Get a voice](#getvoice).
169
164
*
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
175
169
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
176
170
* in the release notes.
177
171
*
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 ).
180
174
*
181
175
* @param listVoicesOptions the {@link ListVoicesOptions} containing the options for the call
182
176
* @return a {@link ServiceCall} with a result of type {@link Voices}
@@ -203,16 +197,15 @@ public ServiceCall<Voices> listVoices(ListVoicesOptions listVoicesOptions) {
203
197
* change from call to call; do not rely on an alphabetized or static list of voices. To see
204
198
* information about a specific voice, use the [Get a voice](#getvoice).
205
199
*
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
211
204
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
212
205
* in the release notes.
213
206
*
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 ).
216
209
*
217
210
* @return a {@link ServiceCall} with a result of type {@link Voices}
218
211
*/
@@ -229,13 +222,12 @@ public ServiceCall<Voices> listVoices() {
229
222
* about all available voices, use the [List voices](#listvoices) method.
230
223
*
231
224
* <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 ).
233
226
*
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
239
231
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
240
232
* in the release notes.
241
233
*
@@ -278,11 +270,10 @@ public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
278
270
* <p>**See also:** [The HTTP
279
271
* interface](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-usingHTTP#usingHTTP).
280
272
*
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
286
277
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
287
278
* in the release notes.
288
279
*
@@ -322,6 +313,12 @@ public ServiceCall<Voice> getVoice(GetVoiceOptions getVoiceOptions) {
322
313
* some of the formats, see [Using audio
323
314
* formats](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-audio-formats).
324
315
*
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
+ *
325
322
* <p>### Warning messages
326
323
*
327
324
* <p>If a request includes invalid query parameters, the service returns a `Warnings` response
@@ -354,60 +351,19 @@ public ServiceCall<InputStream> synthesize(SynthesizeOptions synthesizeOptions)
354
351
if (synthesizeOptions .spellOutMode () != null ) {
355
352
builder .query ("spell_out_mode" , String .valueOf (synthesizeOptions .spellOutMode ()));
356
353
}
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
+ }
357
360
final JsonObject contentJson = new JsonObject ();
358
361
contentJson .addProperty ("text" , synthesizeOptions .text ());
359
362
builder .bodyJson (contentJson );
360
363
ResponseConverter <InputStream > responseConverter = ResponseConverterUtils .getInputStream ();
361
364
return createServiceCall (builder .build (), responseConverter );
362
365
}
363
366
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
-
411
367
/**
412
368
* Get pronunciation.
413
369
*
@@ -416,11 +372,10 @@ public WebSocket synthesizeUsingWebSocket(
416
372
* default translation for the language of that voice or for a specific custom model to see the
417
373
* translation for that model.
418
374
*
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
424
379
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
425
380
* in the release notes.
426
381
*
@@ -469,11 +424,10 @@ public ServiceCall<Pronunciation> getPronunciation(
469
424
* <p>**See also:** [Creating a custom
470
425
* model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-customModels#cuModelsCreate).
471
426
*
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
477
431
* update](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-release-notes#text-to-speech-31march2022)
478
432
* in the release notes.
479
433
*
0 commit comments