Spaces:
Running
on
Zero
Running
on
Zero
Delete inference_gui.py
Browse files- inference_gui.py +0 -310
inference_gui.py
DELETED
|
@@ -1,310 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
from PyQt5.QtCore import QEvent
|
| 4 |
-
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QTextEdit
|
| 5 |
-
from PyQt5.QtWidgets import QGridLayout, QVBoxLayout, QWidget, QFileDialog, QStatusBar, QComboBox
|
| 6 |
-
import soundfile as sf
|
| 7 |
-
|
| 8 |
-
from tools.i18n.i18n import I18nAuto
|
| 9 |
-
i18n = I18nAuto()
|
| 10 |
-
|
| 11 |
-
from inference_webui import gpt_path, sovits_path, change_gpt_weights, change_sovits_weights, get_tts_wav
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
class GPTSoVITSGUI(QMainWindow):
|
| 15 |
-
GPT_Path = gpt_path
|
| 16 |
-
SoVITS_Path = sovits_path
|
| 17 |
-
|
| 18 |
-
def __init__(self):
|
| 19 |
-
super().__init__()
|
| 20 |
-
|
| 21 |
-
self.setWindowTitle('GPT-SoVITS GUI')
|
| 22 |
-
self.setGeometry(800, 450, 950, 850)
|
| 23 |
-
|
| 24 |
-
self.setStyleSheet("""
|
| 25 |
-
QWidget {
|
| 26 |
-
background-color: #a3d3b1;
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
QTabWidget::pane {
|
| 30 |
-
background-color: #a3d3b1;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
QTabWidget::tab-bar {
|
| 34 |
-
alignment: left;
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
QTabBar::tab {
|
| 38 |
-
background: #8da4bf;
|
| 39 |
-
color: #ffffff;
|
| 40 |
-
padding: 8px;
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
QTabBar::tab:selected {
|
| 44 |
-
background: #2a3f54;
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
QLabel {
|
| 48 |
-
color: #000000;
|
| 49 |
-
}
|
| 50 |
-
|
| 51 |
-
QPushButton {
|
| 52 |
-
background-color: #4CAF50;
|
| 53 |
-
color: white;
|
| 54 |
-
padding: 8px;
|
| 55 |
-
border: 1px solid #4CAF50;
|
| 56 |
-
border-radius: 4px;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
QPushButton:hover {
|
| 60 |
-
background-color: #45a049;
|
| 61 |
-
border: 1px solid #45a049;
|
| 62 |
-
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
|
| 63 |
-
}
|
| 64 |
-
""")
|
| 65 |
-
|
| 66 |
-
license_text = (
|
| 67 |
-
"本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责. "
|
| 68 |
-
"如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录LICENSE.")
|
| 69 |
-
license_label = QLabel(license_text)
|
| 70 |
-
license_label.setWordWrap(True)
|
| 71 |
-
|
| 72 |
-
self.GPT_model_label = QLabel("选择GPT模型:")
|
| 73 |
-
self.GPT_model_input = QLineEdit()
|
| 74 |
-
self.GPT_model_input.setPlaceholderText("拖拽或选择文件")
|
| 75 |
-
self.GPT_model_input.setText(self.GPT_Path)
|
| 76 |
-
self.GPT_model_input.setReadOnly(True)
|
| 77 |
-
self.GPT_model_button = QPushButton("选择GPT模型文件")
|
| 78 |
-
self.GPT_model_button.clicked.connect(self.select_GPT_model)
|
| 79 |
-
|
| 80 |
-
self.SoVITS_model_label = QLabel("选择SoVITS模型:")
|
| 81 |
-
self.SoVITS_model_input = QLineEdit()
|
| 82 |
-
self.SoVITS_model_input.setPlaceholderText("拖拽或选择文件")
|
| 83 |
-
self.SoVITS_model_input.setText(self.SoVITS_Path)
|
| 84 |
-
self.SoVITS_model_input.setReadOnly(True)
|
| 85 |
-
self.SoVITS_model_button = QPushButton("选择SoVITS模型文件")
|
| 86 |
-
self.SoVITS_model_button.clicked.connect(self.select_SoVITS_model)
|
| 87 |
-
|
| 88 |
-
self.ref_audio_label = QLabel("上传参考音频:")
|
| 89 |
-
self.ref_audio_input = QLineEdit()
|
| 90 |
-
self.ref_audio_input.setPlaceholderText("拖拽或选择文件")
|
| 91 |
-
self.ref_audio_input.setReadOnly(True)
|
| 92 |
-
self.ref_audio_button = QPushButton("选择音频文件")
|
| 93 |
-
self.ref_audio_button.clicked.connect(self.select_ref_audio)
|
| 94 |
-
|
| 95 |
-
self.ref_text_label = QLabel("参考音频文本:")
|
| 96 |
-
self.ref_text_input = QLineEdit()
|
| 97 |
-
self.ref_text_input.setPlaceholderText("直接输入文字或上传文本")
|
| 98 |
-
self.ref_text_button = QPushButton("上传文本")
|
| 99 |
-
self.ref_text_button.clicked.connect(self.upload_ref_text)
|
| 100 |
-
|
| 101 |
-
self.ref_language_label = QLabel("参考音频语言:")
|
| 102 |
-
self.ref_language_combobox = QComboBox()
|
| 103 |
-
self.ref_language_combobox.addItems(["中文", "英文", "日文", "中英混合", "日英混合", "多语种混合"])
|
| 104 |
-
self.ref_language_combobox.setCurrentText("多语种混合")
|
| 105 |
-
|
| 106 |
-
self.target_text_label = QLabel("合成目标文本:")
|
| 107 |
-
self.target_text_input = QLineEdit()
|
| 108 |
-
self.target_text_input.setPlaceholderText("直接输入文字或上传文本")
|
| 109 |
-
self.target_text_button = QPushButton("上传文本")
|
| 110 |
-
self.target_text_button.clicked.connect(self.upload_target_text)
|
| 111 |
-
|
| 112 |
-
self.target_language_label = QLabel("合成音频语言:")
|
| 113 |
-
self.target_language_combobox = QComboBox()
|
| 114 |
-
self.target_language_combobox.addItems(["中文", "英文", "日文", "中英混合", "日英混合", "多语种混合"])
|
| 115 |
-
self.target_language_combobox.setCurrentText("多语种混合")
|
| 116 |
-
|
| 117 |
-
self.output_label = QLabel("输出音频路径:")
|
| 118 |
-
self.output_input = QLineEdit()
|
| 119 |
-
self.output_input.setPlaceholderText("拖拽或选择文件")
|
| 120 |
-
self.output_input.setReadOnly(True)
|
| 121 |
-
self.output_button = QPushButton("选择文件夹")
|
| 122 |
-
self.output_button.clicked.connect(self.select_output_path)
|
| 123 |
-
|
| 124 |
-
self.output_text = QTextEdit()
|
| 125 |
-
self.output_text.setReadOnly(True)
|
| 126 |
-
|
| 127 |
-
self.add_drag_drop_events([
|
| 128 |
-
self.GPT_model_input,
|
| 129 |
-
self.SoVITS_model_input,
|
| 130 |
-
self.ref_audio_input,
|
| 131 |
-
self.ref_text_input,
|
| 132 |
-
self.target_text_input,
|
| 133 |
-
self.output_input,
|
| 134 |
-
])
|
| 135 |
-
|
| 136 |
-
self.synthesize_button = QPushButton("合成")
|
| 137 |
-
self.synthesize_button.clicked.connect(self.synthesize)
|
| 138 |
-
|
| 139 |
-
self.clear_output_button = QPushButton("清空输出")
|
| 140 |
-
self.clear_output_button.clicked.connect(self.clear_output)
|
| 141 |
-
|
| 142 |
-
self.status_bar = QStatusBar()
|
| 143 |
-
|
| 144 |
-
main_layout = QVBoxLayout()
|
| 145 |
-
|
| 146 |
-
input_layout = QGridLayout(self)
|
| 147 |
-
input_layout.setSpacing(10)
|
| 148 |
-
|
| 149 |
-
input_layout.addWidget(license_label, 0, 0, 1, 3)
|
| 150 |
-
|
| 151 |
-
input_layout.addWidget(self.GPT_model_label, 1, 0)
|
| 152 |
-
input_layout.addWidget(self.GPT_model_input, 2, 0, 1, 2)
|
| 153 |
-
input_layout.addWidget(self.GPT_model_button, 2, 2)
|
| 154 |
-
|
| 155 |
-
input_layout.addWidget(self.SoVITS_model_label, 3, 0)
|
| 156 |
-
input_layout.addWidget(self.SoVITS_model_input, 4, 0, 1, 2)
|
| 157 |
-
input_layout.addWidget(self.SoVITS_model_button, 4, 2)
|
| 158 |
-
|
| 159 |
-
input_layout.addWidget(self.ref_audio_label, 5, 0)
|
| 160 |
-
input_layout.addWidget(self.ref_audio_input, 6, 0, 1, 2)
|
| 161 |
-
input_layout.addWidget(self.ref_audio_button, 6, 2)
|
| 162 |
-
|
| 163 |
-
input_layout.addWidget(self.ref_language_label, 7, 0)
|
| 164 |
-
input_layout.addWidget(self.ref_language_combobox, 8, 0, 1, 1)
|
| 165 |
-
input_layout.addWidget(self.ref_text_label, 9, 0)
|
| 166 |
-
input_layout.addWidget(self.ref_text_input, 10, 0, 1, 2)
|
| 167 |
-
input_layout.addWidget(self.ref_text_button, 10, 2)
|
| 168 |
-
|
| 169 |
-
input_layout.addWidget(self.target_language_label, 11, 0)
|
| 170 |
-
input_layout.addWidget(self.target_language_combobox, 12, 0, 1, 1)
|
| 171 |
-
input_layout.addWidget(self.target_text_label, 13, 0)
|
| 172 |
-
input_layout.addWidget(self.target_text_input, 14, 0, 1, 2)
|
| 173 |
-
input_layout.addWidget(self.target_text_button, 14, 2)
|
| 174 |
-
|
| 175 |
-
input_layout.addWidget(self.output_label, 15, 0)
|
| 176 |
-
input_layout.addWidget(self.output_input, 16, 0, 1, 2)
|
| 177 |
-
input_layout.addWidget(self.output_button, 16, 2)
|
| 178 |
-
|
| 179 |
-
main_layout.addLayout(input_layout)
|
| 180 |
-
|
| 181 |
-
output_layout = QVBoxLayout()
|
| 182 |
-
output_layout.addWidget(self.output_text)
|
| 183 |
-
main_layout.addLayout(output_layout)
|
| 184 |
-
|
| 185 |
-
main_layout.addWidget(self.synthesize_button)
|
| 186 |
-
|
| 187 |
-
main_layout.addWidget(self.clear_output_button)
|
| 188 |
-
|
| 189 |
-
main_layout.addWidget(self.status_bar)
|
| 190 |
-
|
| 191 |
-
self.central_widget = QWidget()
|
| 192 |
-
self.central_widget.setLayout(main_layout)
|
| 193 |
-
self.setCentralWidget(self.central_widget)
|
| 194 |
-
|
| 195 |
-
def dragEnterEvent(self, event):
|
| 196 |
-
if event.mimeData().hasUrls():
|
| 197 |
-
event.acceptProposedAction()
|
| 198 |
-
|
| 199 |
-
def dropEvent(self, event):
|
| 200 |
-
if event.mimeData().hasUrls():
|
| 201 |
-
file_paths = [url.toLocalFile() for url in event.mimeData().urls()]
|
| 202 |
-
if len(file_paths) == 1:
|
| 203 |
-
self.update_ref_audio(file_paths[0])
|
| 204 |
-
else:
|
| 205 |
-
self.update_ref_audio(", ".join(file_paths))
|
| 206 |
-
|
| 207 |
-
def add_drag_drop_events(self, widgets):
|
| 208 |
-
for widget in widgets:
|
| 209 |
-
widget.setAcceptDrops(True)
|
| 210 |
-
widget.installEventFilter(self)
|
| 211 |
-
|
| 212 |
-
def eventFilter(self, obj, event):
|
| 213 |
-
if event.type() in (QEvent.DragEnter, QEvent.Drop):
|
| 214 |
-
mime_data = event.mimeData()
|
| 215 |
-
if mime_data.hasUrls():
|
| 216 |
-
event.acceptProposedAction()
|
| 217 |
-
|
| 218 |
-
return super().eventFilter(obj, event)
|
| 219 |
-
|
| 220 |
-
def select_GPT_model(self):
|
| 221 |
-
file_path, _ = QFileDialog.getOpenFileName(self, "选择GPT模型文件", "", "GPT Files (*.ckpt)")
|
| 222 |
-
if file_path:
|
| 223 |
-
self.GPT_model_input.setText(file_path)
|
| 224 |
-
|
| 225 |
-
def select_SoVITS_model(self):
|
| 226 |
-
file_path, _ = QFileDialog.getOpenFileName(self, "选择SoVITS模型文件", "", "SoVITS Files (*.pth)")
|
| 227 |
-
if file_path:
|
| 228 |
-
self.SoVITS_model_input.setText(file_path)
|
| 229 |
-
|
| 230 |
-
def select_ref_audio(self):
|
| 231 |
-
file_path, _ = QFileDialog.getOpenFileName(self, "选择参考音频文件", "", "Audio Files (*.wav *.mp3)")
|
| 232 |
-
if file_path:
|
| 233 |
-
self.update_ref_audio(file_path)
|
| 234 |
-
|
| 235 |
-
def upload_ref_text(self):
|
| 236 |
-
file_path, _ = QFileDialog.getOpenFileName(self, "选择文本文件", "", "Text Files (*.txt)")
|
| 237 |
-
if file_path:
|
| 238 |
-
with open(file_path, 'r', encoding='utf-8') as file:
|
| 239 |
-
content = file.read()
|
| 240 |
-
self.ref_text_input.setText(content)
|
| 241 |
-
|
| 242 |
-
def upload_target_text(self):
|
| 243 |
-
file_path, _ = QFileDialog.getOpenFileName(self, "选择文本文件", "", "Text Files (*.txt)")
|
| 244 |
-
if file_path:
|
| 245 |
-
with open(file_path, 'r', encoding='utf-8') as file:
|
| 246 |
-
content = file.read()
|
| 247 |
-
self.target_text_input.setText(content)
|
| 248 |
-
|
| 249 |
-
def select_output_path(self):
|
| 250 |
-
options = QFileDialog.Options()
|
| 251 |
-
options |= QFileDialog.DontUseNativeDialog
|
| 252 |
-
options |= QFileDialog.ShowDirsOnly
|
| 253 |
-
|
| 254 |
-
folder_dialog = QFileDialog()
|
| 255 |
-
folder_dialog.setOptions(options)
|
| 256 |
-
folder_dialog.setFileMode(QFileDialog.Directory)
|
| 257 |
-
|
| 258 |
-
if folder_dialog.exec_():
|
| 259 |
-
folder_path = folder_dialog.selectedFiles()[0]
|
| 260 |
-
self.output_input.setText(folder_path)
|
| 261 |
-
|
| 262 |
-
def update_ref_audio(self, file_path):
|
| 263 |
-
self.ref_audio_input.setText(file_path)
|
| 264 |
-
|
| 265 |
-
def clear_output(self):
|
| 266 |
-
self.output_text.clear()
|
| 267 |
-
|
| 268 |
-
def synthesize(self):
|
| 269 |
-
GPT_model_path = self.GPT_model_input.text()
|
| 270 |
-
SoVITS_model_path = self.SoVITS_model_input.text()
|
| 271 |
-
ref_audio_path = self.ref_audio_input.text()
|
| 272 |
-
language_combobox = self.ref_language_combobox.currentText()
|
| 273 |
-
language_combobox = i18n(language_combobox)
|
| 274 |
-
ref_text = self.ref_text_input.text()
|
| 275 |
-
target_language_combobox = self.target_language_combobox.currentText()
|
| 276 |
-
target_language_combobox = i18n(target_language_combobox)
|
| 277 |
-
target_text = self.target_text_input.text()
|
| 278 |
-
output_path = self.output_input.text()
|
| 279 |
-
|
| 280 |
-
if GPT_model_path != self.GPT_Path:
|
| 281 |
-
change_gpt_weights(gpt_path=GPT_model_path)
|
| 282 |
-
self.GPT_Path = GPT_model_path
|
| 283 |
-
if SoVITS_model_path != self.SoVITS_Path:
|
| 284 |
-
change_sovits_weights(sovits_path=SoVITS_model_path)
|
| 285 |
-
self.SoVITS_Path = SoVITS_model_path
|
| 286 |
-
|
| 287 |
-
synthesis_result = get_tts_wav(ref_wav_path=ref_audio_path,
|
| 288 |
-
prompt_text=ref_text,
|
| 289 |
-
prompt_language=language_combobox,
|
| 290 |
-
text=target_text,
|
| 291 |
-
text_language=target_language_combobox)
|
| 292 |
-
|
| 293 |
-
result_list = list(synthesis_result)
|
| 294 |
-
|
| 295 |
-
if result_list:
|
| 296 |
-
last_sampling_rate, last_audio_data = result_list[-1]
|
| 297 |
-
output_wav_path = os.path.join(output_path, "output.wav")
|
| 298 |
-
sf.write(output_wav_path, last_audio_data, last_sampling_rate)
|
| 299 |
-
|
| 300 |
-
result = "Audio saved to " + output_wav_path
|
| 301 |
-
|
| 302 |
-
self.status_bar.showMessage("合成完成!输出路径:" + output_wav_path, 5000)
|
| 303 |
-
self.output_text.append("处理结果:\n" + result)
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
if __name__ == '__main__':
|
| 307 |
-
app = QApplication(sys.argv)
|
| 308 |
-
mainWin = GPTSoVITSGUI()
|
| 309 |
-
mainWin.show()
|
| 310 |
-
sys.exit(app.exec_())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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