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

Added setEnableWordTimeOffsets(true) to Async Recognize for a File #781

Conversation

dlaqab
Copy link

@dlaqab dlaqab commented Aug 1, 2017

Added setEnableWordTimeOffsets(true) to Async Recognize for a File
Added setEnableWordTimeOffsets(false) to Sync samples and quick start

Added setEnableWordTimeOffsets(false) to Sync samples and quick start
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Aug 1, 2017
@dlaqab
Copy link
Author

dlaqab commented Aug 1, 2017

I am covered by my current employer (Google)

@@ -127,6 +128,7 @@ public static void syncRecognizeGcs(String gcsUri) throws Exception, IOException
.setEncoding(AudioEncoding.FLAC)
.setLanguageCode("en-US")
.setSampleRateHertz(16000)
.setEnableWordTimeOffsets(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't false the default?

@@ -95,6 +95,7 @@ public static void syncRecognizeFile(String fileName) throws Exception, IOExcept
.setEncoding(AudioEncoding.LINEAR16)
.setLanguageCode("en-US")
.setSampleRateHertz(16000)
.setEnableWordTimeOffsets(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't false the default?

@@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this.

Copy link
Author

Choose a reason for hiding this comment

The 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

for (WordInfo wordInfo: alternative.getWordsList()) {
System.out.println(wordInfo.getWord());
System.out.printf("\t%s ns - %s ns\n",
wordInfo.getStartTime().getNanos(), wordInfo.getEndTime().getNanos());
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

@@ -50,6 +50,7 @@ public static void main(String... args) throws Exception {
.setEncoding(AudioEncoding.LINEAR16)
.setSampleRateHertz(16000)
.setLanguageCode("en-US")
.setEnableWordTimeOffsets(false)
Copy link
Contributor

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?

Copy link
Contributor

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?

Fixed the tests for WordTimeOffsets
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 2, 2017
@@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

          System.out.printf("\t%s.%s sec - %s.%s sec\n",
              wordInfo.getStartTime().getSeconds(),
              wordInfo.getStartTime().getNanos() / 100000000,
              wordInfo.getEndTime().getSeconds(),
              wordInfo.getEndTime().getNanos() / 100000000);
        }

Copy link
Author

Choose a reason for hiding this comment

The 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

Recognize.asyncRecognizeGcs(gcsPath);
String got = bout.toString();
assertThat(got).contains("\t0.0 sec -");
assertThat(got).contains("\t0 ns");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change when you correct the print output in asyncRecognizeFile

@gguuss
Copy link
Contributor

gguuss commented Aug 2, 2017

@dlaqab Please update your branch to match master, change your new code to match the updated start seconds / end seconds code as:

          System.out.printf("\t%s.%s sec - %s.%s sec\n",
              wordInfo.getStartTime().getSeconds(),
              wordInfo.getStartTime().getNanos() / 100000000,
              wordInfo.getEndTime().getSeconds(),
              wordInfo.getEndTime().getNanos() / 100000000);
        }

Revert your change in RecognizeIT to test for actual seconds / fractions of a second.

@gguuss
Copy link
Contributor

gguuss commented Aug 2, 2017

@lesv /FYI - Looks like the Circle tests are not running because this is on a personal fork of the repo. When I run the tests locally, the following is my output:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building speech-google-cloud-samples 1.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (default) @ speech-google-cloud-samples ---
[INFO] argLine set to -javaagent:/Users/class/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/class/temp/daryush/java-docs-samples/speech/cloud-client/target/jacoco.exec
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ speech-google-cloud-samples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ speech-google-cloud-samples ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ speech-google-cloud-samples ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ speech-google-cloud-samples ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.20:test (default-test) @ speech-google-cloud-samples ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.9:report (report) @ speech-google-cloud-samples ---
[INFO] Loading execution data file /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/target/jacoco.exec
[INFO] Analyzed bundle 'speech-google-cloud-samples' with 3 classes
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ speech-google-cloud-samples ---
[INFO]
[INFO] --- maven-failsafe-plugin:2.20:integration-test (default) @ speech-google-cloud-samples ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.speech.QuickstartSampleIT
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.831 s - in com.example.speech.QuickstartSampleIT
[INFO] Running com.example.speech.RecognizeIT
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 52.388 s - in com.example.speech.RecognizeIT
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 58.288 s
[INFO] Finished at: 2017-08-02T16:42:02-07:00
[INFO] Final Memory: 21M/376M
[INFO] ------------------------------------------------------------------------

Checkstyle shows:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building speech-google-cloud-samples 1.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-checkstyle-plugin:2.17:check (default-cli) @ speech-google-cloud-samples ---
[INFO] Starting audit...
[WARN] /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/main/java/com/example/speech/QuickstartSample.java:36:3: Missing a Javadoc comment. [JavadocMethod]
[WARN] /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/main/java/com/example/speech/Recognize.java:47:3: Missing a Javadoc comment. [JavadocMethod]
[WARN] /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/main/java/com/example/speech/Recognize.java:157:3: Missing a Javadoc comment. [JavadocMethod]
[WARN] /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/test/java/com/example/speech/QuickstartSampleIT.java:35: Abbreviation in name 'QuickstartSampleIT' must contain no more than '2' consecutive capital letters. [AbbreviationAsWordInName]
[WARN] /Users/class/temp/daryush/java-docs-samples/speech/cloud-client/src/test/java/com/example/speech/RecognizeIT.java:35: Abbreviation in name 'RecognizeIT' must contain no more than '2' consecutive capital letters. [AbbreviationAsWordInName]
Audit done.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.491 s
[INFO] Finished at: 2017-08-02T16:44:34-07:00
[INFO] Final Memory: 18M/308M
[INFO] ------------------------------------------------------------------------

So mostly LGTM, I'm just a little concerned about setting the optional parameter to its default value in the Quickstart still.

@lesv
Copy link
Contributor

lesv commented Aug 3, 2017

@gguuss I'll try to fix that tomorrow.

Copy link
Contributor

@gguuss gguuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we may want to at some point remove the .setEnableWordTimeOffsets(false) calls but reluctantly approving for today.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 3, 2017
@gguuss
Copy link
Contributor

gguuss commented Aug 3, 2017

I signed it!

Copy link
Contributor

@gguuss gguuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make change separately to match other samples.

@beccasaurus
Copy link

This can be closed.

@dlaqab
Copy link
Author

dlaqab commented Aug 4, 2017

why? I am not sure why this needs to be closed

@beccasaurus
Copy link

  1. The default for EnableWordTimeOffsets is false; it is incorrect to add it explicitly.
  2. None of the other languages do this, making Java inconsistent.

@beccasaurus beccasaurus self-requested a review August 4, 2017 04:01
@beccasaurus
Copy link

The setEnableWordTimeOffsets() call in these samples is extraneous to the task these samples are intended to demonstrate. Closing.

@beccasaurus beccasaurus closed this Aug 4, 2017
@beccasaurus
Copy link

Note: samples which demonstrate Enable Word Time Offsets were added to java-docs-samples in #787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants