-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Added setEnableWordTimeOffsets(true) to Async Recognize for a File #781
Changes from 2 commits
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) | ||
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) | ||
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) | ||
|
@@ -185,7 +188,12 @@ public static void asyncRecognizeFile(String fileName) throws Exception, IOExcep | |
for (SpeechRecognitionResult result: results) { | ||
List<SpeechRecognitionAlternative> alternatives = result.getAlternativesList(); | ||
for (SpeechRecognitionAlternative alternative: alternatives) { | ||
System.out.printf("Transcription: %s%n", alternative.getTranscript()); | ||
System.out.printf("Transcription: %s\n",alternative.getTranscript()); | ||
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. This should be:
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. This line shows the all up transcript - lines bellow it are iterating through the words and displaying the start and end time stamps |
||
for (WordInfo wordInfo: alternative.getWordsList()) { | ||
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. 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()); | ||
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. 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. 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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,10 +84,17 @@ public void testAsyncRecognizeGcs() throws Exception { | |
} | ||
|
||
@Test | ||
public void testAsyncWordoffset() throws Exception { | ||
public void testAsyncWordoffsetFile() throws Exception { | ||
Recognize.asyncRecognizeFile(fileName); | ||
String got = bout.toString(); | ||
assertThat(got).contains("\t0 ns"); | ||
} | ||
|
||
@Test | ||
public void testAsyncWordoffsetGcs() throws Exception { | ||
Recognize.asyncRecognizeGcs(gcsPath); | ||
String got = bout.toString(); | ||
assertThat(got).contains("\t0.0 sec -"); | ||
assertThat(got).contains("\t0 ns"); | ||
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. Revert this change when you correct the print output in |
||
} | ||
|
||
@Test | ||
|
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?