Search in sources :

Example 1 with AsyncRecognizeRequest

use of com.google.cloud.speech.v1beta1.AsyncRecognizeRequest 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)

Aggregations

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 Operation (com.google.longrunning.Operation)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Test (org.junit.Test)1