File size: 3,967 Bytes
09eaf7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,
                               QComboBox, QPushButton, QMessageBox, QGroupBox)

# 尝试导入实际的功能模块
try:
    from tools.step040_tts import generate_all_wavs_under_folder
    from tools.utils import SUPPORT_VOICE
except ImportError:
    # 定义临时的支持语音列表
    SUPPORT_VOICE = ['zh-CN-XiaoxiaoNeural', 'zh-CN-YunxiNeural',
                     'en-US-JennyNeural', 'ja-JP-NanamiNeural']


class TTSTab(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.layout = QVBoxLayout(self)

        # 视频文件夹
        self.video_folder = QLineEdit("videos")
        self.layout.addWidget(QLabel("视频文件夹"))
        self.layout.addWidget(self.video_folder)

        # AI语音生成方法
        self.tts_method = QComboBox()
        self.tts_method.addItems(['xtts', 'cosyvoice', 'EdgeTTS', "Higgs"])
        self.layout.addWidget(QLabel("AI语音生成方法"))
        self.layout.addWidget(self.tts_method)

        # 目标语言
        self.target_language = QComboBox()
        self.target_language.addItems(['中文', 'English', '粤语', 'Japanese', 'Korean', 'Spanish', 'French'])
        self.target_language.setCurrentText('中文')
        self.layout.addWidget(QLabel("目标语言"))
        self.layout.addWidget(self.target_language)

        # EdgeTTS声音选择
        self.edge_tts_voice = QComboBox()
        self.edge_tts_voice.addItems(SUPPORT_VOICE)
        self.edge_tts_voice.setCurrentText('zh-CN-XiaoxiaoNeural')
        self.layout.addWidget(QLabel("EdgeTTS声音选择"))
        self.layout.addWidget(self.edge_tts_voice)

        # 执行按钮
        self.run_button = QPushButton("开始生成语音")
        self.run_button.clicked.connect(self.run_tts)
        self.layout.addWidget(self.run_button)

        # 状态显示
        self.status_label = QLabel("准备就绪")
        self.layout.addWidget(QLabel("合成状态:"))
        self.layout.addWidget(self.status_label)

        # 音频播放控件
        synthesized_group = QGroupBox("合成语音")
        synthesized_layout = QVBoxLayout()
        self.synthesized_play_button = QPushButton("播放合成语音")
        synthesized_layout.addWidget(self.synthesized_play_button)
        synthesized_group.setLayout(synthesized_layout)

        original_group = QGroupBox("原始音频")
        original_layout = QVBoxLayout()
        self.original_play_button = QPushButton("播放原始音频")
        original_layout.addWidget(self.original_play_button)
        original_group.setLayout(original_layout)

        audio_layout = QHBoxLayout()
        audio_layout.addWidget(synthesized_group)
        audio_layout.addWidget(original_group)

        self.layout.addLayout(audio_layout)
        self.setLayout(self.layout)

    def run_tts(self):
        # 这里应该调用原始的generate_all_wavs_under_folder函数
        # 临时实现,实际应用中需要替换为真实的调用
        self.status_label.setText("生成中...")
        QMessageBox.information(self, "功能提示", "AI语音合成功能正在实现中...")

        # 实际应用中解除以下注释

        try:
            status, synthesized_path, original_path = generate_all_wavs_under_folder(
                self.video_folder.text(),
                self.tts_method.currentText(),
                self.target_language.currentText(),
                self.edge_tts_voice.currentText()
            )
            self.status_label.setText(status)
            if synthesized_path and os.path.exists(synthesized_path):
                self.synthesized_play_button.setEnabled(True)
            if original_path and os.path.exists(original_path):
                self.original_play_button.setEnabled(True)
        except Exception as e:
            self.status_label.setText(f"生成失败: {str(e)}")