File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
+ import re
2
3
import sys
3
4
import wave
4
5
import numpy as np
@@ -39,19 +40,32 @@ def __init__(
39
40
self ._voices = None
40
41
self ._model = None
41
42
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
42
51
43
52
def load (self ):
44
53
for path in paths_to_insert :
45
54
sys .path .insert (0 , path )
46
55
47
- from cosyvoice .cli .cosyvoice import CosyVoice as CosyVoiceModel
48
-
49
56
if self .model_load :
50
57
return self
51
58
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
54
61
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 ()
55
69
self ._model_dict = create_model_dict (
56
70
self ._cfg .model ,
57
71
task_type = TaskTypeEnum .TTS ,
You can’t perform that action at this time.
0 commit comments