Skip to content

(model/cosyvoice): support flush api#212

Closed
songguocola wants to merge 1 commit into
dashscope:mainfrom
songguocola:audio_0511
Closed

(model/cosyvoice): support flush api#212
songguocola wants to merge 1 commit into
dashscope:mainfrom
songguocola:audio_0511

Conversation

@songguocola
Copy link
Copy Markdown
Contributor

No description provided.

@songguocola songguocola deleted the audio_0511 branch May 11, 2026 11:40
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 introduces a TextStreamItem class to encapsulate both text and flush commands within the speech synthesis stream, replacing the previous String-based flow. It adds streamingFlush methods to support flushing the stream with optional parameters and updates the internal RxJava pipeline to handle these new items. A potential race condition was identified regarding the mutable JsonObject parameters in TextStreamItem, where it is recommended to perform a deep copy to ensure data consistency during asynchronous processing.

Comment on lines +790 to +794
public TextStreamItem(boolean flush, JsonObject params) {
this.text = null;
this.flush = flush;
this.params = params;
}
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 JsonObject passed as params is a mutable object. Since the serialization of this item occurs asynchronously in the RxJava stream (within the getStreamingData method), any modifications made to the params object by the caller after calling streamingFlush but before the message is actually processed and sent could lead to race conditions or inconsistent data. It is safer to store a deep copy of the parameters to ensure the state is captured at the moment of the call.

Suggested change
public TextStreamItem(boolean flush, JsonObject params) {
this.text = null;
this.flush = flush;
this.params = params;
}
public TextStreamItem(boolean flush, JsonObject params) {
this.text = null;
this.flush = flush;
this.params = params != null ? params.deepCopy() : null;
}

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.

1 participant