chenjgtea
commited on
Commit
·
7027c47
1
Parent(s):
c289d9f
新增gpu模式下chattts代码
Browse files- Chat2TTS/core.py +15 -0
Chat2TTS/core.py
CHANGED
@@ -175,6 +175,21 @@ class Chat:
|
|
175 |
return self._encode_spk_emb(self._sample_random_speaker())
|
176 |
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
def _sample_random_speaker(self) -> torch.Tensor:
|
180 |
with torch.no_grad():
|
|
|
175 |
return self._encode_spk_emb(self._sample_random_speaker())
|
176 |
|
177 |
|
178 |
+
@staticmethod
|
179 |
+
def _encode_spk_emb(spk_emb: torch.Tensor) -> str:
|
180 |
+
with torch.no_grad():
|
181 |
+
arr: np.ndarray = spk_emb.to(dtype=torch.float16, device="cpu").numpy()
|
182 |
+
s = b14.encode_to_string(
|
183 |
+
lzma.compress(
|
184 |
+
arr.tobytes(),
|
185 |
+
format=lzma.FORMAT_RAW,
|
186 |
+
filters=[
|
187 |
+
{"id": lzma.FILTER_LZMA2, "preset": 9 | lzma.PRESET_EXTREME}
|
188 |
+
],
|
189 |
+
),
|
190 |
+
)
|
191 |
+
del arr
|
192 |
+
return s
|
193 |
|
194 |
def _sample_random_speaker(self) -> torch.Tensor:
|
195 |
with torch.no_grad():
|