Search in sources :

Example 1 with RecognizeRequest

use of com.google.cloud.speech.v1.RecognizeRequest in project google-cloud-java by GoogleCloudPlatform.

the class SpeechClientTest method recognizeTest.

@Test
@SuppressWarnings("all")
public void recognizeTest() {
    RecognizeResponse expectedResponse = RecognizeResponse.newBuilder().build();
    mockSpeech.addResponse(expectedResponse);
    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();
    RecognizeResponse actualResponse = client.recognize(config, audio);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSpeech.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RecognizeRequest actualRequest = (RecognizeRequest) actualRequests.get(0);
    Assert.assertEquals(config, actualRequest.getConfig());
    Assert.assertEquals(audio, actualRequest.getAudio());
}
Also used : RecognitionAudio(com.google.cloud.speech.v1.RecognitionAudio) AudioEncoding(com.google.cloud.speech.v1.RecognitionConfig.AudioEncoding) LongRunningRecognizeRequest(com.google.cloud.speech.v1.LongRunningRecognizeRequest) RecognizeRequest(com.google.cloud.speech.v1.RecognizeRequest) StreamingRecognizeRequest(com.google.cloud.speech.v1.StreamingRecognizeRequest) RecognitionConfig(com.google.cloud.speech.v1.RecognitionConfig) LongRunningRecognizeResponse(com.google.cloud.speech.v1.LongRunningRecognizeResponse) StreamingRecognizeResponse(com.google.cloud.speech.v1.StreamingRecognizeResponse) RecognizeResponse(com.google.cloud.speech.v1.RecognizeResponse) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Aggregations

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 RecognizeRequest (com.google.cloud.speech.v1.RecognizeRequest)1 RecognizeResponse (com.google.cloud.speech.v1.RecognizeResponse)1 StreamingRecognizeRequest (com.google.cloud.speech.v1.StreamingRecognizeRequest)1 StreamingRecognizeResponse (com.google.cloud.speech.v1.StreamingRecognizeResponse)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 Test (org.junit.Test)1