@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (getAlternativesCount() > 0) { hash = (37 * hash) + ALTERNATIVES_FIELD_NUMBER; hash = (53 * hash) + getAlternativesList().hashCode(); } hash = (37 * hash) + CHANNEL_TAG_FIELD_NUMBER; hash = (53 * hash) + getChannelTag(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Test public void syncRecognize() { RecognizeResponse response = speechClient.recognize(config(), audio()); Truth.assertThat(response.getResultsCount()).isGreaterThan(0); Truth.assertThat(response.getResults(0).getAlternativesCount()).isGreaterThan(0); String text = response.getResults(0).getAlternatives(0).getTranscript(); Truth.assertThat(text).isEqualTo("hello"); }
@Test public void longrunningRecognize() throws Exception { LongRunningRecognizeResponse response = speechClient.longRunningRecognizeAsync(config(), audio()).get(); Truth.assertThat(response.getResultsCount()).isGreaterThan(0); Truth.assertThat(response.getResults(0).getAlternativesCount()).isGreaterThan(0); String text = response.getResults(0).getAlternatives(0).getTranscript(); Truth.assertThat(text).isEqualTo("hello"); }
/** * @see AIDataService#voiceRequest(InputStream, RequestExtras, AIServiceContext) */ @Override public AIResponse voiceRequest(InputStream voiceStream, RequestExtras requestExtras, AIServiceContext serviceContext) throws AIServiceException { RecognizeResponse response; try { SpeechClient speechClient = SpeechClient.create(); RecognitionAudio recognitionAudio = createRecognitionAudio(voiceStream); response = speechClient.recognize(config.getRecognitionConfig(), recognitionAudio); } catch (IOException | StatusRuntimeException e) { throw new AIServiceException("Failed to recognize speech", e); } if ((response.getResultsCount() == 0) || (response.getResults(0).getAlternativesCount() == 0)) { throw new AIServiceException("No speech"); } String transcript = response.getResults(0).getAlternatives(0).getTranscript(); AIRequest request = new AIRequest(transcript); return request(request, requestExtras, serviceContext); }