Search in sources :

Example 1 with Operation

use of com.google.longrunning.Operation in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method asyncRecognizeTest.

@Test
@SuppressWarnings("all")
public void asyncRecognizeTest() throws Exception {
    AsyncRecognizeResponse expectedResponse = AsyncRecognizeResponse.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("asyncRecognizeTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockSpeech.addResponse(resultOperation);
    RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
    int sampleRate = 44100;
    RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRate(sampleRate).build();
    String uri = "gs://bucket_name/file_name.flac";
    RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
    AsyncRecognizeResponse actualResponse = client.asyncRecognizeAsync(config, audio).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSpeech.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AsyncRecognizeRequest actualRequest = (AsyncRecognizeRequest) actualRequests.get(0);
    Assert.assertEquals(config, actualRequest.getConfig());
    Assert.assertEquals(audio, actualRequest.getAudio());
}
Also used : RecognitionAudio(com.google.cloud.speech.v1beta1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding) AsyncRecognizeRequest(com.google.cloud.speech.v1beta1.AsyncRecognizeRequest) RecognitionConfig(com.google.cloud.speech.v1beta1.RecognitionConfig) Operation(com.google.longrunning.Operation) AsyncRecognizeResponse(com.google.cloud.speech.v1beta1.AsyncRecognizeResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with Operation

use of com.google.longrunning.Operation in project google-cloud-java by GoogleCloudPlatform.

the class VideoIntelligenceServiceClientTest method annotateVideoTest.

@Test
@SuppressWarnings("all")
public void annotateVideoTest() throws Exception {
    AnnotateVideoResponse expectedResponse = AnnotateVideoResponse.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("annotateVideoTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockVideoIntelligenceService.addResponse(resultOperation);
    String inputUri = "inputUri1707300727";
    List<Feature> features = new ArrayList<>();
    VideoContext videoContext = VideoContext.newBuilder().build();
    String outputUri = "outputUri-1273518802";
    String locationId = "locationId552319461";
    AnnotateVideoResponse actualResponse = client.annotateVideoAsync(inputUri, features, videoContext, outputUri, locationId).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockVideoIntelligenceService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    AnnotateVideoRequest actualRequest = (AnnotateVideoRequest) actualRequests.get(0);
    Assert.assertEquals(inputUri, actualRequest.getInputUri());
    Assert.assertEquals(features, actualRequest.getFeaturesList());
    Assert.assertEquals(videoContext, actualRequest.getVideoContext());
    Assert.assertEquals(outputUri, actualRequest.getOutputUri());
    Assert.assertEquals(locationId, actualRequest.getLocationId());
}
Also used : AnnotateVideoRequest(com.google.cloud.videointelligence.v1beta1.AnnotateVideoRequest) ArrayList(java.util.ArrayList) VideoContext(com.google.cloud.videointelligence.v1beta1.VideoContext) Operation(com.google.longrunning.Operation) Feature(com.google.cloud.videointelligence.v1beta1.Feature) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) AnnotateVideoResponse(com.google.cloud.videointelligence.v1beta1.AnnotateVideoResponse) Test(org.junit.Test)

Example 3 with Operation

use of com.google.longrunning.Operation in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method longRunningRecognizeTest.

@Test
@SuppressWarnings("all")
public void longRunningRecognizeTest() throws Exception {
    LongRunningRecognizeResponse expectedResponse = LongRunningRecognizeResponse.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("longRunningRecognizeTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockSpeech.addResponse(resultOperation);
    RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.FLAC;
    int sampleRateHertz = 44100;
    String languageCode = "en-US";
    RecognitionConfig config = RecognitionConfig.newBuilder().setEncoding(encoding).setSampleRateHertz(sampleRateHertz).setLanguageCode(languageCode).build();
    String uri = "gs://bucket_name/file_name.flac";
    RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(uri).build();
    LongRunningRecognizeResponse actualResponse = client.longRunningRecognizeAsync(config, audio).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSpeech.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    LongRunningRecognizeRequest actualRequest = (LongRunningRecognizeRequest) actualRequests.get(0);
    Assert.assertEquals(config, actualRequest.getConfig());
    Assert.assertEquals(audio, actualRequest.getAudio());
}
Also used : LongRunningRecognizeResponse(com.google.cloud.speech.v1.LongRunningRecognizeResponse) RecognitionAudio(com.google.cloud.speech.v1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding) LongRunningRecognizeRequest(com.google.cloud.speech.v1.LongRunningRecognizeRequest) RecognitionConfig(com.google.cloud.speech.v1.RecognitionConfig) Operation(com.google.longrunning.Operation) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

Operation (com.google.longrunning.Operation)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 Test (org.junit.Test)3 LongRunningRecognizeRequest (com.google.cloud.speech.v1.LongRunningRecognizeRequest)1 LongRunningRecognizeResponse (com.google.cloud.speech.v1.LongRunningRecognizeResponse)1 RecognitionAudio (com.google.cloud.speech.v1.RecognitionAudio)1 RecognitionConfig (com.google.cloud.speech.v1.RecognitionConfig)1 AudioEncoding (com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding)1 AsyncRecognizeRequest (com.google.cloud.speech.v1beta1.AsyncRecognizeRequest)1 AsyncRecognizeResponse (com.google.cloud.speech.v1beta1.AsyncRecognizeResponse)1 RecognitionAudio (com.google.cloud.speech.v1beta1.RecognitionAudio)1 RecognitionConfig (com.google.cloud.speech.v1beta1.RecognitionConfig)1 AudioEncoding (com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding)1 AnnotateVideoRequest (com.google.cloud.videointelligence.v1beta1.AnnotateVideoRequest)1 AnnotateVideoResponse (com.google.cloud.videointelligence.v1beta1.AnnotateVideoResponse)1 Feature (com.google.cloud.videointelligence.v1beta1.Feature)1 VideoContext (com.google.cloud.videointelligence.v1beta1.VideoContext)1 ArrayList (java.util.ArrayList)1