Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes deprecated async local file method #606

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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<LongRunningRecognizeResponse> response =
speech.longRunningRecognizeAsync(config, audio);
while (!response.isDone()) {
System.out.println("Waiting for response...");
Thread.sleep(200);
}

List<SpeechRecognitionResult> results = response.get().getResultsList();

for (SpeechRecognitionResult result: results) {
List<SpeechRecognitionAlternative> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down