-
Notifications
You must be signed in to change notification settings - Fork 22
(feat:model/cosyvoice):use new protocol to build websocket connection #188
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 @songguocola, 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 fundamentally changes how audio services, particularly speech synthesis, establish and manage their network connections. By introducing a dedicated WebSocket protocol layer, it aims to provide a more robust and efficient mechanism for real-time audio data exchange. This refactoring centralizes WebSocket logic, making the 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. Changelog
Activity
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 introduces a new WebSocket protocol for CosyVoice speech synthesis. While a security audit found no vulnerabilities of medium severity or higher, the code review identified several areas for improvement. These include concerns regarding thread safety, exception handling (e.g., potential null pointer exceptions and improper InterruptedException handling), and critical flaws in the test implementation. Addressing these issues will enhance the robustness and reliability of the new functionality.
| public void onClosed(WebSocket webSocket, int code, String reason) { | ||
| isOpen.set(false); | ||
| isClosed.set(true); | ||
| connectLatch.get().countDown(); |
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.
The call to connectLatch.get() could result in a NullPointerException if onClosed is called before connect() has initialized the latch. It's safer to add a null check, similar to what's done in onFailure.
| connectLatch.get().countDown(); | |
| if (connectLatch.get() != null) { | |
| connectLatch.get().countDown(); | |
| } |
src/main/java/com/alibaba/dashscope/audio/protocol/AudioWebsocketRequest.java
Show resolved
Hide resolved
| } catch (InterruptedException ignored) { | ||
| log.error("Interrupted while waiting for streaming complete"); | ||
| } |
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.
Catching InterruptedException and not restoring the thread's interrupted status can lead to subtle and hard-to-debug issues, especially in concurrent code. The interrupted flag should be restored by calling Thread.currentThread().interrupt(). This is handled correctly in other parts of this class, like in streamingCall.
} catch (InterruptedException e) {
log.error("Interrupted while waiting for streaming complete", e);
Thread.currentThread().interrupt();
}
src/main/java/com/alibaba/dashscope/audio/protocol/AudioWebsocketRequest.java
Show resolved
Hide resolved
| * Accumulates audio data to audioStream. Reuses existing buffer when possible to minimize | ||
| * allocations. | ||
| */ | ||
| private void accumulateAudioData(ByteBuffer frame) throws Exception { |
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.
The method signature declares throws Exception, which is too broad. The only checked exception that can be thrown from the method body is IOException from audioStream.write(). It's better to declare the specific exception, throws IOException, for better error handling and code clarity.
| private void accumulateAudioData(ByteBuffer frame) throws Exception { | |
| private void accumulateAudioData(ByteBuffer frame) throws java.io.IOException { |
| callback.onComplete(); | ||
| } | ||
| if (audioStream != null) { | ||
| audioStream.reset(); // 重置 ByteArrayOutputStream,清空数据但保留缓冲区 |
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.
The comment is in Chinese, while the rest of the code and comments are in English. For consistency and to make it understandable for a wider audience, please translate the comment to English.
| audioStream.reset(); // 重置 ByteArrayOutputStream,清空数据但保留缓冲区 | |
| audioStream.reset(); // Reset ByteArrayOutputStream, clear data but keep the buffer |
| public void onMessage(WebSocket webSocket, String string) { | ||
| System.out.println("mock server recv: " + string); | ||
| JsonObject req = JsonUtils.parse(string); | ||
| if (task_id == "") { |
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.
No description provided.