File size: 1,454 Bytes
b9c341a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import time
import torch
from modelscope import snapshot_download

MODEL_DIR = snapshot_download("ccmusic/bel_canto")


def time_stamp(timestamp=None):
    if timestamp != None:
        return timestamp.strftime("%Y-%m-%d %H:%M:%S")

    return time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.time()))


def toCUDA(x):
    if hasattr(x, "cuda"):
        if torch.cuda.is_available():
            return x.cuda()

    return x


def find_wav_files(folder_path="./examples"):
    wav_files = []
    for root, _, files in os.walk(folder_path):
        for file in files:
            if file.endswith(".wav"):
                file_path = os.path.join(root, file)
                wav_files.append(file_path)

    return wav_files


def get_modelist(model_dir=MODEL_DIR):
    try:
        entries = os.listdir(model_dir)
    except OSError as e:
        print(f"无法访问 {model_dir}: {e}")
        return

    # 遍历所有条目
    output = []
    for entry in entries:
        # 获取完整路径
        full_path = os.path.join(model_dir, entry)

        # 跳过'.git'文件夹
        if entry == ".git":
            print(f"跳过 .git 文件夹: {full_path}")
            continue

        # 检查条目是文件还是目录
        if os.path.isdir(full_path):
            # 打印目录路径
            output.append(os.path.basename(full_path))

    return output