@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"); }
SpeechRecognitionAlternative alternative = result.getAlternatives(0); System.out.format("Transcript: %s\n\n", alternative.getTranscript());
@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"); }
final SpeechRecognitionAlternative alternative = result.getAlternatives(0); FlowFile ff = session.write(session.create(), new OutputStreamCallback() { @Override
/** * @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); }