add cosyvoice3 inference code

This commit is contained in:
lyuxiang.lx
2025-12-08 10:04:11 +00:00
parent 622a3a19b0
commit bfa835a74b
4 changed files with 135 additions and 86 deletions

View File

@@ -182,7 +182,7 @@ class CosyVoice2(CosyVoice):
raise NotImplementedError('inference_instruct is not implemented for CosyVoice2!')
def inference_instruct2(self, tts_text, instruct_text, prompt_wav, zero_shot_spk_id='', stream=False, speed=1.0, text_frontend=True):
assert isinstance(self.model, CosyVoice2Model), 'inference_instruct2 is only implemented for CosyVoice2!'
assert isinstance(self.model, CosyVoice2Model) or isinstance(self.model, CosyVoice3Model), 'inference_instruct2 is only implemented for CosyVoice2 and CosyVoice3!'
for i in tqdm(self.frontend.text_normalize(tts_text, split=True, text_frontend=text_frontend)):
model_input = self.frontend.frontend_instruct2(i, instruct_text, prompt_wav, self.sample_rate, zero_shot_spk_id)
start_time = time.time()
@@ -194,7 +194,7 @@ class CosyVoice2(CosyVoice):
start_time = time.time()
class CosyVoice3(CosyVoice):
class CosyVoice3(CosyVoice2):
def __init__(self, model_dir, load_jit=False, load_trt=False, load_vllm=False, fp16=False, trt_concurrent=1):
self.instruct = True if '-Instruct' in model_dir else False