|
| 1 | +/* |
| 2 | + * Copyright 2022 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.mediatranslation.v1beta1.samples; |
| 18 | + |
| 19 | +// [START |
| 20 | +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_streamingtranslatespeech_async] |
| 21 | +import com.google.api.gax.rpc.BidiStream; |
| 22 | +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceClient; |
| 23 | +import com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest; |
| 24 | +import com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse; |
| 25 | + |
| 26 | +public class AsyncStreamingTranslateSpeech { |
| 27 | + |
| 28 | + public static void main(String[] args) throws Exception { |
| 29 | + asyncStreamingTranslateSpeech(); |
| 30 | + } |
| 31 | + |
| 32 | + public static void asyncStreamingTranslateSpeech() throws Exception { |
| 33 | + // This snippet has been automatically generated for illustrative purposes only. |
| 34 | + // It may require modifications to work in your environment. |
| 35 | + try (SpeechTranslationServiceClient speechTranslationServiceClient = |
| 36 | + SpeechTranslationServiceClient.create()) { |
| 37 | + BidiStream<StreamingTranslateSpeechRequest, StreamingTranslateSpeechResponse> bidiStream = |
| 38 | + speechTranslationServiceClient.streamingTranslateSpeechCallable().call(); |
| 39 | + StreamingTranslateSpeechRequest request = |
| 40 | + StreamingTranslateSpeechRequest.newBuilder().build(); |
| 41 | + bidiStream.send(request); |
| 42 | + for (StreamingTranslateSpeechResponse response : bidiStream) { |
| 43 | + // Do something when a response is received. |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | +// [END |
| 49 | +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_streamingtranslatespeech_async] |
0 commit comments