Ram commited on
Commit
0966596
·
1 Parent(s): e6265db

Use speech_tokenizer_v3.onnx for CosyVoiceFrontEnd

Browse files
Files changed (1) hide show
  1. cosyvoice/cli/frontend.py +26 -13
cosyvoice/cli/frontend.py CHANGED
@@ -26,26 +26,39 @@ import inflect
26
  from cosyvoice.utils.file_utils import logging, load_wav
27
  from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph, is_only_punctuation
28
 
29
-
30
  class CosyVoiceFrontEnd:
31
-
32
- def __init__(self,
33
- get_tokenizer: Callable,
34
- feat_extractor: Callable,
35
- campplus_model: str,
36
- speech_tokenizer_model: str,
37
- spk2info: str = '',
38
- allowed_special: str = 'all'):
 
39
  self.tokenizer = get_tokenizer()
40
  self.feat_extractor = feat_extractor
41
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
42
  option = onnxruntime.SessionOptions()
43
  option.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL
44
  option.intra_op_num_threads = 1
45
- self.campplus_session = onnxruntime.InferenceSession(campplus_model, sess_options=option, providers=["CPUExecutionProvider"])
46
- self.speech_tokenizer_session = onnxruntime.InferenceSession(speech_tokenizer_model, sess_options=option,
47
- providers=["CUDAExecutionProvider" if torch.cuda.is_available() else
48
- "CPUExecutionProvider"])
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  if os.path.exists(spk2info):
50
  self.spk2info = torch.load(spk2info, map_location=self.device, weights_only=True)
51
  else:
 
26
  from cosyvoice.utils.file_utils import logging, load_wav
27
  from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph, is_only_punctuation
28
 
 
29
  class CosyVoiceFrontEnd:
30
+ def __init__(
31
+ self,
32
+ get_tokenizer: Callable,
33
+ feat_extractor: Callable,
34
+ campplus_model: str,
35
+ speech_tokenizer_model: str,
36
+ spk2info: str = '',
37
+ allowed_special: str = 'all',
38
+ ):
39
  self.tokenizer = get_tokenizer()
40
  self.feat_extractor = feat_extractor
41
  self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
42
  option = onnxruntime.SessionOptions()
43
  option.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL
44
  option.intra_op_num_threads = 1
45
+
46
+ self.campplus_session = onnxruntime.InferenceSession(
47
+ campplus_model, sess_options=option, providers=["CPUExecutionProvider"]
48
+ )
49
+
50
+ # Force correct tokenizer file under same directory
51
+ import os
52
+ tokenizer_dir = os.path.dirname(speech_tokenizer_model)
53
+ speech_tokenizer_model = os.path.join(tokenizer_dir, "speech_tokenizer_v3.onnx")
54
+
55
+ self.speech_tokenizer_session = onnxruntime.InferenceSession(
56
+ speech_tokenizer_model,
57
+ sess_options=option,
58
+ providers=["CUDAExecutionProvider" if torch.cuda.is_available() else "CPUExecutionProvider"],
59
+ )
60
+
61
+
62
  if os.path.exists(spk2info):
63
  self.spk2info = torch.load(spk2info, map_location=self.device, weights_only=True)
64
  else: