Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -16,6 +16,14 @@ from huggingface_hub import hf_hub_download
16
  # 繁简转换
17
  converter = opencc.OpenCC('s2t.json')
18
 
 
 
 
 
 
 
 
 
19
  # 加载模型
20
  cosyvoice_base = CosyVoice2(
21
  'ASLP-lab/Cosyvoice2-Yue',
@@ -33,18 +41,24 @@ print('load model 2')
33
  # )
34
 
35
  @spaces.GPU
36
- def tts_inference(model_choice, text, prompt_audio):
37
  # 选择模型和默认音频
38
- if model_choice == "CosyVoice2-张悦楷粤语评书":
39
  model = cosyvoice_zjg
40
  prompt_audio = "asset/sg_017_090.wav"
41
  elif model_choice == "CosyVoice2-精品女音":
42
  model = cosyvoice_base
43
  prompt_audio = "asset/F01_中立_20054.wav"
44
- elif model_choice == "CosyVoice2-base":
45
  model = cosyvoice_base
46
- if prompt_audio is None:
47
- return None, "请上传参考音频"
 
 
 
 
 
 
48
  else:
49
  return None, "未知模型"
50
 
@@ -74,13 +88,18 @@ demo = gr.Interface(
74
  fn=tts_inference,
75
  inputs=[
76
  gr.Dropdown(
77
- ["CosyVoice2-base", "CosyVoice2-张悦楷粤语评书"],
78
  # ["CosyVoice2-base", "CosyVoice2-张悦楷粤语评书", "CosyVoice2-精品女音"],
79
- label="选择模型", value="CosyVoice2-base"
 
 
 
 
 
 
80
  ),
81
- gr.Textbox(lines=2, label="输入文本"),
82
- # gr.Audio(source="upload", type="filepath", label="上传参考音频(仅 CosyVoice2-base 必需)")
83
- gr.Audio(sources=["upload"], type="filepath", label="上传参考音频(仅 CosyVoice2-base 必需)")
84
  ],
85
  outputs=[
86
  gr.Audio(type="numpy", label="生成的语音"),
 
16
  # 繁简转换
17
  converter = opencc.OpenCC('s2t.json')
18
 
19
+ # 预设参考音频选项
20
+ PRESET_AUDIO_OPTIONS = {
21
+ "ZoengJyutGaai": "asset/张悦楷.wav",
22
+ "Trump": "asset/特朗普.wav",
23
+ "Taiyi Zhenren": "asset/太乙真人.wav",
24
+ "自定义上传": None
25
+ }
26
+
27
  # 加载模型
28
  cosyvoice_base = CosyVoice2(
29
  'ASLP-lab/Cosyvoice2-Yue',
 
41
  # )
42
 
43
  @spaces.GPU
44
+ def tts_inference(model_choice, text, preset_audio_choice, prompt_audio):
45
  # 选择模型和默认音频
46
+ if model_choice == "CosyVoice2-Yue-ZoengJyutGaai":
47
  model = cosyvoice_zjg
48
  prompt_audio = "asset/sg_017_090.wav"
49
  elif model_choice == "CosyVoice2-精品女音":
50
  model = cosyvoice_base
51
  prompt_audio = "asset/F01_中立_20054.wav"
52
+ elif model_choice == "CosyVoice2-Yue":
53
  model = cosyvoice_base
54
+ if preset_audio_choice == "自定义上传":
55
+ if custom_audio is None:
56
+ return None, "请上传参考音频或选择预设音频"
57
+ prompt_audio = custom_audio
58
+ else:
59
+ prompt_audio = PRESET_AUDIO_OPTIONS[preset_audio_choice]
60
+ if prompt_audio is None:
61
+ return None, "请选择有效的参考音频"
62
  else:
63
  return None, "未知模型"
64
 
 
88
  fn=tts_inference,
89
  inputs=[
90
  gr.Dropdown(
91
+ ["CosyVoice2-Yue", "CosyVoice2-Yue-ZoengJyutGaai"],
92
  # ["CosyVoice2-base", "CosyVoice2-张悦楷粤语评书", "CosyVoice2-精品女音"],
93
+ label="select model", value="CosyVoice2-Yue"
94
+ ),
95
+ gr.Textbox(lines=2, label="input text"),
96
+ gr.Dropdown(
97
+ choices=list(PRESET_AUDIO_OPTIONS.keys()),
98
+ value="ZoengJyutGaai",
99
+ label="please select audio options(only for CosyVoice2-Yue)"
100
  ),
101
+ # gr.Audio(source="upload", type="filepath", label="上传参考音频(仅 CosyVoice2-Yue 必需)")
102
+ gr.Audio(sources=["upload"], type="filepath", label="upload prompt audio(only for CosyVoice2-Yue)")
 
103
  ],
104
  outputs=[
105
  gr.Audio(type="numpy", label="生成的语音"),