File size: 1,383 Bytes
1df74c6
d2b7e94
1df74c6
d2b7e94
1df74c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import subprocess
from typing import IO, Union

from modules.speaker import Speaker, speaker_mgr


def get_datasets_dir():
    """
    列出 ./datasets/data_* 文件夹
    """
    dataset_path = "./datasets"
    dataset_list = os.listdir(dataset_path)
    dataset_list = [
        d for d in dataset_list if os.path.isdir(os.path.join(dataset_path, d))
    ]
    dataset_list = [d for d in dataset_list if d.startswith("data_")]
    return dataset_list


def get_datasets_listfile():
    datasets = get_datasets_dir()
    listfiles = []
    for d in datasets:
        dir_path = os.path.join("./datasets", d)
        files = os.listdir(dir_path)
        for f in files:
            if f.endswith(".list"):
                listfiles.append(os.path.join(dir_path, f))
    return listfiles


def run_speaker_ft(
    batch_size: int, epochs: int, train_text: bool, data_path: str, init_speaker: str
):
    command = ["python3", "-m", "modules.finetune.train_speaker"]
    command += [
        f"--batch_size={batch_size}",
        f"--epochs={epochs}",
        f"--data_path={data_path}",
    ]
    if train_text:
        command.append("--train_text")
    if init_speaker:
        command.append(f"--init_speaker={init_speaker}")
    process = subprocess.Popen(
        command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1
    )

    return process