glide-the commited on
Commit
5ff06d1
·
1 Parent(s): 155b8bc

Add file to Git LFS tracking

Browse files
bark/mode_load.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from bark.model_fine import FineGPT, FineGPTConfig
2
  from bark.model import GPT, GPTConfig
3
  from huggingface_hub import hf_hub_download
@@ -139,8 +141,8 @@ def _download(self, from_hf_path, file_name, local_dir):
139
  hf_hub_download(repo_id=from_hf_path, filename=file_name, local_dir=local_dir)
140
 
141
 
142
- def _load_codec_model(device):
143
- model = EncodecModel.encodec_model_24khz()
144
  model.set_target_bandwidth(6.0)
145
  model.eval()
146
  model.to(device)
@@ -214,7 +216,7 @@ class BarkModelLoader:
214
  _tokenizer_path: str = "bert-base-multilingual-cased"
215
  _encodec: EncodecModel
216
 
217
- def __init__(self, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str, device: str):
218
 
219
  if tokenizer_path:
220
  self._tokenizer_path = tokenizer_path
@@ -222,6 +224,10 @@ class BarkModelLoader:
222
  self._tokenizer = BertTokenizer.from_pretrained(self._tokenizer_path)
223
  logger.info(f"BertTokenizer loaded")
224
 
 
 
 
 
225
  self._text_model.model_path = text_path
226
  self._coarse_model.model_path = coarse_path
227
  self._fine_model.model_path = fine_path
@@ -286,7 +292,6 @@ class BarkModelLoader:
286
  self._coarse_model.model = model
287
  elif model_type.model_type == "fine_model":
288
  self._fine_model.model = model
289
- self._encodec = _load_codec_model(device)
290
 
291
  def generate_text_semantic(
292
  self,
 
1
+ from pathlib import Path
2
+
3
  from bark.model_fine import FineGPT, FineGPTConfig
4
  from bark.model import GPT, GPTConfig
5
  from huggingface_hub import hf_hub_download
 
141
  hf_hub_download(repo_id=from_hf_path, filename=file_name, local_dir=local_dir)
142
 
143
 
144
+ def _load_codec_model(device,codec_repository_path: str):
145
+ model = EncodecModel.encodec_model_24khz(pretrained=True, repository=Path(codec_repository_path))
146
  model.set_target_bandwidth(6.0)
147
  model.eval()
148
  model.to(device)
 
216
  _tokenizer_path: str = "bert-base-multilingual-cased"
217
  _encodec: EncodecModel
218
 
219
+ def __init__(self, codec_repository_path: str, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str, device: str):
220
 
221
  if tokenizer_path:
222
  self._tokenizer_path = tokenizer_path
 
224
  self._tokenizer = BertTokenizer.from_pretrained(self._tokenizer_path)
225
  logger.info(f"BertTokenizer loaded")
226
 
227
+ logger.info(f"_encodec load.")
228
+ self._encodec = _load_codec_model(device=device, codec_repository_path=codec_repository_path)
229
+ logger.info(f"_encodec loaded")
230
+
231
  self._text_model.model_path = text_path
232
  self._coarse_model.model_path = coarse_path
233
  self._fine_model.model_path = fine_path
 
292
  self._coarse_model.model = model
293
  elif model_type.model_type == "fine_model":
294
  self._fine_model.model = model
 
295
 
296
  def generate_text_semantic(
297
  self,
speakers/processors/bark_to_voice.py CHANGED
@@ -56,9 +56,10 @@ class BarkProcessorData(ProcessorData):
56
  @registry.register_processor("bark_to_voice")
57
  class BarkToVoice(BaseProcessor):
58
 
59
- def __init__(self, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str):
60
  super().__init__()
61
- self._load_bark_mode(tokenizer_path=tokenizer_path,
 
62
  text_path=text_path,
63
  coarse_path=coarse_path,
64
  fine_path=fine_path)
@@ -92,12 +93,15 @@ class BarkToVoice(BaseProcessor):
92
  if cfg is None:
93
  raise RuntimeError("from_config cfg is None.")
94
 
 
95
  tokenizer_path = cfg.get("tokenizer_path", "")
96
  text_model_path = cfg.get("text_model_path", "")
97
  coarse_model_path = cfg.get("coarse_model_path", "")
98
  fine_model_path = cfg.get("fine_model_path", "")
99
 
100
- return cls(tokenizer_path=os.path.join(registry.get_path("bark_library_root"),
 
 
101
  tokenizer_path),
102
  text_path=os.path.join(registry.get_path("bark_library_root"),
103
  text_model_path),
@@ -110,10 +114,11 @@ class BarkToVoice(BaseProcessor):
110
  def match(self, data: ProcessorData):
111
  return "BARK" in data.type
112
 
113
- def _load_bark_mode(self, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str):
114
 
115
  logger.info(f'Bark model loading')
116
- self.bark_load = BarkModelLoader(tokenizer_path=tokenizer_path,
 
117
  text_path=text_path,
118
  coarse_path=coarse_path,
119
  fine_path=fine_path,
 
56
  @registry.register_processor("bark_to_voice")
57
  class BarkToVoice(BaseProcessor):
58
 
59
+ def __init__(self,codec_repository_path: str, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str):
60
  super().__init__()
61
+ self._load_bark_mode(codec_repository_path=codec_repository_path,
62
+ tokenizer_path=tokenizer_path,
63
  text_path=text_path,
64
  coarse_path=coarse_path,
65
  fine_path=fine_path)
 
93
  if cfg is None:
94
  raise RuntimeError("from_config cfg is None.")
95
 
96
+ codec_repository_path = cfg.get("codec_repository_path", "")
97
  tokenizer_path = cfg.get("tokenizer_path", "")
98
  text_model_path = cfg.get("text_model_path", "")
99
  coarse_model_path = cfg.get("coarse_model_path", "")
100
  fine_model_path = cfg.get("fine_model_path", "")
101
 
102
+ return cls(codec_repository_path=os.path.join(registry.get_path("bark_library_root"),
103
+ codec_repository_path),
104
+ tokenizer_path=os.path.join(registry.get_path("bark_library_root"),
105
  tokenizer_path),
106
  text_path=os.path.join(registry.get_path("bark_library_root"),
107
  text_model_path),
 
114
  def match(self, data: ProcessorData):
115
  return "BARK" in data.type
116
 
117
+ def _load_bark_mode(self, codec_repository_path: str, tokenizer_path: str, text_path: str, coarse_path: str, fine_path: str):
118
 
119
  logger.info(f'Bark model loading')
120
+ self.bark_load = BarkModelLoader(codec_repository_path=codec_repository_path,
121
+ tokenizer_path=tokenizer_path,
122
  text_path=text_path,
123
  coarse_path=coarse_path,
124
  fine_path=fine_path,
speakers/speakers.yaml CHANGED
@@ -14,6 +14,7 @@ preprocess:
14
  rvc_config_file: "rvc.yaml"
15
  - bark_processor:
16
  name: "bark_to_voice"
 
17
  tokenizer_path: "model/bert-base-multilingual-cased"
18
  text_model_path: "model/suno/bark_v0/text_2.pt"
19
  coarse_model_path: "model/suno/bark_v0/coarse_2.pt"
 
14
  rvc_config_file: "rvc.yaml"
15
  - bark_processor:
16
  name: "bark_to_voice"
17
+ codec_repository_path: "model/codec"
18
  tokenizer_path: "model/bert-base-multilingual-cased"
19
  text_model_path: "model/suno/bark_v0/text_2.pt"
20
  coarse_model_path: "model/suno/bark_v0/coarse_2.pt"