Skip to content

[Fix] asr finished in on_event#69

Merged
kevinlin09 merged 1 commit intodashscope:mainfrom
lengjiayi:asr_fix_finished
Oct 29, 2025
Merged

[Fix] asr finished in on_event#69
kevinlin09 merged 1 commit intodashscope:mainfrom
lengjiayi:asr_fix_finished

Conversation

@lengjiayi
Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @lengjiayi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue in the Automatic Speech Recognition (ASR) module where the completion of a recognition segment might not be accurately detected. The change enhances the termination condition to account for cases where the output stream contains data but explicitly signals completion, ensuring more robust and reliable ASR processing.

Highlights

  • ASR Completion Logic: Modified the ASR recognition logic to correctly detect when a recognition part is finished. Previously, it only checked for an empty output; now it also checks for an explicit 'finished: True' flag within the output, ensuring proper termination handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @lengjiayi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the Automatic Speech Recognition (ASR) module where the completion of an ASR task might not have been correctly detected in all scenarios. The change ensures that the system accurately recognizes when an ASR process has finished, either by receiving an empty output or an explicit 'finished' flag, leading to more reliable timestamping of completion events.

Highlights

  • ASR Completion Logic: Modified the condition for detecting Automatic Speech Recognition (ASR) completion to include explicit 'finished' flags in the output, alongside checking for empty output.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request modifies the __receive_worker method in dashscope/audio/asr/recognition.py to include an additional condition for completing the audio stream. Specifically, it checks if the 'finished' key exists in part.output and if its value is True. This change ensures that the audio stream completes when the server explicitly signals the end of the stream, in addition to the existing check for an empty output.

for part in responses:
if part.status_code == HTTPStatus.OK:
if len(part.output) == 0:
if len(part.output) == 0 or ('finished' in part.output and part.output['finished'] == True):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The current logic uses or which might lead to unexpected behavior. If len(part.output) == 0 is false but the second condition 'finished' in part.output and part.output['finished'] == True is true, the code will still proceed as if the condition is met. This could potentially cause issues if the intention is to only complete when both conditions are true. It is recommended to use and to ensure both conditions are met before proceeding.

Consider changing or to and to ensure that the complete timestamp is only set when both the output is empty and the 'finished' flag is present and true.

Suggested change
if len(part.output) == 0 or ('finished' in part.output and part.output['finished'] == True):
if len(part.output) == 0 and ('finished' in part.output and part.output['finished'] == True):

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a fix in the ASR recognition worker to correctly handle the end of a task. The change adds a condition to check for a finished: true flag in the server response. My review includes a suggestion to refactor this condition for better readability and to adhere to Python best practices, making the code more concise and maintainable.

for part in responses:
if part.status_code == HTTPStatus.OK:
if len(part.output) == 0:
if len(part.output) == 0 or ('finished' in part.output and part.output['finished'] == True):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The condition to check for completion can be simplified to be more concise and idiomatic Python.

  • Checking for an empty dictionary can be done with not part.output.
  • Checking for the presence and truthiness of the 'finished' key can be done with part.output.get('finished'). This avoids verbose key existence checks.
  • Comparing a boolean value with == True is generally discouraged.1

This makes the code more readable and maintainable.

Suggested change
if len(part.output) == 0 or ('finished' in part.output and part.output['finished'] == True):
if not part.output or part.output.get('finished'):

Style Guide References

Footnotes

  1. PEP 8 advises against comparing boolean values to True or False using ==.

@kevinlin09 kevinlin09 merged commit a26ab52 into dashscope:main Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants