GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Duplicate/combined word (lists) when using the response 'SpeechRecognitionResult' from longRunningRecognizeAsync · Issue #3903 · googleapis/google-cloud-java

Duplicate/combined word (lists) when using the response 'SpeechRecognitionResult' from longRunningRecognizeAsync #3903

New issue
Copy link
New issue
Copy link
Closed
Closed
Duplicate/combined word (lists) when using the response 'SpeechRecognitionResult' from longRunningRecognizeAsync#3903
Copy link
Assignees
codyoss
Labels
api: speechIssues related to the Speech-to-Text API.type: questionRequest for information or clarification. Not an issue.

Description

@JeroenAppel
JeroenAppel
opened on Nov 5, 2018
Issue body actions

When looping trough the 'SpeechRecognitionResult' objects, I noticed that the transcript attribute and the 'words_' list do not match for (at least) the last result. In our app, we always use the first and only alternative. I noticed that the word lists do match the transcript from the first few results, but for the last result, all words including the last one will be returned in words. I would expect that the last result only contains the words which are related to that specific transcript.

I assume this is a bug. If not; please advice.

Environment details

  • OS: Windows 10
  • Java version: 1.8.0_102
  • google-cloud-java version(s): google-cloud-speech-0.67.0-beta

Code snippet

In order to clarify this, I added a simplified code snippet below.

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

for (SpeechRecognitionResult result : results) {
     SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
     String transcript = alternative.getTranscript();
     for (WordInfo wordInfo : alternative.getWordsList()) {
           String word = wordInfo.getWord();
     }
}

In my current example, we have 3 results. The number of words are correct for the first two, but the third (last) is incorrect and includes all words from the whole text.

Result 0: Only the word Jaguar (both the transcript and the only word)
image

Result 1: A longer transcript, with 102 (correct) words in total
image

Result 2: A short transcript with only 23 words. As you can see, the list with words includes all 126 words (1+102+23).
image

