File size: 1,864 Bytes
1ddca60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import os
import sys

def run_f5_tts():
    # Lấy đường dẫn tuyệt đối của file hiện tại
    current_dir = os.path.dirname(os.path.abspath(__file__))

    # Lấy đường dẫn tuyệt đối đến file infer_cli.py
    infer_cli_path = os.path.join(current_dir, "src", "f5_tts", "infer", "infer_cli.py")

    # Định nghĩa tham số
    model = "F5TTS_Base"
    ref_text = "bà nói cái chuyện gì tôi nhớ à, còn chuyện gì tôi hỏng nhớ."
    ref_audio = "clon/ONG_GIA.mp3"
    gen_text = "tình yêu là gì? mà nó có thể làm con người ta đau khổ đến như vậy?"

    speed = 1.0
    vocoder_name = "vocos"
    vocab_file = os.path.join(current_dir, "F5-TTS-MRSU", "vocab.txt")
    ckpt_file = os.path.join(current_dir, "F5-TTS-MRSU", "model_last.pt")

    # ✅ Thiết lập biến môi trường tương đương lệnh: $env:PYTHONIOENCODING="utf-8"
    os.environ["PYTHONIOENCODING"] = "utf-8"

    # Gọi python để chạy file infer_cli.py trực tiếp
    command = [
        sys.executable,  # dùng đúng Python đang chạy script này
        infer_cli_path,
        "--model", model,
        "--ref_audio", ref_audio,
        "--ref_text", ref_text,
        "--gen_text", gen_text,
        "--speed", str(speed),
        "--vocoder_name", vocoder_name,
        "--vocab_file", vocab_file,
        "--ckpt_file", ckpt_file
    ]

    try:
        result = subprocess.run(
            command,
            check=True,
            capture_output=True,
            text=True
        )
        print("✅ Kết quả:\n", result.stdout)
    except subprocess.CalledProcessError as e:
        print("❌ Lỗi khi chạy suy luận:\n", e.stderr)
    except Exception as e:
        print("❌ Lỗi không xác định:\n", str(e))

if __name__ == "__main__":
    run_f5_tts()