You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.8 KiB
164 lines
4.8 KiB
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import sys
|
|
from PyQt5.QtWidgets import (
|
|
QApplication, QMainWindow, QPushButton, QLabel,
|
|
QVBoxLayout, QHBoxLayout, QWidget, QStackedWidget
|
|
)
|
|
from PyQt5.QtCore import Qt
|
|
|
|
|
|
# ======================
|
|
# 主菜单
|
|
# ======================
|
|
class MainMenuWidget(QWidget):
|
|
def __init__(self, parent):
|
|
super().__init__(parent)
|
|
layout = QVBoxLayout()
|
|
title = QLabel("音频分类器")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
title.setStyleSheet("font-size: 24px; font-weight: bold; margin: 20px;")
|
|
layout.addWidget(title)
|
|
|
|
btn1 = QPushButton("采集音频")
|
|
btn1.clicked.connect(lambda: parent.switch_to_input("record"))
|
|
btn2 = QPushButton("上传WAV文件")
|
|
btn2.clicked.connect(lambda: parent.switch_to_input("upload"))
|
|
btn3 = QPushButton("历史记录")
|
|
btn3.clicked.connect(parent.switch_to_history)
|
|
|
|
for b in [btn1, btn2, btn3]:
|
|
b.setMinimumHeight(60)
|
|
layout.addWidget(b)
|
|
|
|
layout.addStretch(1)
|
|
self.setLayout(layout)
|
|
|
|
|
|
# ======================
|
|
# 输入界面(录音 / 上传)
|
|
# ======================
|
|
class InputWidget(QWidget):
|
|
def __init__(self, parent, mode="record"):
|
|
super().__init__(parent)
|
|
self.parent = parent
|
|
self.mode = mode
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
layout = QVBoxLayout()
|
|
|
|
# 返回按钮
|
|
back = QPushButton("返回")
|
|
back.clicked.connect(self.parent.switch_to_main_menu)
|
|
layout.addWidget(back)
|
|
|
|
# 界面标题
|
|
title = QLabel("音频采集" if self.mode == "record" else "上传WAV文件")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(title)
|
|
|
|
# 处理按钮
|
|
process_btn = QPushButton("开始处理")
|
|
process_btn.clicked.connect(lambda: self.parent.switch_to_result())
|
|
layout.addWidget(process_btn)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
# ======================
|
|
# 结果页
|
|
# ======================
|
|
class ResultWidget(QWidget):
|
|
def __init__(self, parent):
|
|
super().__init__(parent)
|
|
self.parent = parent
|
|
layout = QVBoxLayout()
|
|
|
|
back = QPushButton("返回")
|
|
back.clicked.connect(self.parent.switch_to_main_menu)
|
|
layout.addWidget(back)
|
|
|
|
title = QLabel("处理结果")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(title)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
# ======================
|
|
# 历史记录页
|
|
# ======================
|
|
class HistoryWidget(QWidget):
|
|
def __init__(self, parent):
|
|
super().__init__(parent)
|
|
self.parent = parent
|
|
layout = QVBoxLayout()
|
|
|
|
back = QPushButton("返回")
|
|
back.clicked.connect(self.parent.switch_to_main_menu)
|
|
layout.addWidget(back)
|
|
|
|
title = QLabel("历史记录")
|
|
title.setAlignment(Qt.AlignCenter)
|
|
layout.addWidget(title)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
# ======================
|
|
# 主窗口
|
|
# ======================
|
|
class AudioClassifierGUI(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.current_input_mode = "record"
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
self.setWindowTitle("音频分类器")
|
|
self.setGeometry(100, 100, 800, 600)
|
|
|
|
# 创建堆叠窗口
|
|
self.stacked_widget = QStackedWidget()
|
|
self.setCentralWidget(self.stacked_widget)
|
|
|
|
# 创建各个界面
|
|
self.main_menu_widget = MainMenuWidget(self)
|
|
self.record_input_widget = InputWidget(self, "record")
|
|
self.upload_input_widget = InputWidget(self, "upload")
|
|
self.result_widget = ResultWidget(self)
|
|
self.history_widget = HistoryWidget(self)
|
|
|
|
# 添加到堆叠窗口
|
|
self.stacked_widget.addWidget(self.main_menu_widget) # 0
|
|
self.stacked_widget.addWidget(self.record_input_widget) # 1
|
|
self.stacked_widget.addWidget(self.upload_input_widget) # 2
|
|
self.stacked_widget.addWidget(self.result_widget) # 3
|
|
self.stacked_widget.addWidget(self.history_widget) # 4
|
|
|
|
# 默认显示主菜单
|
|
self.stacked_widget.setCurrentWidget(self.main_menu_widget)
|
|
|
|
def switch_to_input(self, mode):
|
|
self.current_input_mode = mode
|
|
if mode == "record":
|
|
self.stacked_widget.setCurrentWidget(self.record_input_widget)
|
|
else:
|
|
self.stacked_widget.setCurrentWidget(self.upload_input_widget)
|
|
|
|
def switch_to_main_menu(self):
|
|
self.stacked_widget.setCurrentWidget(self.main_menu_widget)
|
|
|
|
def switch_to_result(self):
|
|
self.stacked_widget.setCurrentWidget(self.result_widget)
|
|
|
|
def switch_to_history(self):
|
|
self.stacked_widget.setCurrentWidget(self.history_widget)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
window = AudioClassifierGUI()
|
|
window.show()
|
|
sys.exit(app.exec_()) |