MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / DACFile

Class DACFile

moss_soundeffect_v2/diffsynth/models/dac_vae.py:19–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18@dataclass
19class DACFile:
20 codes: torch.Tensor
21
22 # Metadata
23 chunk_length: int
24 original_length: int
25 input_db: float
26 channels: int
27 sample_rate: int
28 padding: bool
29 dac_version: str
30
31 def save(self, path):
32 artifacts = {
33 "codes": self.codes.numpy().astype(np.uint16),
34 "metadata": {
35 "input_db": self.input_db.numpy().astype(np.float32),
36 "original_length": self.original_length,
37 "sample_rate": self.sample_rate,
38 "chunk_length": self.chunk_length,
39 "channels": self.channels,
40 "padding": self.padding,
41 "dac_version": SUPPORTED_VERSIONS[-1],
42 },
43 }
44 path = Path(path).with_suffix(".dac")
45 with open(path, "wb") as f:
46 np.save(f, artifacts)
47 return path
48
49 @classmethod
50 def load(cls, path):
51 artifacts = np.load(path, allow_pickle=True)[()]
52 codes = torch.from_numpy(artifacts["codes"].astype(int))
53 if artifacts["metadata"].get("dac_version", None) not in SUPPORTED_VERSIONS:
54 raise RuntimeError(
55 f"Given file {path} can't be loaded with this version of descript-audio-codec."
56 )
57 return cls(codes=codes, **artifacts["metadata"])
58
59
60class CodecMixin:

Callers 1

compressMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected