68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using Python.Runtime;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CloudBuilder.Topshelf.Python
|
|
{
|
|
public class SoVITS
|
|
{
|
|
public readonly Python39Command python;
|
|
|
|
public SoVITS(Python39Command python)
|
|
{
|
|
this.python = python;
|
|
string file = python.ApplicationService.Configuration["Python39:PythonFile"]!;
|
|
|
|
if (!File.Exists(file)) return;
|
|
|
|
string init = File.ReadAllText(file, Encoding.UTF8);
|
|
|
|
using (Py.GIL())
|
|
{
|
|
python.Exec(init);
|
|
}
|
|
}
|
|
|
|
public void Generate(string text)
|
|
{
|
|
try
|
|
{
|
|
//必须定义方法的方式使用
|
|
using (Py.GIL())
|
|
{
|
|
string exec = $"api.generate(ref_wav_path=r\"{Path.Combine("F:\\GPT-SoVITS\\Template\\男青年\\douyihang", "douyihang-像一个被清空的文件夹,所有的喧嚣都暂时删除,只剩下空白的背景和呼吸的节奏.wav")}\",prompt_text=\"{"像一个被清空的文件夹,所有的喧嚣都暂时删除,只剩下空白的背景和呼吸的节奏"}\",text=\"{text}\",output_path=r\"{Path.Combine("F:\\GPT-SoVITS\\GPT-SoVITS-v2pro-20250604", "1404206091.mp3")}\")";
|
|
|
|
python.Exec(exec);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
import os
|
|
import sys
|
|
import random
|
|
# Change to project directory這個是針對C#的環境
|
|
os.chdir(r"F:\GPT-SoVITS\GPT-SoVITS-v2pro-20250604")
|
|
sys.path.insert(0, os.getcwd())
|
|
|
|
now_dir = os.getcwd()
|
|
sys.path.append(now_dir)
|
|
sys.path.append("%s/GPT_SoVITS" % (now_dir))
|
|
|
|
print(f"Current directory: {now_dir}")
|
|
print(f"Python path: {sys.executable}")
|
|
|
|
from gpt_sovits_api import GPTSoVITSAPI
|
|
|
|
print("\nInitializing GPT-SoVITS API...")
|
|
api = GPTSoVITSAPI(version="v2ProPlus")
|
|
|
|
*/ |