-
Notifications
You must be signed in to change notification settings - Fork 1.5k
when mode is 2pass and test audio is vad_example.wav, we should give … #2772
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
Conversation
Summary of ChangesHello @AllenDou, 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 intermittent issue in the WebSocket client where the connection would sometimes close before all messages could be received, leading to exceptions. By strategically adding a short asynchronous delay before the connection closure, the change ensures that the client has ample time to process incoming data, thereby enhancing the stability and reliability of the WebSocket communication during specific test scenarios. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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
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 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
|
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.
Code Review
This pull request aims to fix a race condition in 2pass mode where the websocket connection is closed before the final message is received. It does so by adding a fixed 5-second sleep. While this may resolve the issue for the specific test case, it's not a robust solution. My review provides a more reliable synchronization mechanism using the existing offline_msg_done flag, which avoids both race conditions and unnecessary delays. This involves a small change in the message function to signal completion and replacing the hardcoded sleep with a conditional wait loop.
| while not offline_msg_done: | ||
| await asyncio.sleep(1) | ||
|
|
||
| await asyncio.sleep(5) |
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.
Using a hardcoded sleep is not a robust way to handle synchronization. The time needed for the server to process and return the final message can vary based on server load, network conditions, and the length of the audio. This can lead to either unnecessary delays or race conditions if the sleep duration is too short.
A more reliable approach is to use an explicit synchronization mechanism. The offline_msg_done flag is already used for this in offline mode. You can extend this to 2pass mode.
First, you'll need to modify the message function to set offline_msg_done = True when it receives the final 2pass-offline result. This is the message that has is_final: False.
# In funasr_wss_client.py, message()
...
else: # 2pass mode
if meg["mode"] == "2pass-online":
...
else: # 2pass-offline
...
print("\rpid" + str(id) + ": " + text_print)
# The final message in 2-pass mode will have 'is_final': False.
if not meg.get("is_final", True):
global offline_msg_done
offline_msg_done = TrueThen, you can replace the hardcoded sleep with a loop that waits for offline_msg_done to be set when in 2pass mode, ideally with a timeout.
| await asyncio.sleep(5) | |
| if args.mode == "2pass": | |
| # Wait for the final message. This requires a change in the `message` function. | |
| timeout = 10 # seconds | |
| while not offline_msg_done and timeout > 0: | |
| await asyncio.sleep(1) | |
| timeout -= 1 | |
| else: | |
| await asyncio.sleep(5) |
…more time to websocket connection to recv message, or funasr_wss_client.py's websocket.recv() will cause exception occasionally because connection has been closed.
when mode is 2pass and test audio is vad_example.wav, we should give more time to websocket connection to recv message, or funasr_wss_client.py's websocket.recv() will cause exception occasionally because connection has been closed.