3737 * <p>This class provides the ability to make remote calls to the backing service through method
3838 * calls that map to API methods. Sample code to get started:
3939 *
40+ * <pre>{@code
41+ * try (SpeechClient speechClient = SpeechClient.create()) {
42+ * RecognitionConfig config = RecognitionConfig.newBuilder().build();
43+ * RecognitionAudio audio = RecognitionAudio.newBuilder().build();
44+ * RecognizeResponse response = speechClient.recognize(config, audio);
45+ * }
46+ * }</pre>
47+ *
4048 * <p>Note: close() needs to be called on the SpeechClient object to clean up resources such as
4149 * threads. In the example above, try-with-resources is used, which automatically calls close().
4250 *
@@ -149,6 +157,16 @@ public final OperationsClient getOperationsClient() {
149157 * Performs synchronous speech recognition: receive results after all audio has been sent and
150158 * processed.
151159 *
160+ * <p>Sample code:
161+ *
162+ * <pre>{@code
163+ * try (SpeechClient speechClient = SpeechClient.create()) {
164+ * RecognitionConfig config = RecognitionConfig.newBuilder().build();
165+ * RecognitionAudio audio = RecognitionAudio.newBuilder().build();
166+ * RecognizeResponse response = speechClient.recognize(config, audio);
167+ * }
168+ * }</pre>
169+ *
152170 * @param config Required. Provides information to the recognizer that specifies how to process
153171 * the request.
154172 * @param audio Required. The audio data to be recognized.
@@ -165,6 +183,19 @@ public final RecognizeResponse recognize(RecognitionConfig config, RecognitionAu
165183 * Performs synchronous speech recognition: receive results after all audio has been sent and
166184 * processed.
167185 *
186+ * <p>Sample code:
187+ *
188+ * <pre>{@code
189+ * try (SpeechClient speechClient = SpeechClient.create()) {
190+ * RecognizeRequest request =
191+ * RecognizeRequest.newBuilder()
192+ * .setConfig(RecognitionConfig.newBuilder().build())
193+ * .setAudio(RecognitionAudio.newBuilder().build())
194+ * .build();
195+ * RecognizeResponse response = speechClient.recognize(request);
196+ * }
197+ * }</pre>
198+ *
168199 * @param request The request object containing all of the parameters for the API call.
169200 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
170201 */
@@ -178,6 +209,19 @@ public final RecognizeResponse recognize(RecognizeRequest request) {
178209 * processed.
179210 *
180211 * <p>Sample code:
212+ *
213+ * <pre>{@code
214+ * try (SpeechClient speechClient = SpeechClient.create()) {
215+ * RecognizeRequest request =
216+ * RecognizeRequest.newBuilder()
217+ * .setConfig(RecognitionConfig.newBuilder().build())
218+ * .setAudio(RecognitionAudio.newBuilder().build())
219+ * .build();
220+ * ApiFuture<RecognizeResponse> future = speechClient.recognizeCallable().futureCall(request);
221+ * // Do something.
222+ * RecognizeResponse response = future.get();
223+ * }
224+ * }</pre>
181225 */
182226 public final UnaryCallable <RecognizeRequest , RecognizeResponse > recognizeCallable () {
183227 return stub .recognizeCallable ();
@@ -190,6 +234,17 @@ public final UnaryCallable<RecognizeRequest, RecognizeResponse> recognizeCallabl
190234 * `LongRunningRecognizeResponse` message. For more information on asynchronous speech
191235 * recognition, see the [how-to](https://cloud.google.com/speech-to-text/docs/async-recognize).
192236 *
237+ * <p>Sample code:
238+ *
239+ * <pre>{@code
240+ * try (SpeechClient speechClient = SpeechClient.create()) {
241+ * RecognitionConfig config = RecognitionConfig.newBuilder().build();
242+ * RecognitionAudio audio = RecognitionAudio.newBuilder().build();
243+ * LongRunningRecognizeResponse response =
244+ * speechClient.longRunningRecognizeAsync(config, audio).get();
245+ * }
246+ * }</pre>
247+ *
193248 * @param config Required. Provides information to the recognizer that specifies how to process
194249 * the request.
195250 * @param audio Required. The audio data to be recognized.
@@ -209,6 +264,19 @@ public final UnaryCallable<RecognizeRequest, RecognizeResponse> recognizeCallabl
209264 * `LongRunningRecognizeResponse` message. For more information on asynchronous speech
210265 * recognition, see the [how-to](https://cloud.google.com/speech-to-text/docs/async-recognize).
211266 *
267+ * <p>Sample code:
268+ *
269+ * <pre>{@code
270+ * try (SpeechClient speechClient = SpeechClient.create()) {
271+ * LongRunningRecognizeRequest request =
272+ * LongRunningRecognizeRequest.newBuilder()
273+ * .setConfig(RecognitionConfig.newBuilder().build())
274+ * .setAudio(RecognitionAudio.newBuilder().build())
275+ * .build();
276+ * LongRunningRecognizeResponse response = speechClient.longRunningRecognizeAsync(request).get();
277+ * }
278+ * }</pre>
279+ *
212280 * @param request The request object containing all of the parameters for the API call.
213281 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
214282 */
@@ -225,6 +293,20 @@ public final UnaryCallable<RecognizeRequest, RecognizeResponse> recognizeCallabl
225293 * recognition, see the [how-to](https://cloud.google.com/speech-to-text/docs/async-recognize).
226294 *
227295 * <p>Sample code:
296+ *
297+ * <pre>{@code
298+ * try (SpeechClient speechClient = SpeechClient.create()) {
299+ * LongRunningRecognizeRequest request =
300+ * LongRunningRecognizeRequest.newBuilder()
301+ * .setConfig(RecognitionConfig.newBuilder().build())
302+ * .setAudio(RecognitionAudio.newBuilder().build())
303+ * .build();
304+ * OperationFuture<LongRunningRecognizeResponse, LongRunningRecognizeMetadata> future =
305+ * speechClient.longRunningRecognizeOperationCallable().futureCall(request);
306+ * // Do something.
307+ * LongRunningRecognizeResponse response = future.get();
308+ * }
309+ * }</pre>
228310 */
229311 public final OperationCallable <
230312 LongRunningRecognizeRequest , LongRunningRecognizeResponse , LongRunningRecognizeMetadata >
@@ -240,6 +322,19 @@ public final UnaryCallable<RecognizeRequest, RecognizeResponse> recognizeCallabl
240322 * recognition, see the [how-to](https://cloud.google.com/speech-to-text/docs/async-recognize).
241323 *
242324 * <p>Sample code:
325+ *
326+ * <pre>{@code
327+ * try (SpeechClient speechClient = SpeechClient.create()) {
328+ * LongRunningRecognizeRequest request =
329+ * LongRunningRecognizeRequest.newBuilder()
330+ * .setConfig(RecognitionConfig.newBuilder().build())
331+ * .setAudio(RecognitionAudio.newBuilder().build())
332+ * .build();
333+ * ApiFuture<Operation> future = speechClient.longRunningRecognizeCallable().futureCall(request);
334+ * // Do something.
335+ * Operation response = future.get();
336+ * }
337+ * }</pre>
243338 */
244339 public final UnaryCallable <LongRunningRecognizeRequest , Operation >
245340 longRunningRecognizeCallable () {
@@ -252,6 +347,18 @@ public final UnaryCallable<RecognizeRequest, RecognizeResponse> recognizeCallabl
252347 * method is only available via the gRPC API (not REST).
253348 *
254349 * <p>Sample code:
350+ *
351+ * <pre>{@code
352+ * try (SpeechClient speechClient = SpeechClient.create()) {
353+ * BidiStream<StreamingRecognizeRequest, StreamingRecognizeResponse> bidiStream =
354+ * speechClient.streamingRecognizeCallable().call();
355+ * StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().build();
356+ * bidiStream.send(request);
357+ * for (StreamingRecognizeResponse response : bidiStream) {
358+ * // Do something when a response is received.
359+ * }
360+ * }
361+ * }</pre>
255362 */
256363 public final BidiStreamingCallable <StreamingRecognizeRequest , StreamingRecognizeResponse >
257364 streamingRecognizeCallable () {
0 commit comments