mirror of
https://github.com/FunAudioLLM/CosyVoice.git
synced 2026-02-05 18:09:24 +08:00
add cosyvoice3 inference code
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -25,6 +25,32 @@ import torch
|
||||
|
||||
IGNORE_ID = -1
|
||||
|
||||
instruct_list = ["You are a helpful assistant. 请用广东话表达。",
|
||||
"You are a helpful assistant. 请用东北话表达。",
|
||||
"You are a helpful assistant. 请用甘肃话表达。",
|
||||
"You are a helpful assistant. 请用贵州话表达。",
|
||||
"You are a helpful assistant. 请用河南话表达。",
|
||||
"You are a helpful assistant. 请用湖北话表达。",
|
||||
"You are a helpful assistant. 请用湖南话表达。",
|
||||
"You are a helpful assistant. 请用江西话表达。",
|
||||
"You are a helpful assistant. 请用闽南话表达。",
|
||||
"You are a helpful assistant. 请用宁夏话表达。",
|
||||
"You are a helpful assistant. 请用山西话表达。",
|
||||
"You are a helpful assistant. 请用陕西话表达。",
|
||||
"You are a helpful assistant. 请用山东话表达。",
|
||||
"You are a helpful assistant. 请用上海话表达。",
|
||||
"You are a helpful assistant. 请用四川话表达。",
|
||||
"You are a helpful assistant. 请用天津话表达。",
|
||||
"You are a helpful assistant. 请用云南话表达。",
|
||||
"You are a helpful assistant. Please say a sentence as loudly as possible.",
|
||||
"You are a helpful assistant. Please say a sentence in a very soft voice.",
|
||||
"You are a helpful assistant. 请用尽可能慢地语速说一句话。",
|
||||
"You are a helpful assistant. 请用尽可能快地语速说一句话。",
|
||||
"You are a helpful assistant. 请非常开心地说一句话。",
|
||||
"You are a helpful assistant. 请非常伤心地说一句话。",
|
||||
"You are a helpful assistant. 请非常生气地说一句话。",
|
||||
"You are a helpful assistant. 我想体验一下小猪佩奇风格,可以吗?",
|
||||
"You are a helpful assistant. 你可以尝试用机器人的方式解答吗?"]
|
||||
|
||||
def pad_list(xs: List[torch.Tensor], pad_value: int):
|
||||
"""Perform padding for the list of tensors.
|
||||
|
||||
Reference in New Issue
Block a user