melo/api.py: add a 'tts' iterator to greatly improve the response speed #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am going to make a simply assistant, it can play the sound generated by chatgpt. But most of the time chatgpt will return a bunch of text, and it will cost a lot of time to waiting for tts respone, that was annoying, for example:
In 'tts_to_file' function, the preprocessing process will try to split a long sentences into texts array. Then using model to interfence with each sentences and combine the result into finally audio array. But if the sentences is very very long, wait the entire process to be finished will cost lots of time, it is not a great idea. Most of the time, the interfence speed will extremely faster than playing speed, so use a iterator to get each of the audio piece.
Code Before (waiting 1.3s to get respone):
Code After (just waiting 0.2s to get respone):