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()