Activity

  1. JustinBeckwith
    added
    triage meI really want to be triaged.
    on Nov 6, 2018
  2. chingor13
    added
    type: questionRequest for information or clarification. Not an issue.
    on Nov 7, 2018
  3. JustinBeckwith
    removed
    triage meI really want to be triaged.
    on Nov 7, 2018
  4. JeroenAppel commented on Nov 19, 2018

    @JeroenAppel
    JeroenAppel
    on Nov 19, 2018
    Author
    More actions

    Could some one from Google please have a look at this? The behavior is not consistent. The results were good for a few days, but now the duplicate list is back.

  5. JesseLovelace
    self-assigned this
    on Dec 3, 2018
  6. JesseLovelace commented on Dec 4, 2018

    @JesseLovelace
    JesseLovelace
    on Dec 4, 2018
    Contributor
    More actions

    Can you share your RecognitionConfig setup code?

  7. JesseLovelace commented on Dec 4, 2018

    @JesseLovelace
    JesseLovelace
    on Dec 4, 2018
    Contributor
    More actions

    I'm wondering if it's related to the fact that when EnableSpeakerDiarization is true, the words list is expected to contain all words from the beginning of the audio, even though the transcript does not.

    Related documentation: https://github.com/googleapis/google-cloud-java/blob/master/google-api-grpc/proto-google-cloud-speech-v1p1beta1/src/main/java/com/google/cloud/speech/v1p1beta1/SpeechRecognitionAlternative.java#L187

    If EnableSpeakerDiarization is set to true, can you set it to false and see if you experience the same problem?

    Reacted by Jeroen Appel
  8. JesseLovelace commented on Dec 4, 2018

    @JesseLovelace
    JesseLovelace
    on Dec 4, 2018
    Contributor
    More actions

    Some additional documentation: https://github.com/googleapis/google-cloud-java/blob/master/google-api-grpc/proto-google-cloud-speech-v1p1beta1/src/main/java/com/google/cloud/speech/v1p1beta1/RecognitionConfig.java#L965

  9. JeroenAppel commented on Dec 6, 2018

    @JeroenAppel
    JeroenAppel
    on Dec 6, 2018
    Author
    More actions

    Thanks for the update Jesse. While experimenting with your suggestions and reading the additional documentation, I can verify that the behavior is now explainable and consistent. The RecognitionConfig will be set by the end user (see the screenshot for an impression).

    When the Speaker Diarization has been set to false, the results are fine. However the behavior is now explainable when set to true, I still think that this is not a preferable way of working with the response. We use the first and the last word in order to determine the start and end of a sentence, because there are no such fields on the 'alternative' level. In addition to that, we store the sentences and associated words altogether in our database. This is required in order to our front-end application. If we want to achieve this now, it feels like we need to build some custom logic to determine which words underneath the alternative are really part of that sentence.

    Hopefully this explains our setup. Thanks for your clarification so far. We are happy to hear your thoughts on this.

    2018-12-06 15_08_41

  10. JesseLovelace commented on Dec 6, 2018

    @JesseLovelace
    JesseLovelace
    on Dec 6, 2018
    Contributor
    More actions

    I agree that the behavior is a little strange and unintuitive, I can start a discussion with the Speech team to see if it can be re-thought, or if there's a workaround in place that I'm not aware of.

    In the meantime, maybe a workaround could be to keep track of the word counts given in previous iterations, and on the last one get the relevant portion using List.subList()?

    You may have tried this, but the code you provided in the original question could be replaced by something like this.

    List<SpeechRecognitionResult> results = response.getResultsList();
    Iterator<SpeechRecognitionResult> i = results.iterator();
    int wordsCounted = 0;
    while(i.hasNext()) {
      SpeechRecognitionResult result = i.next();
      SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
      String transcript = alternative.getTranscript();
      List<WordInfo> words;
      if (i.hasNext() || !config.getEnableSpeakerDiarization()) {
        wordsCounted += alternative.getWordsCount();
        words = alternative.getWordsList();
      } else {
        words = alternative.getWordsList().subList(wordsCounted, alternative.getWordsCount());
      }
      for (WordInfo wordInfo : words) {
        String word = wordInfo.getWord();
      }
    }
    Reacted by Jeroen Appel
  11. JeroenAppel commented on Dec 10, 2018

    @JeroenAppel
    JeroenAppel
    on Dec 10, 2018
    Author
    More actions

    Thanks for the update and workaround @JesseLovelace For now, it looks like this is working for our implementation. I am now able to set the correct start- and end time.

    If there are any updates on a final 'solution' or a more intuitive way of working with the responses, I will be happy to hear about that in the future. For now, thanks for your support.

  12. JesseLovelace commented on Jan 15, 2019

    @JesseLovelace
    JesseLovelace
    on Jan 15, 2019
    Contributor
    More actions

    @beccasaurus FYI

  13. sduskis
    added
    api: speechIssues related to the Speech-to-Text API.
    on Mar 8, 2019
  14. JesseLovelace
    removed their assignment
    on Jun 10, 2019
  15. codyoss commented on Dec 3, 2019

    @codyoss
    codyoss
    on Dec 3, 2019
    Member
    More actions

    Closing issue as it seem the original question has been answered. If you would like a feature request for the service itself I would suggest opening up a ticket with the GCP Public Issue Tracker.

  16. codyoss
    closed this as completedon Dec 3, 2019
  17. JustinBeckwith
    assigned
    codyoss
    on Feb 1, 2021
  18. suztomo
    added a commit that references this issue on Mar 9, 2026

    deps: update dependency io.opentelemetry:opentelemetry-bom to v1.52.0 (…

    509a6fc
  19. lqiu96
    added a commit that references this issue on Mar 20, 2026

    deps: update dependency io.opentelemetry:opentelemetry-bom to v1.52.0 (…

    94cc7be
  20. chingor13
    added a commit that references this issue on Mar 24, 2026

    chore(main): release 2.62.2 (#3903)

    afbb1dc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @codyoss
    codyoss

Labels

api: speechIssues related to the Speech-to-Text API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.