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());
}
Aggregations