use of com.google.cloud.speech.v1.RecognitionAudio in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method asyncRecognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void asyncRecognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
try {
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();
client.asyncRecognizeAsync(config, audio).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(ApiException.class, e.getCause().getClass());
ApiException apiException = (ApiException) e.getCause();
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode());
}
}
use of com.google.cloud.speech.v1.RecognitionAudio 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());
}
use of com.google.cloud.speech.v1.RecognitionAudio in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method longRunningRecognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void longRunningRecognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
try {
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();
client.longRunningRecognizeAsync(config, audio).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(ApiException.class, e.getCause().getClass());
ApiException apiException = (ApiException) e.getCause();
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode());
}
}
use of com.google.cloud.speech.v1.RecognitionAudio in project google-cloud-java by GoogleCloudPlatform.
the class SpeechClientTest method recognizeExceptionTest.
@Test
@SuppressWarnings("all")
public void recognizeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSpeech.addException(exception);
try {
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();
client.recognize(config, audio);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.cloud.speech.v1.RecognitionAudio 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