Search in sources :

Example 1 with SyncRecognizeRequest

use of com.google.cloud.speech.v1beta1.SyncRecognizeRequest in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method syncRecognizeTest.

@Test
@SuppressWarnings("all")
public void syncRecognizeTest() {
    SyncRecognizeResponse expectedResponse = SyncRecognizeResponse.newBuilder().build();
    mockSpeech.addResponse(expectedResponse);
    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();
    SyncRecognizeResponse actualResponse = client.syncRecognize(config, audio);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSpeech.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SyncRecognizeRequest actualRequest = (SyncRecognizeRequest) 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) SyncRecognizeRequest(com.google.cloud.speech.v1beta1.SyncRecognizeRequest) RecognitionConfig(com.google.cloud.speech.v1beta1.RecognitionConfig) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) SyncRecognizeResponse(com.google.cloud.speech.v1beta1.SyncRecognizeResponse) Test(org.junit.Test)

Aggregations

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 SyncRecognizeRequest (com.google.cloud.speech.v1beta1.SyncRecognizeRequest)1 SyncRecognizeResponse (com.google.cloud.speech.v1beta1.SyncRecognizeResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Test (org.junit.Test)1