File size: 12,347 Bytes
b861c45 14e2ddc 36cb5c0 908aa0f bf724e4 a3a7f88 2c620a8 d06d4a3 f9483ea 726d74d 6a19b6e 890be8d 1dbc5a3 85c215e 8505da5 904c8c6 1dbc5a3 85c215e 904c8c6 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 81867e5 1dbc5a3 85c215e 904c8c6 642bc8a 983ea21 f9483ea 716b74c 84bfc31 4af3b07 653bfa8 abd0759 4af3b07 82f975e 14e2ddc 2c620a8 b62bfca 32aff8b cdbd44a 3b0ceec d84aead e2ed0c1 d84aead a0630a9 14e2ddc b62bfca b267376 14e2ddc ce92b2c 1bddb9b b62bfca b267376 14e2ddc b62bfca c6f1836 3bcfbb9 5e767fd 3bcfbb9 3f504f0 c6f1836 3bcfbb9 8a64af2 3f504f0 3bcfbb9 6a0151f 1dbc5a3 3bcfbb9 267d1a2 8a64af2 3f504f0 d5cff63 6a0151f 2784291 9b3e9fc 136b8b5 9b3e9fc 6a0151f 3699d67 9b3e9fc 6a0151f 136b8b5 9b3e9fc a0630a9 9b3e9fc 2784291 136b8b5 6a0151f 1278f59 6a0151f 2784291 2ec3ca3 c08fe17 136b8b5 2784291 5e7df34 716b74c 5761eeb 904c8c6 86d1004 5e767fd 90a8b0b d06d4a3 4af3b07 2126633 642bc8a d5cff63 d70ba40 2784291 c4e8e16 |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# /home/aistudio/work
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
# os.system('y | conda install ffmpeg cmake')
# pip install -U gradio
# subprocess.run([sys.executable, "-m", "pip", "install", "-U", "LangSegment"])
#pip install LangSegment
# def AA():
# while True:
# time.sleep(10) # 每次迭代暂停1秒
# threading.Thread(target=AA).start()
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(['openi', 'dataset', 'download', 'qilan2/SD-QL', 'GPT-SoVITS2.zip', '--cluster', 'NPU', '--save_path', '/home/aistudio'])
# subprocess.run(['unzip', '/home/aistudio/GPT-SoVITS2.zip', '-d', '/home/aistudio/work/'])
subprocess.run(['unzip', '/home/aistudio/data/data308901/GPT-SoVITS2.zip', '-d', '/home/aistudio/work/'])
# os.remove('/home/aistudio/GPT-SoVITS2.zip')
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 启动进程
os.system(full_command ) # 在后台运行命令 + ' &'
def execute_commands(port_and_commands_json):
try:
# 解析 JSON 字符串
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]) # 使用 Popen 启动,不阻塞主线程
# 等待3分钟并检查端口是否开放
time.sleep(60) # 等待180秒(3分钟)
if is_port_open(9880): # 检查端口 9880 是否在监听
print("api.py 正在运行,不需要安装依赖。")
# # 停止这个正在运行的进程
# for proc in psutil.process_iter(attrs=['pid', 'name']):
# if "api.py" in proc.info['name']:
# stop_process(proc.info['pid'])
# break
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/')
# os.system("echo 'y' | sh install.sh")
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)
# os.system('python /home/aistudio/work/GPT-SoVITS/api.py -s "/home/aistudio/work/tts-mode/ks/ks_e8_s72.pth" -g "/home/aistudio/work/tts-mode/ks/ks-e15.ckpt" -dr "/home/aistudio/work/tts-mode/ks/ks-又下雨又打雷,还下冰雹,我这边还下冰雹呢。.wav" -dt "又下雨又打雷,还下冰雹,我这边还下冰雹呢。" -dl "zh" -p "7860"')
# os.system('python /home/aistudio/work/GPT-SoVITS/api.py -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 -p 510')
# subprocess.run('python /home/aistudio/activate_port.py 7863', shell=True)
|