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.
# This API can still be use
audio = model.tts_to_file(text, speaker_ids['ZH'], speed=speed)
# or
for audio in model.tts_iter(x, speaker_ids['ZH'], speed=speed):
play_audio(audio)
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):