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
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
1818package com .ibm .watson .text_to_speech .v1 ;
6262import com .ibm .watson .text_to_speech .v1 .model .Voice ;
6363import com .ibm .watson .text_to_speech .v1 .model .Voices ;
6464import 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 ;
6765import java .io .InputStream ;
6866import java .util .HashMap ;
6967import java .util .Map ;
7068import java .util .Map .Entry ;
71- import okhttp3 .HttpUrl ;
7269import 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
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}.
111104 */
112105public 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 *
0 commit comments