Skip to content

Commit a06952d

Browse files
committed
feat: support cosyvoice2
1 parent 4a18b1a commit a06952d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

vox_box/backends/tts/cosyvoice.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import sys
34
import wave
45
import numpy as np
@@ -39,19 +40,32 @@ def __init__(
3940
self._voices = None
4041
self._model = None
4142
self._model_dict = {}
43+
self._is_cosyvoice_v2 = False
44+
45+
cosyvoice_yaml_path = os.path.join(self._cfg.model, "cosyvoice.yaml")
46+
if os.path.exists(cosyvoice_yaml_path):
47+
with open(cosyvoice_yaml_path, "r", encoding="utf-8") as f:
48+
content = f.read()
49+
if re.search(r"Qwen2", content, re.IGNORECASE):
50+
self._is_cosyvoice_v2 = True
4251

4352
def load(self):
4453
for path in paths_to_insert:
4554
sys.path.insert(0, path)
4655

47-
from cosyvoice.cli.cosyvoice import CosyVoice as CosyVoiceModel
48-
4956
if self.model_load:
5057
return self
5158

52-
self._model = CosyVoiceModel(self._cfg.model)
53-
self._voices = self._get_voices()
59+
if self._is_cosyvoice_v2:
60+
from cosyvoice.cli.cosyvoice import CosyVoice2 as CosyVoiceModel2
5461

62+
self._model = CosyVoiceModel2(self._cfg.model, load_jit=True)
63+
else:
64+
from cosyvoice.cli.cosyvoice import CosyVoice as CosyVoiceModel
65+
66+
self._model = CosyVoiceModel(self._cfg.model, load_jit=True)
67+
68+
self._voices = self._get_voices()
5569
self._model_dict = create_model_dict(
5670
self._cfg.model,
5771
task_type=TaskTypeEnum.TTS,

0 commit comments

Comments
 (0)