diff --git a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java index a6480b50f92..8be4138bc6b 100644 --- a/speech/cloud-client/src/main/java/com/example/speech/Recognize.java +++ b/speech/cloud-client/src/main/java/com/example/speech/Recognize.java @@ -66,12 +66,9 @@ public static void main(String... args) throws Exception { } else if (command.equals("asyncrecognize")) { if (path.startsWith("gs://")) { asyncRecognizeGcs(path); - } else { - asyncRecognizeFile(path); } } else if (command.equals("streamrecognize")) { streamingRecognizeFile(path); - //streamingRecognizeEasy(path); } } @@ -143,50 +140,6 @@ public static void syncRecognizeGcs(String gcsUri) throws Exception, IOException speech.close(); } - /* - /** - * Performs non-blocking speech recognition on raw PCM audio and prints - * the transcription. - * - * @param fileName the path to a PCM audio file to transcribe. - */ - public static void asyncRecognizeFile(String fileName) throws Exception, IOException { - // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS - SpeechClient speech = SpeechClient.create(); - - Path path = Paths.get(fileName); - byte[] data = Files.readAllBytes(path); - ByteString audioBytes = ByteString.copyFrom(data); - - // Configure request with local raw PCM audio - RecognitionConfig config = RecognitionConfig.newBuilder() - .setEncoding(AudioEncoding.LINEAR16) - .setLanguageCode("en-US") - .setSampleRateHertz(16000) - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder() - .setContent(audioBytes) - .build(); - - // Use non-blocking call for getting file transcription - OperationFuture response = - speech.longRunningRecognizeAsync(config, audio); - while (!response.isDone()) { - System.out.println("Waiting for response..."); - Thread.sleep(200); - } - - List results = response.get().getResultsList(); - - for (SpeechRecognitionResult result: results) { - List alternatives = result.getAlternativesList(); - for (SpeechRecognitionAlternative alternative: alternatives) { - System.out.printf("Transcription: %s%n", alternative.getTranscript()); - } - } - speech.close(); - } - /** * Performs non-blocking speech recognition on remote FLAC file and prints * the transcription. diff --git a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java index dac2f6be8ef..7fb42e95f00 100644 --- a/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java +++ b/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java @@ -69,13 +69,6 @@ public void testRecognizeGcs() throws Exception { assertThat(got).contains("how old is the Brooklyn Bridge"); } - @Test - public void testAsyncRecognizeFile() throws Exception { - Recognize.asyncRecognizeFile(fileName); - String got = bout.toString(); - assertThat(got).contains("how old is the Brooklyn Bridge"); - } - @Test public void testAsyncRecognizeGcs() throws Exception { Recognize.asyncRecognizeGcs(gcsPath);