MCPcopy Index your code
hub / github.com/descriptinc/descript-audio-codec / decode

Function decode

dac/utils/decode.py:19–89  ·  view source on GitHub ↗

Decode audio from codes. Parameters ---------- input : str Path to input directory or file output : str, optional Path to output directory, by default "". If `input` is a directory, the directory sub-tree relative to `input` is re-created in `output`. wei

(
    input: str,
    output: str = "",
    weights_path: str = "",
    model_tag: str = "latest",
    model_bitrate: str = "8kbps",
    device: str = "cuda",
    model_type: str = "44khz",
    verbose: bool = False,
)

Source from the content-addressed store, hash-verified

17@torch.inference_mode()
18@torch.no_grad()
19def decode(
20 input: str,
21 output: str = "",
22 weights_path: str = "",
23 model_tag: str = "latest",
24 model_bitrate: str = "8kbps",
25 device: str = "cuda",
26 model_type: str = "44khz",
27 verbose: bool = False,
28):
29 """Decode audio from codes.
30
31 Parameters
32 ----------
33 input : str
34 Path to input directory or file
35 output : str, optional
36 Path to output directory, by default "".
37 If `input` is a directory, the directory sub-tree relative to `input` is re-created in `output`.
38 weights_path : str, optional
39 Path to weights file, by default "". If not specified, the weights file will be downloaded from the internet using the
40 model_tag and model_type.
41 model_tag : str, optional
42 Tag of the model to use, by default "latest". Ignored if `weights_path` is specified.
43 model_bitrate: str
44 Bitrate of the model. Must be one of "8kbps", or "16kbps". Defaults to "8kbps".
45 device : str, optional
46 Device to use, by default "cuda". If "cpu", the model will be loaded on the CPU.
47 model_type : str, optional
48 The type of model to use. Must be one of "44khz", "24khz", or "16khz". Defaults to "44khz". Ignored if `weights_path` is specified.
49 """
50 generator = load_model(
51 model_type=model_type,
52 model_bitrate=model_bitrate,
53 tag=model_tag,
54 load_path=weights_path,
55 )
56 generator.to(device)
57 generator.eval()
58
59 # Find all .dac files in input directory
60 _input = Path(input)
61 input_files = list(_input.glob("**/*.dac"))
62
63 # If input is a .dac file, add it to the list
64 if _input.suffix == ".dac":
65 input_files.append(_input)
66
67 # Create output directory
68 output = Path(output)
69 output.mkdir(parents=True, exist_ok=True)
70
71 for i in tqdm(range(len(input_files)), desc=f"Decoding files"):
72 # Load file
73 artifact = DACFile.load(input_files[i])
74
75 # Reconstruct audio from codes
76 recons = generator.decompress(artifact, verbose=verbose)

Callers 1

decode.pyFile · 0.85

Calls 3

load_modelFunction · 0.90
loadMethod · 0.80
decompressMethod · 0.80

Tested by

no test coverage detected