32
32
* <p>This class provides the ability to make remote calls to the backing service through method
33
33
* calls that map to API methods. Sample code to get started:
34
34
*
35
+ * <pre>{@code
36
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
37
+ * String languageCode = "languageCode-2092349083";
38
+ * ListVoicesResponse response = textToSpeechClient.listVoices(languageCode);
39
+ * }
40
+ * }</pre>
41
+ *
35
42
* <p>Note: close() needs to be called on the TextToSpeechClient object to clean up resources such
36
43
* as threads. In the example above, try-with-resources is used, which automatically calls close().
37
44
*
@@ -135,6 +142,15 @@ public TextToSpeechStub getStub() {
135
142
/**
136
143
* Returns a list of Voice supported for synthesis.
137
144
*
145
+ * <p>Sample code:
146
+ *
147
+ * <pre>{@code
148
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
149
+ * String languageCode = "languageCode-2092349083";
150
+ * ListVoicesResponse response = textToSpeechClient.listVoices(languageCode);
151
+ * }
152
+ * }</pre>
153
+ *
138
154
* @param languageCode Optional. Recommended.
139
155
* [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. If specified, the
140
156
* ListVoices call will only return voices that can be used to synthesize this language_code.
@@ -154,6 +170,16 @@ public final ListVoicesResponse listVoices(String languageCode) {
154
170
/**
155
171
* Returns a list of Voice supported for synthesis.
156
172
*
173
+ * <p>Sample code:
174
+ *
175
+ * <pre>{@code
176
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
177
+ * ListVoicesRequest request =
178
+ * ListVoicesRequest.newBuilder().setLanguageCode("languageCode-2092349083").build();
179
+ * ListVoicesResponse response = textToSpeechClient.listVoices(request);
180
+ * }
181
+ * }</pre>
182
+ *
157
183
* @param request The request object containing all of the parameters for the API call.
158
184
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
159
185
*/
@@ -166,6 +192,17 @@ public final ListVoicesResponse listVoices(ListVoicesRequest request) {
166
192
* Returns a list of Voice supported for synthesis.
167
193
*
168
194
* <p>Sample code:
195
+ *
196
+ * <pre>{@code
197
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
198
+ * ListVoicesRequest request =
199
+ * ListVoicesRequest.newBuilder().setLanguageCode("languageCode-2092349083").build();
200
+ * ApiFuture<ListVoicesResponse> future =
201
+ * textToSpeechClient.listVoicesCallable().futureCall(request);
202
+ * // Do something.
203
+ * ListVoicesResponse response = future.get();
204
+ * }
205
+ * }</pre>
169
206
*/
170
207
public final UnaryCallable <ListVoicesRequest , ListVoicesResponse > listVoicesCallable () {
171
208
return stub .listVoicesCallable ();
@@ -175,6 +212,18 @@ public final UnaryCallable<ListVoicesRequest, ListVoicesResponse> listVoicesCall
175
212
/**
176
213
* Synthesizes speech synchronously: receive results after all text input has been processed.
177
214
*
215
+ * <p>Sample code:
216
+ *
217
+ * <pre>{@code
218
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
219
+ * SynthesisInput input = SynthesisInput.newBuilder().build();
220
+ * VoiceSelectionParams voice = VoiceSelectionParams.newBuilder().build();
221
+ * AudioConfig audioConfig = AudioConfig.newBuilder().build();
222
+ * SynthesizeSpeechResponse response =
223
+ * textToSpeechClient.synthesizeSpeech(input, voice, audioConfig);
224
+ * }
225
+ * }</pre>
226
+ *
178
227
* @param input Required. The Synthesizer requires either plain text or SSML as input.
179
228
* @param voice Required. The desired voice of the synthesized audio.
180
229
* @param audioConfig Required. The configuration of the synthesized audio.
@@ -195,6 +244,21 @@ public final SynthesizeSpeechResponse synthesizeSpeech(
195
244
/**
196
245
* Synthesizes speech synchronously: receive results after all text input has been processed.
197
246
*
247
+ * <p>Sample code:
248
+ *
249
+ * <pre>{@code
250
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
251
+ * SynthesizeSpeechRequest request =
252
+ * SynthesizeSpeechRequest.newBuilder()
253
+ * .setInput(SynthesisInput.newBuilder().build())
254
+ * .setVoice(VoiceSelectionParams.newBuilder().build())
255
+ * .setAudioConfig(AudioConfig.newBuilder().build())
256
+ * .addAllEnableTimePointing(new ArrayList<SynthesizeSpeechRequest.TimepointType>())
257
+ * .build();
258
+ * SynthesizeSpeechResponse response = textToSpeechClient.synthesizeSpeech(request);
259
+ * }
260
+ * }</pre>
261
+ *
198
262
* @param request The request object containing all of the parameters for the API call.
199
263
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
200
264
*/
@@ -207,6 +271,22 @@ public final SynthesizeSpeechResponse synthesizeSpeech(SynthesizeSpeechRequest r
207
271
* Synthesizes speech synchronously: receive results after all text input has been processed.
208
272
*
209
273
* <p>Sample code:
274
+ *
275
+ * <pre>{@code
276
+ * try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) {
277
+ * SynthesizeSpeechRequest request =
278
+ * SynthesizeSpeechRequest.newBuilder()
279
+ * .setInput(SynthesisInput.newBuilder().build())
280
+ * .setVoice(VoiceSelectionParams.newBuilder().build())
281
+ * .setAudioConfig(AudioConfig.newBuilder().build())
282
+ * .addAllEnableTimePointing(new ArrayList<SynthesizeSpeechRequest.TimepointType>())
283
+ * .build();
284
+ * ApiFuture<SynthesizeSpeechResponse> future =
285
+ * textToSpeechClient.synthesizeSpeechCallable().futureCall(request);
286
+ * // Do something.
287
+ * SynthesizeSpeechResponse response = future.get();
288
+ * }
289
+ * }</pre>
210
290
*/
211
291
public final UnaryCallable <SynthesizeSpeechRequest , SynthesizeSpeechResponse >
212
292
synthesizeSpeechCallable () {
0 commit comments