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