python+PyQt5 左右聲道測試源代碼
更新時間:2024年02月06日 14:29:26 作者:漂泊_人生
這篇文章主要介紹了python+PyQt5 左右聲道測試源代碼,左聲道,人機交互測試,點擊右邊聽到的對應序號按鈕,對python左右聲道測試感興趣的朋友一起看看吧
UI:

源代碼:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'MicrophoneWinFrm.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
import logging
import os
import json
import configparser
from PyQt5.QtCore import pyqtSignal
import sys
import random#隨機數
import subprocess
import inspect
from subprocess import Popen,PIPE
from colorama import Fore,Style
import re
#pip install colorama
import pygame
#pip install pygame
class Mic_ChannelTest(QtCore.QThread):
test_result_signal = QtCore.pyqtSignal(tuple) # 新增信號,傳遞一個包含設備路徑和測試結果的元組
finished_signal = QtCore.pyqtSignal() # 新增信號,表示線程完成
def __init__(self, parent=None):
super(Mic_ChannelTest, self).__init__(parent)
self.is_running=True
def run(self):
self.parent().test_AudioChannel()#啟動多線程
self.finished_signal.emit()#線程完成時發(fā)出信號
self.stop()
def stop(self):
self.is_running = False # 或者使用更安全的停止邏輯
class Ui_Form(QWidget):
updateTimer = pyqtSignal(bool) # 時間線程啟動器
def __init__(self):
super().__init__()
self.config = configparser.ConfigParser() # 創(chuàng)建對象
self.itemName = '' # 項目名稱
self.testArgs = [] # 測試參數信息
self.testStandardArgs = '' # 測試準標參數
self.Err = '' # 錯誤信息
self.cfgArgs = [] # 測試參數
self.leftChannel_TestPass=False#左聲道測試
self.rigthChannel_TestPass=False#右聲道測試
self.leftChannelSoundFile=''#左聲道音頻文件
self.rightChannelSoundFile=''#右聲道音頻文件
self.nowTest='leftChannel'#默認左聲道測試
self.randNum=1#隨機數
# 生成日志信息
self.logger = logging.getLogger('my_logger') # 步驟1 創(chuàng)建日志記錄器
self.logger.setLevel(logging.DEBUG) # 步驟2 將指定日志級別
self.file_handler = logging.FileHandler('./log/log.txt') # 步驟3 創(chuàng)建文件處理器
self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') # 步驟4 創(chuàng)建格式化器
self.file_handler.setFormatter(self.formatter) # 步驟4 將格式化器添加到處理器
self.logger.addHandler(self.file_handler) # 步驟5 將處理器添加到日志記錄器
# 讀取配置
self.config.read('./Conf/config.conf', encoding='utf-8') # 讀取配置文件,如果配置文件不存在則創(chuàng)建
#左右聲道音頻文件
self.leftChannelSoundFile=self.config.get('MicrophoneConfig','LeftChannel')#左聲道音頻文件
self.rightChannelSoundFile=self.config.get('MicrophoneConfig','RightChannel')#右聲道音頻文件
# 讀取測試配置
self.itemName = self.config.get('TestItemNameArrays', 'MicTest') # 項目名稱
self.itemFailSleepExit = int(self.config.get('TestItemWinFrmSleepExit', 'MicTest')) # 項目測試Fail延時退出
self.testArgs.clear()
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json') # 讀取測試參數信息
self.setupUi()
self.lbl_CurrentSwTest.setText('讀取配置信息...')
#將變量添加到容器中
self.left_buttons = [self.bp_Left_1,self.bp_Left_2,self.bp_Left_3,self.bp_Left_4,self.bp_Left_5,self.bp_Left_6,self.bp_Left_7,self.bp_Left_8]#左聲道控件
self.right_buttons=[self.bp_Rigth_1,self.bp_Rigth_2,self.bp_Rigth_3,self.bp_Rigth_4,self.bp_Rigth_5,self.bp_Rigth_6,self.bp_Rigth_7,self.bp_Rigth_8]#右聲道控件
for lbut in self.left_buttons:#遍歷左聲道控件
lbut.clicked.connect(self.on_left_button_clicked)#添加左擊事件
lbut.setEnabled(False)
for rbut in self.right_buttons:#遍歷右聲道控件
rbut.clicked.connect(self.on_right_button_clicked)#添加右擊事件
rbut.setEnabled(False)
if self.ReadJsonTestArgs(self.itemName) == True: # 讀取標準參數
test=[]#測試參數
testArgs=self.testStandardArgs.split('|')
#print(self.testStandardArgs)
if testArgs[0][testArgs[0].find('=')+1:]=='True':
self.lbl_LeftChannel_2.setText('True')
self.lbl_LeftChannel_2.setStyleSheet('background-color: rgb(85, 255, 127);')
self.label_8.setStyleSheet('background-color: rgb(85, 255, 127);')
if testArgs[1][testArgs[1].find('=')+1:]=='True':
self.lbl_RightChannel.setText('True')
self.lbl_RightChannel.setStyleSheet('background-color: rgb(85, 255, 127);')
self.label_8.setStyleSheet('background-color: rgb(85, 255, 127);')
#創(chuàng)建一個定時器來檢查左右聲道音頻診斷測試
self.timer = QTimer(self)
self.timer.setInterval(1000) # 每秒檢查一次
self.timer.timeout.connect(self.check_Test)
self.timer.start()
# 連接信號到槽
self.updateTimer.connect(self.handleTimer)
#左鍵單擊事件
def on_left_button_clicked(self):
button = self.sender()
button.setStyleSheet('background-color: rgb(85, 255, 127);')
# 假設我們根據按鈕的編號來改變顏色
button_number = self.left_buttons.index(button) + 1
print(self.randNum,button_number)
if self.randNum==button_number:
self.leftChannel_TestPass=True
self.nowTest='rigthChannel'
for lbt in self.left_buttons:
lbt.setEnabled(False)
self.handleTimer(True); # 啟動線程
#右鍵單擊事件
def on_right_button_clicked(self):
button=self.sender()
button.setStyleSheet('background-color: rgb(85, 255, 127);')
# 假設我們根據按鈕的編號來改變顏色
button_number = self.right_buttons.index(button) + 1
if self.randNum==button_number:
self.rigthChannel_TestPass=True
for lbt in self.right_buttons:
lbt.setEnabled(False)
self.handleTimer(True); # 啟動線程
#啟動多線程
def start_analysis_threads(self):
# 創(chuàng)建多個線程
self.handleTimer(False) # 停止進程
self.finished_threads = 0 # 重置計數器
thread=Mic_ChannelTest(self)
thread.start()#執(zhí)行跑線程
#判斷啟動隨機播放音頻
def test_AudioChannel(self):
self.randNum = random.randint(1, 8) # 生成1到10之間的隨機整數
if self.leftChannel_TestPass == True: # 左聲道測試PASS
self.label_2.setText('右聲道:人機交互測試,點擊左邊聽到的對應序號按鈕..')
self.lbl_CurrentSwTest.setText('音頻右聲道測試..')
for rbut in self.right_buttons: # 遍歷右聲道控件
rbut.setStyleSheet('')
rbut.setEnabled(True)
# rbut.setStyleSheet('background-color: rgb(85, 255, 127);')
self.nowTest = 'leftChannel' # 當前左聲道測試
self.play_mp3(f'{self.rightChannelSoundFile}') # 左聲道播放
self.play_mp3(f'Microphone/R{str(self.randNum)}.mp3') # 左聲道隨機數播放
else:
self.label_2.setText('左聲道:人機交互測試,點擊右邊聽到的對應序號按鈕..')
self.lbl_CurrentSwTest.setText('音頻左聲道測試..')
for lbut in self.left_buttons: # 遍歷左聲道控件
lbut.setEnabled(True)
lbut.setStyleSheet('')
# lbut.setStyleSheet('background-color: rgb(85, 255, 127);')
self.nowTest = 'rightChannel' # 當前右聲道測試
self.play_mp3(f'{self.leftChannelSoundFile}') # 右聲道播放
self.play_mp3(f'Microphone/L{str(self.randNum)}.mp3') # 右聲道隨機數播放
#if self.lbl_LeftChannel_2.text()=='True' and self.lbl_RightChannel.text()=='True':
#播放MP3
def play_mp3(self,file_path):
try:
print('file_path',file_path)
pygame.mixer.init()
pygame.mixer.music.load(file_path)
pygame.mixer.music.play()
# 等待音樂播放完成
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
except Exception as e:
print(f'play mp3 Err:{e}')
sys.exit(1)
# 校驗是否完成測試
def check_Test(self):
if self.lbl_LeftChannel_2.text()=='True' and self.lbl_RightChannel.text()=='True':
if self.leftChannel_TestPass==True and self.rigthChannel_TestPass==True:
self.UpdateJsonTestArgs(self.itemName,'LeftChannel=True|RightChannel=True','PASS')#更新測試信息
self.ShowLog('測試PASS', True)
sys.exit(0)
elif self.lbl_LeftChannel_2.text()=='True':
if self.leftChannel_TestPass==True:
self.UpdateJsonTestArgs(self.itemName, 'LeftChannel=True', 'PASS') # 更新測試信息
self.ShowLog('測試PASS', True)
sys.exit(0)
elif self.lbl_RightChannel.text()=='True':
if self.rigthChannel_TestPass==True:
self.UpdateJsonTestArgs(self.itemName, 'RightChannel=True', 'PASS') # 更新測試信息
self.ShowLog('測試PASS', True)
sys.exit(0)
#self.updateTimer.emit(False) # 重新啟動定時器
self.lbl_CurrentSwTest.setText('音頻測試中..')
self.start_analysis_threads()
# 定義觸發(fā)器
def handleTimer(self, start):
if start:
self.timer.start()
else:
self.timer.stop()
def setupUi(self):
self.setObjectName("Form")
self.resize(678, 737)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("IMAGE/Mic.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.setWindowIcon(icon)
self.gridLayout = QtWidgets.QGridLayout(self)
self.gridLayout.setObjectName("gridLayout")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.lbl_Logo = QtWidgets.QLabel(self)
self.lbl_Logo.setText("")
self.lbl_Logo.setPixmap(QtGui.QPixmap("IMAGE/logo.jpg"))
self.lbl_Logo.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_Logo.setObjectName("lbl_Logo")
self.horizontalLayout_4.addWidget(self.lbl_Logo)
self.label = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setStyleSheet("background-color: rgb(170, 170, 127);")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.horizontalLayout_4.addWidget(self.label)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.lbl_CurrentSwTest = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_CurrentSwTest.setFont(font)
self.lbl_CurrentSwTest.setStyleSheet("background-color: rgb(85, 255, 127);")
self.lbl_CurrentSwTest.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_CurrentSwTest.setObjectName("lbl_CurrentSwTest")
self.horizontalLayout_5.addWidget(self.lbl_CurrentSwTest)
self.verticalLayout_2.addLayout(self.horizontalLayout_5)
self.horizontalLayout.addLayout(self.verticalLayout_2)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.label_5 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_5.setFont(font)
self.label_5.setStyleSheet("background-color: rgb(255, 170, 127);")
self.label_5.setAlignment(QtCore.Qt.AlignCenter)
self.label_5.setObjectName("label_5")
self.horizontalLayout_6.addWidget(self.label_5)
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label_4 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_4.setFont(font)
self.label_4.setStyleSheet("background-color: rgb(255, 170, 127);")
self.label_4.setAlignment(QtCore.Qt.AlignCenter)
self.label_4.setObjectName("label_4")
self.verticalLayout_4.addWidget(self.label_4)
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.label_7 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_7.setFont(font)
self.label_7.setStyleSheet("background-color: rgb(255, 170, 127);")
self.label_7.setAlignment(QtCore.Qt.AlignCenter)
self.label_7.setObjectName("label_7")
self.horizontalLayout_8.addWidget(self.label_7)
self.label_6 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_6.setFont(font)
self.label_6.setStyleSheet("background-color: rgb(255, 170, 127);")
self.label_6.setAlignment(QtCore.Qt.AlignCenter)
self.label_6.setObjectName("label_6")
self.horizontalLayout_8.addWidget(self.label_6)
self.verticalLayout_4.addLayout(self.horizontalLayout_8)
self.horizontalLayout_6.addLayout(self.verticalLayout_4)
self.verticalLayout_3.addLayout(self.horizontalLayout_6)
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.label_8 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.label_8.setFont(font)
self.label_8.setAlignment(QtCore.Qt.AlignCenter)
self.label_8.setObjectName("label_8")
self.horizontalLayout_9.addWidget(self.label_8)
self.horizontalLayout_7.addLayout(self.horizontalLayout_9)
self.horizontalLayout_10 = QtWidgets.QHBoxLayout()
self.horizontalLayout_10.setObjectName("horizontalLayout_10")
self.lbl_LeftChannel_2 = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_LeftChannel_2.setFont(font)
self.lbl_LeftChannel_2.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_LeftChannel_2.setObjectName("lbl_LeftChannel_2")
self.horizontalLayout_10.addWidget(self.lbl_LeftChannel_2)
self.lbl_RightChannel = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setPointSize(12)
self.lbl_RightChannel.setFont(font)
self.lbl_RightChannel.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_RightChannel.setObjectName("lbl_RightChannel")
self.horizontalLayout_10.addWidget(self.lbl_RightChannel)
self.horizontalLayout_7.addLayout(self.horizontalLayout_10)
self.verticalLayout_3.addLayout(self.horizontalLayout_7)
self.horizontalLayout.addLayout(self.verticalLayout_3)
self.verticalLayout.addLayout(self.horizontalLayout,1)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.groupBox = QtWidgets.QGroupBox(self)
font = QtGui.QFont()
font.setPointSize(12)
self.groupBox.setFont(font)
self.groupBox.setAlignment(QtCore.Qt.AlignCenter)
self.groupBox.setObjectName("groupBox")
self.gridLayout_3 = QtWidgets.QGridLayout(self.groupBox)
self.gridLayout_3.setObjectName("gridLayout_3")
self.verticalLayout_5 = QtWidgets.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_11 = QtWidgets.QHBoxLayout()
self.horizontalLayout_11.setObjectName("horizontalLayout_11")
self.label_13 = QtWidgets.QLabel(self.groupBox)
self.label_13.setText("")
self.label_13.setObjectName("label_13")
self.horizontalLayout_11.addWidget(self.label_13)
font = QtGui.QFont()
font.setPointSize(18)
self.bp_Left_1 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_1.setObjectName("bp_Left_1")
self.bp_Left_1.setFont(font)
self.horizontalLayout_11.addWidget(self.bp_Left_1)
self.label_12 = QtWidgets.QLabel(self.groupBox)
self.label_12.setText("")
self.label_12.setObjectName("label_12")
self.horizontalLayout_11.addWidget(self.label_12)
self.verticalLayout_5.addLayout(self.horizontalLayout_11)
self.horizontalLayout_12 = QtWidgets.QHBoxLayout()
self.horizontalLayout_12.setObjectName("horizontalLayout_12")
self.label_14 = QtWidgets.QLabel(self.groupBox)
self.label_14.setText("")
self.label_14.setObjectName("label_14")
self.horizontalLayout_12.addWidget(self.label_14)
self.bp_Left_2 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_2.setObjectName("bp_Left_2")
self.bp_Left_2.setFont(font)
self.horizontalLayout_12.addWidget(self.bp_Left_2)
self.label_21 = QtWidgets.QLabel(self.groupBox)
self.label_21.setText("")
self.label_21.setObjectName("label_21")
self.horizontalLayout_12.addWidget(self.label_21)
self.verticalLayout_5.addLayout(self.horizontalLayout_12)
self.horizontalLayout_13 = QtWidgets.QHBoxLayout()
self.horizontalLayout_13.setObjectName("horizontalLayout_13")
self.label_15 = QtWidgets.QLabel(self.groupBox)
self.label_15.setText("")
self.label_15.setObjectName("label_15")
self.horizontalLayout_13.addWidget(self.label_15)
self.bp_Left_3 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_3.setObjectName("bp_Left_3")
self.bp_Left_3.setFont(font)
self.horizontalLayout_13.addWidget(self.bp_Left_3)
self.label_22 = QtWidgets.QLabel(self.groupBox)
self.label_22.setText("")
self.label_22.setObjectName("label_22")
self.horizontalLayout_13.addWidget(self.label_22)
self.verticalLayout_5.addLayout(self.horizontalLayout_13)
self.horizontalLayout_24 = QtWidgets.QHBoxLayout()
self.horizontalLayout_24.setObjectName("horizontalLayout_24")
self.label_30 = QtWidgets.QLabel(self.groupBox)
self.label_30.setText("")
self.label_30.setObjectName("label_30")
self.horizontalLayout_24.addWidget(self.label_30)
self.bp_Left_4 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_4.setObjectName("bp_Left_4")
self.bp_Left_4.setFont(font)
self.horizontalLayout_24.addWidget(self.bp_Left_4)
self.label_3 = QtWidgets.QLabel(self.groupBox)
self.label_3.setText("")
self.label_3.setObjectName("label_3")
self.horizontalLayout_24.addWidget(self.label_3)
self.verticalLayout_5.addLayout(self.horizontalLayout_24)
self.horizontalLayout_23 = QtWidgets.QHBoxLayout()
self.horizontalLayout_23.setObjectName("horizontalLayout_23")
self.label_31 = QtWidgets.QLabel(self.groupBox)
self.label_31.setText("")
self.label_31.setObjectName("label_31")
self.horizontalLayout_23.addWidget(self.label_31)
self.bp_Left_5 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_5.setObjectName("bp_Left_5")
self.bp_Left_5.setFont(font)
self.horizontalLayout_23.addWidget(self.bp_Left_5)
self.label_11 = QtWidgets.QLabel(self.groupBox)
self.label_11.setText("")
self.label_11.setObjectName("label_11")
self.horizontalLayout_23.addWidget(self.label_11)
self.verticalLayout_5.addLayout(self.horizontalLayout_23)
self.horizontalLayout_22 = QtWidgets.QHBoxLayout()
self.horizontalLayout_22.setObjectName("horizontalLayout_22")
self.label_32 = QtWidgets.QLabel(self.groupBox)
self.label_32.setText("")
self.label_32.setObjectName("label_32")
self.horizontalLayout_22.addWidget(self.label_32)
self.bp_Left_6 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_6.setObjectName("bp_Left_6")
self.bp_Left_6.setFont(font)
self.horizontalLayout_22.addWidget(self.bp_Left_6)
self.label_28 = QtWidgets.QLabel(self.groupBox)
self.label_28.setText("")
self.label_28.setObjectName("label_28")
self.horizontalLayout_22.addWidget(self.label_28)
self.verticalLayout_5.addLayout(self.horizontalLayout_22)
self.horizontalLayout_21 = QtWidgets.QHBoxLayout()
self.horizontalLayout_21.setObjectName("horizontalLayout_21")
self.label_33 = QtWidgets.QLabel(self.groupBox)
self.label_33.setText("")
self.label_33.setObjectName("label_33")
self.horizontalLayout_21.addWidget(self.label_33)
self.bp_Left_7 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_7.setObjectName("bp_Left_7")
self.bp_Left_7.setFont(font)
self.horizontalLayout_21.addWidget(self.bp_Left_7)
self.label_29 = QtWidgets.QLabel(self.groupBox)
self.label_29.setText("")
self.label_29.setObjectName("label_29")
self.horizontalLayout_21.addWidget(self.label_29)
self.verticalLayout_5.addLayout(self.horizontalLayout_21)
self.horizontalLayout_14 = QtWidgets.QHBoxLayout()
self.horizontalLayout_14.setObjectName("horizontalLayout_14")
self.label_16 = QtWidgets.QLabel(self.groupBox)
self.label_16.setText("")
self.label_16.setObjectName("label_16")
self.horizontalLayout_14.addWidget(self.label_16)
self.bp_Left_8 = QtWidgets.QPushButton(self.groupBox)
self.bp_Left_8.setObjectName("bp_Left_8")
self.bp_Left_8.setFont(font)
self.horizontalLayout_14.addWidget(self.bp_Left_8)
self.label_23 = QtWidgets.QLabel(self.groupBox)
self.label_23.setText("")
self.label_23.setObjectName("label_23")
self.horizontalLayout_14.addWidget(self.label_23)
self.verticalLayout_5.addLayout(self.horizontalLayout_14)
self.gridLayout_3.addLayout(self.verticalLayout_5, 0, 0, 1, 1)
self.horizontalLayout_2.addWidget(self.groupBox)
self.groupBox_2 = QtWidgets.QGroupBox(self)
font = QtGui.QFont()
font.setPointSize(12)
self.groupBox_2.setFont(font)
self.groupBox_2.setAlignment(QtCore.Qt.AlignCenter)
self.groupBox_2.setObjectName("groupBox_2")
self.gridLayout_4 = QtWidgets.QGridLayout(self.groupBox_2)
self.gridLayout_4.setObjectName("gridLayout_4")
self.verticalLayout_6 = QtWidgets.QVBoxLayout()
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.horizontalLayout_15 = QtWidgets.QHBoxLayout()
self.horizontalLayout_15.setObjectName("horizontalLayout_15")
self.label_24 = QtWidgets.QLabel(self.groupBox_2)
self.label_24.setText("")
self.label_24.setObjectName("label_24")
font = QtGui.QFont()
font.setPointSize(18)
self.horizontalLayout_15.addWidget(self.label_24)
self.bp_Rigth_1 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_1.setObjectName("bp_Rigth_1")
self.bp_Rigth_1.setFont(font)
self.horizontalLayout_15.addWidget(self.bp_Rigth_1)
self.label_17 = QtWidgets.QLabel(self.groupBox_2)
self.label_17.setText("")
self.label_17.setObjectName("label_17")
self.horizontalLayout_15.addWidget(self.label_17)
self.verticalLayout_6.addLayout(self.horizontalLayout_15)
self.horizontalLayout_27 = QtWidgets.QHBoxLayout()
self.horizontalLayout_27.setObjectName("horizontalLayout_27")
self.label_38 = QtWidgets.QLabel(self.groupBox_2)
self.label_38.setText("")
self.label_38.setObjectName("label_38")
self.horizontalLayout_27.addWidget(self.label_38)
self.bp_Rigth_2 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_2.setObjectName("bp_Rigth_2")
self.bp_Rigth_2.setFont(font)
self.horizontalLayout_27.addWidget(self.bp_Rigth_2)
self.label_34 = QtWidgets.QLabel(self.groupBox_2)
self.label_34.setText("")
self.label_34.setObjectName("label_34")
self.horizontalLayout_27.addWidget(self.label_34)
self.verticalLayout_6.addLayout(self.horizontalLayout_27)
self.horizontalLayout_28 = QtWidgets.QHBoxLayout()
self.horizontalLayout_28.setObjectName("horizontalLayout_28")
self.label_39 = QtWidgets.QLabel(self.groupBox_2)
self.label_39.setText("")
self.label_39.setObjectName("label_39")
self.horizontalLayout_28.addWidget(self.label_39)
self.bp_Rigth_3 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_3.setObjectName("bp_Rigth_3")
self.bp_Rigth_3.setFont(font)
self.horizontalLayout_28.addWidget(self.bp_Rigth_3)
self.label_35 = QtWidgets.QLabel(self.groupBox_2)
self.label_35.setText("")
self.label_35.setObjectName("label_35")
self.horizontalLayout_28.addWidget(self.label_35)
self.verticalLayout_6.addLayout(self.horizontalLayout_28)
self.horizontalLayout_26 = QtWidgets.QHBoxLayout()
self.horizontalLayout_26.setObjectName("horizontalLayout_26")
self.label_40 = QtWidgets.QLabel(self.groupBox_2)
self.label_40.setText("")
self.label_40.setObjectName("label_40")
self.horizontalLayout_26.addWidget(self.label_40)
self.bp_Rigth_4 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_4.setObjectName("bp_Rigth_4")
self.bp_Rigth_4.setFont(font)
self.horizontalLayout_26.addWidget(self.bp_Rigth_4)
self.label_36 = QtWidgets.QLabel(self.groupBox_2)
self.label_36.setText("")
self.label_36.setObjectName("label_36")
self.horizontalLayout_26.addWidget(self.label_36)
self.verticalLayout_6.addLayout(self.horizontalLayout_26)
self.horizontalLayout_25 = QtWidgets.QHBoxLayout()
self.horizontalLayout_25.setObjectName("horizontalLayout_25")
self.label_41 = QtWidgets.QLabel(self.groupBox_2)
self.label_41.setText("")
self.label_41.setObjectName("label_41")
self.horizontalLayout_25.addWidget(self.label_41)
self.bp_Rigth_5 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_5.setObjectName("bp_Rigth_5")
self.bp_Rigth_5.setFont(font)
self.horizontalLayout_25.addWidget(self.bp_Rigth_5)
self.label_37 = QtWidgets.QLabel(self.groupBox_2)
self.label_37.setText("")
self.label_37.setObjectName("label_37")
self.horizontalLayout_25.addWidget(self.label_37)
self.verticalLayout_6.addLayout(self.horizontalLayout_25)
self.horizontalLayout_17 = QtWidgets.QHBoxLayout()
self.horizontalLayout_17.setObjectName("horizontalLayout_17")
self.label_25 = QtWidgets.QLabel(self.groupBox_2)
self.label_25.setText("")
self.label_25.setObjectName("label_25")
self.horizontalLayout_17.addWidget(self.label_25)
self.bp_Rigth_6 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_6.setObjectName("bp_Rigth_6")
self.bp_Rigth_6.setFont(font)
self.horizontalLayout_17.addWidget(self.bp_Rigth_6)
self.label_18 = QtWidgets.QLabel(self.groupBox_2)
self.label_18.setText("")
self.label_18.setObjectName("label_18")
self.horizontalLayout_17.addWidget(self.label_18)
self.verticalLayout_6.addLayout(self.horizontalLayout_17)
self.horizontalLayout_18 = QtWidgets.QHBoxLayout()
self.horizontalLayout_18.setObjectName("horizontalLayout_18")
self.label_26 = QtWidgets.QLabel(self.groupBox_2)
self.label_26.setText("")
self.label_26.setObjectName("label_26")
self.horizontalLayout_18.addWidget(self.label_26)
self.bp_Rigth_7 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_7.setObjectName("bp_Rigth_7")
self.bp_Rigth_7.setFont(font)
self.horizontalLayout_18.addWidget(self.bp_Rigth_7)
self.label_19 = QtWidgets.QLabel(self.groupBox_2)
self.label_19.setText("")
self.label_19.setObjectName("label_19")
self.horizontalLayout_18.addWidget(self.label_19)
self.verticalLayout_6.addLayout(self.horizontalLayout_18)
self.horizontalLayout_19 = QtWidgets.QHBoxLayout()
self.horizontalLayout_19.setObjectName("horizontalLayout_19")
self.label_27 = QtWidgets.QLabel(self.groupBox_2)
self.label_27.setText("")
self.label_27.setObjectName("label_27")
self.horizontalLayout_19.addWidget(self.label_27)
self.bp_Rigth_8 = QtWidgets.QPushButton(self.groupBox_2)
self.bp_Rigth_8.setObjectName("bp_Rigth_8")
self.bp_Rigth_8.setFont(font)
self.horizontalLayout_19.addWidget(self.bp_Rigth_8)
self.label_20 = QtWidgets.QLabel(self.groupBox_2)
self.label_20.setText("")
self.label_20.setObjectName("label_20")
self.horizontalLayout_19.addWidget(self.label_20)
self.verticalLayout_6.addLayout(self.horizontalLayout_19)
self.gridLayout_4.addLayout(self.verticalLayout_6, 0, 0, 1, 1)
self.horizontalLayout_2.addWidget(self.groupBox_2)
self.verticalLayout.addLayout(self.horizontalLayout_2,7)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.groupBox_3 = QtWidgets.QGroupBox(self)
font = QtGui.QFont()
font.setPointSize(12)
self.groupBox_3.setFont(font)
self.groupBox_3.setObjectName("groupBox_3")
self.gridLayout_2 = QtWidgets.QGridLayout(self.groupBox_3)
self.gridLayout_2.setObjectName("gridLayout_2")
self.label_2 = QtWidgets.QLabel(self.groupBox_3)
self.label_2.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 127);")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1)
self.horizontalLayout_3.addWidget(self.groupBox_3)
self.verticalLayout.addLayout(self.horizontalLayout_3,2)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint) # 只顯示最小化按鈕和關閉按鈕
# 更新測試參數json,itemName:項目名稱,readValue:讀取值,testResult:測試結果
def UpdateJsonTestArgs(self, itemName, readValue, testResult):
try:
updateTestArgs = [] # 更新的測試參數
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')
for js in self.testArgs:
if itemName in js['ItemName']:
js['Read'] = readValue # 讀取的值
js['TestResult'] = testResult # 測試結果
updateTestArgs.append(js)
else:
updateTestArgs.append(js)
with open("./Conf/TestArgs.json", "w") as write_file:
json.dump(updateTestArgs, write_file)
return True
except Exception as e:
self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)
sys.exit(1)
# 啟動線重腳本
def TestThread(self):
pass
# self.t_autoplay=Thread(target=self.Test)
# self.t_autoplay.start()
# 讀取項目參數信息,itemName:項目名稱
def ReadJsonTestArgs(self, itemName):
try:
#print('self.testArgs:', self.testArgs)
self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')
for js in self.testArgs:
if itemName in js['ItemName']:
self.testStandardArgs = js['Standard']
return True
self.ShowLog('Read TestArgs.json ItemName:' + itemName + ' Info Is Empty!!', False)
sys.exit(1)
except Exception as e:
self.ShowLog("Read TestArgs.json ItemName:" + itemName + " Info Err:" + str(e), False)
sys.exit(1)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("Form", "Mic-【測試】"))
self.label.setText(_translate("Form", "控制過程"))
self.lbl_CurrentSwTest.setText(_translate("Form", "Wait..."))
self.label_5.setText(_translate("Form", "測試項目"))
self.label_4.setText(_translate("Form", "音頻聲道"))
self.label_7.setText(_translate("Form", "左聲道"))
self.label_6.setText(_translate("Form", "右聲道"))
self.label_8.setText(_translate("Form", "喇叭測試"))
self.lbl_LeftChannel_2.setText(_translate("Form", "N/A"))
self.lbl_RightChannel.setText(_translate("Form", "N/A"))
self.groupBox.setTitle(_translate("Form", "【左聲道】"))
self.bp_Left_1.setText(_translate("Form", "1"))
self.bp_Left_2.setText(_translate("Form", "2"))
self.bp_Left_3.setText(_translate("Form", "3"))
self.bp_Left_4.setText(_translate("Form", "4"))
self.bp_Left_5.setText(_translate("Form", "5"))
self.bp_Left_6.setText(_translate("Form", "6"))
self.bp_Left_7.setText(_translate("Form", "7"))
self.bp_Left_8.setText(_translate("Form", "8"))
self.groupBox_2.setTitle(_translate("Form", "【右聲道】"))
self.bp_Rigth_1.setText(_translate("Form", "1"))
self.bp_Rigth_2.setText(_translate("Form", "2"))
self.bp_Rigth_3.setText(_translate("Form", "3"))
self.bp_Rigth_4.setText(_translate("Form", "4"))
self.bp_Rigth_5.setText(_translate("Form", "5"))
self.bp_Rigth_6.setText(_translate("Form", "6"))
self.bp_Rigth_7.setText(_translate("Form", "7"))
self.bp_Rigth_8.setText(_translate("Form", "8"))
self.groupBox_3.setTitle(_translate("Form", "【日志】"))
self.label_2.setText(_translate("Form", "待測試.."))
# 讀取json信息
def ReadJsonInfo(self, fileName):
try:
if os.path.exists(fileName):
f = open(fileName, 'r', encoding='utf-8')
return json.loads(f.read())
except Exception as e:
self.ShowLog("Read " + fileName + " Err:" + str(e), False)
#sys.exit(1)
# 手動關閉窗口
def closeEvent(self, event):
# 告知線程停止運行
sys.exit(1)
# 定義一個函數使得函數窗口居中顯示
def Center(self):
# 獲取屏幕尺寸
screen_geometry = app.desktop().availableGeometry()
# 計算窗口居中位置
x = (screen_geometry.width() - self.width()) // 2
y = (screen_geometry.height() - self.height()) // 2
# 設置窗口位置
self.move(x, y)
# 打印的信息
def ShowLog(self, log, isPass):
try:
if isPass == True:
self.label_2.setStyleSheet("background-color: rgb(85, 255, 127);color:green;")
self.logger.info(str(log))
self.label_2.setText("TEST PASS")
else:
self.label_2.setStyleSheet("background-color: rgb(85, 255, 127);color: red;")
self.logger.error(str(log))
self.label_2.setText(log)
except Exception as e:
print("\033[1;31m" + str(e) + " \033[0m")
#sys.exit(1)
if __name__=='__main__':
app=QApplication(sys.argv)
win=Ui_Form()
win.Center() # 居中
win.show()
#win.start_realtime_audio_processing() # 啟動實時音頻處理
sys.exit(app.exec_())到此這篇關于python+PyQt5 左右聲道測試的文章就介紹到這了,更多相關python 左右聲道測試內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Mac在python3環(huán)境下安裝virtualwrapper遇到的問題及解決方法
這篇文章主要介紹了Mac在python3環(huán)境下安裝virtualwrapper遇到的問題及解決方法,我在使用mac安裝virtualwrapper的時候遇到了問題,搞了好長時間,,在這里總結一下分享出來,供遇到相同的問題的朋友使用,少走些彎路,需要的朋友可以參考下2019-07-07
python應用之如何使用Python發(fā)送通知到微信
現在通過發(fā)微信信息來做消息通知和告警已經很普遍了,下面這篇文章主要給大家介紹了關于python應用之如何使用Python發(fā)送通知到微信的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-03-03

