Spaces:
Sleeping
Sleeping
Fix build timeout and Perth watermarker NoneType error
Browse files- neuttsair/neutts.py +27 -3
neuttsair/neutts.py
CHANGED
|
@@ -4,7 +4,6 @@ import librosa
|
|
| 4 |
import numpy as np
|
| 5 |
import torch
|
| 6 |
import re
|
| 7 |
-
import perth
|
| 8 |
from neucodec import NeuCodec, DistillNeuCodec
|
| 9 |
from phonemizer.backend import EspeakBackend
|
| 10 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
|
@@ -38,6 +37,31 @@ def _linear_overlap_add(frames: list[np.ndarray], stride: int) -> np.ndarray:
|
|
| 38 |
return out / sum_weight
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
class NeuTTSAir:
|
| 42 |
|
| 43 |
def __init__(
|
|
@@ -75,8 +99,8 @@ class NeuTTSAir:
|
|
| 75 |
|
| 76 |
self._load_codec(codec_repo, codec_device)
|
| 77 |
|
| 78 |
-
# Load watermarker
|
| 79 |
-
self.watermarker =
|
| 80 |
|
| 81 |
def _load_backbone(self, backbone_repo, backbone_device):
|
| 82 |
print(f"Loading backbone from: {backbone_repo} on {backbone_device} ...")
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import torch
|
| 6 |
import re
|
|
|
|
| 7 |
from neucodec import NeuCodec, DistillNeuCodec
|
| 8 |
from phonemizer.backend import EspeakBackend
|
| 9 |
from transformers import AutoTokenizer, AutoModelForCausalLM, TextIteratorStreamer
|
|
|
|
| 37 |
return out / sum_weight
|
| 38 |
|
| 39 |
|
| 40 |
+
class _NoOpWatermarker:
|
| 41 |
+
"""Pass-through when Perth watermarker fails to load."""
|
| 42 |
+
|
| 43 |
+
def apply_watermark(self, wav: np.ndarray, sample_rate: int = 24_000) -> np.ndarray:
|
| 44 |
+
return wav
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _load_watermarker():
|
| 48 |
+
"""Load PerthImplicitWatermarker with fallbacks for broken package layouts."""
|
| 49 |
+
try:
|
| 50 |
+
import perth
|
| 51 |
+
cls = getattr(perth, "PerthImplicitWatermarker", None)
|
| 52 |
+
if cls is not None and callable(cls):
|
| 53 |
+
return cls()
|
| 54 |
+
except Exception:
|
| 55 |
+
pass
|
| 56 |
+
try:
|
| 57 |
+
from perth.perth_net.perth_net_implicit.perth_watermarker import PerthImplicitWatermarker
|
| 58 |
+
return PerthImplicitWatermarker()
|
| 59 |
+
except Exception:
|
| 60 |
+
pass
|
| 61 |
+
print("Warning: Perth watermarker unavailable, using pass-through.")
|
| 62 |
+
return _NoOpWatermarker()
|
| 63 |
+
|
| 64 |
+
|
| 65 |
class NeuTTSAir:
|
| 66 |
|
| 67 |
def __init__(
|
|
|
|
| 99 |
|
| 100 |
self._load_codec(codec_repo, codec_device)
|
| 101 |
|
| 102 |
+
# Load watermarker (PerthImplicitWatermarker can be None in some envs → NoneType not callable)
|
| 103 |
+
self.watermarker = _load_watermarker()
|
| 104 |
|
| 105 |
def _load_backbone(self, backbone_repo, backbone_device):
|
| 106 |
print(f"Loading backbone from: {backbone_repo} on {backbone_device} ...")
|