(model/cosyvoice): support flush api#212
Conversation
There was a problem hiding this comment.
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.
| public TextStreamItem(boolean flush, JsonObject params) { | ||
| this.text = null; | ||
| this.flush = flush; | ||
| this.params = params; | ||
| } |
There was a problem hiding this comment.
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.
| 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; | |
| } |
No description provided.