|
|
|
|
|
import os |
|
|
import subprocess |
|
|
import sys |
|
|
import json |
|
|
import threading |
|
|
import time |
|
|
import psutil |
|
|
import socket |
|
|
|
|
|
env = os.environ.copy() |
|
|
|
|
|
|
|
|
port_and_commands_json = json.dumps([ |
|
|
{ |
|
|
'port': 501, |
|
|
'command': '-s /home/aistudio/work/tts-mode/九月/9yue_e8_s80.pth -g /home/aistudio/work/tts-mode/九月/9yue-e25.ckpt -dr /home/aistudio/work/tts-mode/九月/九月-古代的簪花之人,不只有富人小姐,还有翩翩少女。.wav -dt 古代的簪花之人,不只有富人小姐,还有翩翩少女。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 502, |
|
|
'command': '-s /home/aistudio/work/tts-mode/贝拉/贝拉-Bella_e51_s1632.pth -g /home/aistudio/work/tts-mode/贝拉/贝拉-Bella-e21.ckpt -dr /home/aistudio/work/tts-mode/贝拉/贝拉-哎就,很狼狈,然后我就,跟你们讲,你说这件事情呢有什么意义呢?也没有什么意义。.wav -dt 哎就,很狼狈,然后我就,跟你们讲,你说这件事情呢有什么意义呢?也没有什么意义。 -dl zh' |
|
|
}, |
|
|
{ |
|
|
'port': 503, |
|
|
'command': '-s /home/aistudio/work/tts-mode/蔡徐坤/蔡徐坤-Kun_e12_s180.pth -g /home/aistudio/work/tts-mode/蔡徐坤/蔡徐坤-Kun-e12.ckpt -dr /home/aistudio/work/tts-mode/蔡徐坤/蔡徐坤-全民制作人们大家好,我是练习时长两年半的个人练习生蔡徐坤。.wav -dt 全民制作人们大家好,我是练习时长两年半的个人练习生蔡徐坤。 -dl zh' |
|
|
}, |
|
|
{ |
|
|
'port': 504, |
|
|
'command': '-s /home/aistudio/work/tts-mode/陈泽/陈泽-Ze_e60_s1500.pth -g /home/aistudio/work/tts-mode/陈泽/陈泽-Ze-e21.ckpt -dr /home/aistudio/work/tts-mode/陈泽/陈泽-材料二表达的内容就是,我骗我爸说在我妈那住骗我妈说在我爸那住利用了一个时间差玩儿了一手,时间蒙太奇。.wav -dt 材料二表达的内容就是,我骗我爸说在我妈那住骗我妈说在我爸那住利用了一个时间差玩儿了一手,时间蒙太奇。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 505, |
|
|
'command': '-s /home/aistudio/work/tts-mode/电棍/电棍-otto_e39_s1638.pth -g /home/aistudio/work/tts-mode/电棍/电棍-otto-e10.ckpt -dr /home/aistudio/work/tts-mode/电棍/电棍-那不得累死啊,倒啥样我怎么开啊,八十八点六千瓦,通电了。.wav -dt 那不得累死啊,倒啥样我怎么开啊,八十八点六千瓦,通电了。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 506, |
|
|
'command': '-s /home/aistudio/work/tts-mode/丁真/丁真-dingzhen_e29_s348.pth -g /home/aistudio/work/tts-mode/丁真/丁真-dingzhen-e15.ckpt -dr /home/aistudio/work/tts-mode/丁真/丁真-过去的一年里,我,去了很多地方,但我最主要的任务就是学习。.wav -dt 过去的一年里,我,去了很多地方,但我最主要的任务就是学习。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 507, |
|
|
'command': '-s /home/aistudio/work/tts-mode/东雪莲/东雪莲-Azuma_e35_s1435.pth -g /home/aistudio/work/tts-mode/东雪莲/东雪莲-Azuma-e10.ckpt -dr /home/aistudio/work/tts-mode/东雪莲/东雪莲-几个月前,真的,非常突然他开始冷淡,包括但不限于已读不回消息看到我扭头就走我说什么他都不理我。.wav -dt 几个月前,真的,非常突然他开始冷淡,包括但不限于已读不回消息看到我扭头就走我说什么他都不理我。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 508, |
|
|
'command': '-s /home/aistudio/work/tts-mode/珈乐/珈乐-Carol_e40_s2160.pth -g /home/aistudio/work/tts-mode/珈乐/珈乐-Carol-e15.ckpt -dr /home/aistudio/work/tts-mode/珈乐/珈乐-我以前,在做那种,测试,很多很多年前做那种网上测试。.wav -dt 我以前,在做那种,测试,很多很多年前做那种网上测试。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 509, |
|
|
'command': '-s /home/aistudio/work/tts-mode/嘉然/嘉然-Diana_e52_s2444.pth -g /home/aistudio/work/tts-mode/嘉然/嘉然-Diana-e24.ckpt -dr /home/aistudio/work/tts-mode/嘉然/嘉然-想知道一下,哎呀,最近嘉心糖们平时就是喜欢干些什么...日常的娱乐项目啊或者是。.wav -dt 想知道一下,哎呀,最近嘉心糖们平时就是喜欢干些什么...日常的娱乐项目啊或者是。 -dl zh' |
|
|
} |
|
|
, |
|
|
{ |
|
|
'port': 510, |
|
|
'command': '-s /home/aistudio/work/tts-mode/米诺/米诺-Mino_e55_s3025.pth -g /home/aistudio/work/tts-mode/米诺/米诺-Mino-e28.ckpt -dr /home/aistudio/work/tts-mode/米诺/米诺-这么多,然后就是说你今天练!你练就是我们买菜回完家回到家就希望你看到你整个地上就最好练完了嘛。.wav -dt 这么多,然后就是说你今天练!你练就是我们买菜回完家回到家就希望你看到你整个地上就最好练完了嘛。 -dl zh' |
|
|
} |
|
|
]) |
|
|
|
|
|
|
|
|
gradio_data = { |
|
|
"gradio": { |
|
|
"501": 501, |
|
|
"502": 502, |
|
|
"503": 503, |
|
|
"504": 504, |
|
|
"505": 505, |
|
|
"506": 506, |
|
|
"507": 507, |
|
|
"508": 508, |
|
|
"509": 509, |
|
|
"510": 510, |
|
|
} |
|
|
} |
|
|
os.makedirs(".webide", exist_ok=True) |
|
|
file_path = os.path.join(".webide", "proxy_config.json") |
|
|
with open(file_path, 'w', encoding='utf-8') as file: |
|
|
json.dump(gradio_data, file, ensure_ascii=False, indent=4) |
|
|
print(f"数据已成功写入 {file_path}") |
|
|
|
|
|
subprocess.run([sys.executable, "-m", "pip", "install", "-U", "openi", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]) |
|
|
import openi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists('/root/nltk_data') and os.path.isdir(folder_path): |
|
|
print(f"文件夹 '/root/nltk_data' 存在。") |
|
|
else: |
|
|
print(f"文件夹 '/root/nltk_data' 不存在。") |
|
|
os.system("rm -r /home/aistudio/nltk_data.zip") |
|
|
openi.download_file(repo_id="qilan2/SD-QL",file="nltk_data.zip",cluster="NPU",save_path="/home/aistudio/",force=False) |
|
|
os.system("unzip /home/aistudio/nltk_data.zip -d /root/") |
|
|
os.system("rm -r /home/aistudio/nltk_data.zip") |
|
|
def download_and_extract_gpt_sovits(): |
|
|
if not os.path.exists('/home/aistudio/work/GPT-SoVITS/api.py'): |
|
|
print('GPT-SoVITS 文件夹异常') |
|
|
|
|
|
|
|
|
subprocess.run(['unzip', '/home/aistudio/data/data308901/GPT-SoVITS2.zip', '-d', '/home/aistudio/work/']) |
|
|
|
|
|
print('GPT-SoVITS 文件夹已创建并解压完成.') |
|
|
subprocess.run(['rm', '/home/aistudio/work/GPT-SoVITS/api.py']) |
|
|
subprocess.run(['wget','-O','/home/aistudio/work/GPT-SoVITS/api.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/api.py']) |
|
|
if not os.path.exists('/home/aistudio/work/tts-mode/乃琳/乃琳Eileen-e20.ckpt'): |
|
|
print('tts-mode 文件夹异常') |
|
|
subprocess.run(['mkdir', '/home/aistudio/work/tts-mode']) |
|
|
subprocess.run(['unzip', '/home/aistudio/data/data308901/tts-mode.zip', '-d', '/home/aistudio/work/tts-mode/']) |
|
|
print('TTS-mode 文件夹已创建并解压完成.') |
|
|
else: |
|
|
print('文件夹已存在,无需下载和解压.') |
|
|
|
|
|
|
|
|
def execute_command(port, command): |
|
|
|
|
|
full_command = f'python /home/aistudio/work/GPT-SoVITS/api.py -p {port} {command}' |
|
|
|
|
|
|
|
|
print(f'Executing command on port {port}: {full_command}') |
|
|
|
|
|
|
|
|
os.system(full_command ) |
|
|
|
|
|
def execute_commands(port_and_commands_json): |
|
|
try: |
|
|
|
|
|
port_and_commands_list = json.loads(port_and_commands_json) |
|
|
|
|
|
threads = [] |
|
|
|
|
|
for item in port_and_commands_list: |
|
|
port = item['port'] |
|
|
command = item['command'] |
|
|
|
|
|
|
|
|
thread = threading.Thread(target=execute_command, args=(port, command)) |
|
|
thread.start() |
|
|
threads.append(thread) |
|
|
|
|
|
time.sleep(30) |
|
|
|
|
|
|
|
|
for thread in threads: |
|
|
thread.join() |
|
|
|
|
|
except json.JSONDecodeError as e: |
|
|
print(f"Failed to decode JSON: {e}") |
|
|
except Exception as e: |
|
|
print(f"An error occurred: {e}") |
|
|
|
|
|
def is_port_open(port): |
|
|
"""检查指定端口是否开放。""" |
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
|
|
return s.connect_ex(('127.0.0.1', port)) == 0 |
|
|
|
|
|
def run_api_script(): |
|
|
api_script = "/home/aistudio/work/GPT-SoVITS/api.py" |
|
|
|
|
|
print("启动 api.py ...") |
|
|
subprocess.Popen(['python', api_script]) |
|
|
|
|
|
|
|
|
time.sleep(60) |
|
|
|
|
|
if is_port_open(9880): |
|
|
print("api.py 正在运行,不需要安装依赖。") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
print("api.py 未能成功启动,需要安装依赖。") |
|
|
install_dependencies() |
|
|
|
|
|
def stop_process(pid): |
|
|
"""停止指定 PID 的进程。""" |
|
|
proc = psutil.Process(pid) |
|
|
print(f"正在停止进程: {proc.name()} (PID: {proc.pid})") |
|
|
proc.terminate() |
|
|
proc.wait(timeout=5) |
|
|
print(f"进程 {proc.name()} 成功停止。") |
|
|
|
|
|
def install_dependencies(): |
|
|
os.chdir('/home/aistudio/work/GPT-SoVITS/') |
|
|
|
|
|
subprocess.run(['pip', 'install', '-r','requirements.txt']) |
|
|
subprocess.run(['npm', 'install', '-g', 'localtunnel']) |
|
|
subprocess.run(['pip', 'install', '-r','requirements.txt']) |
|
|
|
|
|
def run_subprocesses_in_thread(port_and_commands): |
|
|
thread = threading.Thread(target=run_subprocesses, args=(port_and_commands,), daemon=True) |
|
|
thread.start() |
|
|
download_and_extract_gpt_sovits() |
|
|
subprocess.run(['rm','/home/aistudio/activate_port.py','/home/aistudio/work/GPT-SoVITS/api.py']) |
|
|
subprocess.run(['wget','-O','/home/aistudio/activate_port.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/activate_port.py']) |
|
|
subprocess.run(['wget','-O','/home/aistudio/work/GPT-SoVITS/api.py', 'https://hf-mirror.com/datasets/Qi28/aistudio_TTS/resolve/main/api.py']) |
|
|
os.chdir('/home/aistudio/work/GPT-SoVITS') |
|
|
|
|
|
run_api_script() |
|
|
execute_commands(port_and_commands_json) |
|
|
subprocess.run(['python', '/home/aistudio/activate_port.py', str(7860)], env=env, capture_output=True, text=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|