CosyVoice icon indicating copy to clipboard operation
CosyVoice copied to clipboard

inference_instruct2 missing 1 required positional argument: 'zero_shot_spk_id'

Open jianlong918 opened this issue 8 months ago • 4 comments

import sys sys.path.append('third_party/Matcha-TTS') from cosyvoice.cli.cosyvoice import CosyVoice, CosyVoice2 from cosyvoice.utils.file_utils import load_wav import torchaudio

cosyvoice = CosyVoice2('pretrained_models/CosyVoice2-0.5B', load_jit=False, load_trt=False, fp16=False)

tts_text = '四十岁后才知道,朋友就像柜子里的"老茶饼。' instruct_text = '用情感电台的主持人的语气有感情的说'
prompttext = '但是刘备先生的坚持和热情打动了我,他的三次拜访让我决定出山,与他共谋天下大计,这就是我传奇一生的开始。' prompt_speech_16k = load_wav('asset/xiaoyu.wav', 16000)

assert cosyvoice.add_zero_shot_spk(prompttext, prompt_speech_16k, 'my_zero_shot_spk') is True for i, j in enumerate(cosyvoice.inference_zero_shot(tts_text, '', '', zero_shot_spk_id='my_zero_shot_spk', stream=False)): torchaudio.save('zero_shot_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate) cosyvoice.save_spkinfo()

for i, j in enumerate(cosyvoice.inference_instruct2(tts_text, instruct_text, prompt_speech_16k, stream=False)): torchaudio.save('instruct_{}.wav'.format(i), j['tts_speech'], cosyvoice.sample_rate)

第一个音频可以正常生成,第二个报错

Traceback (most recent call last): File "E:\AiProgram\cosyvoice\CosyVoice\test.py", line 20, in for i, j in enumerate(cosyvoice.inference_instruct2(tts_text, instruct_text, prompt_speech_16k, stream=False)): File "E:\AiProgram\cosyvoice\CosyVoice\cosyvoice\cli\cosyvoice.py", line 183, in inference_instruct2 model_input = self.frontend.frontend_instruct2(i, instruct_text, prompt_speech_16k, self.sample_rate) File "E:\AiProgram\cosyvoice\CosyVoice\cosyvoice\cli\frontend.py", line 200, in frontend_instruct2 model_input = self.frontend_zero_shot(tts_text, instruct_text + '<|endofprompt|>', prompt_speech_16k, resample_rate) TypeError: CosyVoiceFrontEnd.frontend_zero_shot() missing 1 required positional argument: 'zero_shot_spk_id'

jianlong918 avatar Apr 20 '25 13:04 jianlong918

遇到了相同的问题 CosyVoiceFrontEnd.frontend_zero_shot() missing 1 required positional argument: 'zero_shot_spk_id'

lllmx-GH avatar Apr 21 '25 03:04 lllmx-GH

我也遇到了,在frontend.py里面的frontend instruct2函数加个空字符串参数临时解决了。 def frontend_instruct2(self, tts_text, instruct_text, prompt_speech_16k, resample_rate): model_input = self.frontend_zero_shot(tts_text, instruct_text + '<|endofprompt|>', prompt_speech_16k, resample_rate,"")#结尾加了个空的字符串参数 del model_input['llm_prompt_speech_token'] del model_input['llm_prompt_speech_token_len'] return model_input

pan17 avatar Apr 22 '25 00:04 pan17

我也遇到了,在frontend.py里面的frontend instruct2函数加个空字符串参数临时解决了。 def frontend_instruct2(self, tts_text, instruct_text, prompt_speech_16k, resample_rate): model_input = self.frontend_zero_shot(tts_text, instruct_text + '<|endofprompt|>', prompt_speech_16k, resample_rate,"")#结尾加了个空的字符串参数 del model_input['llm_prompt_speech_token'] del model_input['llm_prompt_speech_token_len'] return model_input

有用,感谢~~~~~~~~~~~~~~

wukongbuku avatar Apr 27 '25 11:04 wukongbuku

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 28 '25 02:05 github-actions[bot]