-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added setEnableWordTimeOffsets(true) to Async Recognize for a File #781
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
Changes from 1 commit
1e4cf44
a893740
29f9f76
e4a7cce
3384179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,7 @@ public static void syncRecognizeFile(String fileName) throws Exception, IOExcept | |
| .setEncoding(AudioEncoding.LINEAR16) | ||
| .setLanguageCode("en-US") | ||
| .setSampleRateHertz(16000) | ||
| .setEnableWordTimeOffsets(false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't false the default? |
||
| .build(); | ||
| RecognitionAudio audio = RecognitionAudio.newBuilder() | ||
| .setContent(audioBytes) | ||
|
|
@@ -127,6 +128,7 @@ public static void syncRecognizeGcs(String gcsUri) throws Exception, IOException | |
| .setEncoding(AudioEncoding.FLAC) | ||
| .setLanguageCode("en-US") | ||
| .setSampleRateHertz(16000) | ||
| .setEnableWordTimeOffsets(false) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't false the default? |
||
| .build(); | ||
| RecognitionAudio audio = RecognitionAudio.newBuilder() | ||
| .setUri(gcsUri) | ||
|
|
@@ -165,6 +167,7 @@ public static void asyncRecognizeFile(String fileName) throws Exception, IOExcep | |
| .setEncoding(AudioEncoding.LINEAR16) | ||
| .setLanguageCode("en-US") | ||
| .setSampleRateHertz(16000) | ||
| .setEnableWordTimeOffsets(true) | ||
| .build(); | ||
| RecognitionAudio audio = RecognitionAudio.newBuilder() | ||
| .setContent(audioBytes) | ||
|
|
@@ -186,6 +189,11 @@ public static void asyncRecognizeFile(String fileName) throws Exception, IOExcep | |
| List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList(); | ||
| for (SpeechRecognitionAlternative alternative: alternatives) { | ||
| System.out.printf("Transcription: %s%n", alternative.getTranscript()); | ||
| for (WordInfo wordInfo: alternative.getWordsList()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test for this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I added the test. I also fixed the test failure in AsyncRecognizeGcs test, so all the tests should pass now |
||
| System.out.println(wordInfo.getWord()); | ||
| System.out.printf("\t%s ns - %s ns\n", | ||
| wordInfo.getStartTime().getNanos(), wordInfo.getEndTime().getNanos()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're missing seconds, this just shows the nanoseconds for portions of the response.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the other async sample to correctly show the seconds and nanos calculated to second fractions.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your original code did not have seconds, and I did not change the "pretty print" to show seconds. |
||
| } | ||
| } | ||
| } | ||
| speech.close(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this superfluous as false is the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure we don't want to set an optional parameter to its default value in the quickstart example. Thoughts?