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.dialogflow.v2.samples; 18 19 // [START dialogflow_v2_generated_Sessions_StreamingDetectIntent_async] 20 import com.google.api.gax.rpc.BidiStream; 21 import com.google.cloud.dialogflow.v2.OutputAudioConfig; 22 import com.google.cloud.dialogflow.v2.QueryInput; 23 import com.google.cloud.dialogflow.v2.QueryParameters; 24 import com.google.cloud.dialogflow.v2.SessionName; 25 import com.google.cloud.dialogflow.v2.SessionsClient; 26 import com.google.cloud.dialogflow.v2.StreamingDetectIntentRequest; 27 import com.google.cloud.dialogflow.v2.StreamingDetectIntentResponse; 28 import com.google.protobuf.ByteString; 29 import com.google.protobuf.FieldMask; 30 31 public class AsyncStreamingDetectIntent { 32 main(String[] args)33 public static void main(String[] args) throws Exception { 34 asyncStreamingDetectIntent(); 35 } 36 asyncStreamingDetectIntent()37 public static void asyncStreamingDetectIntent() throws Exception { 38 // This snippet has been automatically generated and should be regarded as a code template only. 39 // It will require modifications to work: 40 // - It may require correct/in-range values for request initialization. 41 // - It may require specifying regional endpoints when creating the service client as shown in 42 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 43 try (SessionsClient sessionsClient = SessionsClient.create()) { 44 BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream = 45 sessionsClient.streamingDetectIntentCallable().call(); 46 StreamingDetectIntentRequest request = 47 StreamingDetectIntentRequest.newBuilder() 48 .setSession(SessionName.ofProjectSessionName("[PROJECT]", "[SESSION]").toString()) 49 .setQueryParams(QueryParameters.newBuilder().build()) 50 .setQueryInput(QueryInput.newBuilder().build()) 51 .setSingleUtterance(true) 52 .setOutputAudioConfig(OutputAudioConfig.newBuilder().build()) 53 .setOutputAudioConfigMask(FieldMask.newBuilder().build()) 54 .setInputAudio(ByteString.EMPTY) 55 .setEnableDebuggingInfo(true) 56 .build(); 57 bidiStream.send(request); 58 for (StreamingDetectIntentResponse response : bidiStream) { 59 // Do something when a response is received. 60 } 61 } 62 } 63 } 64 // [END dialogflow_v2_generated_Sessions_StreamingDetectIntent_async] 65