commit 81130ac0875435c519e7c83ea756decb17c5cfb3 Author: Ninnjah <45268461+Ninnjah@users.noreply.github.com> Date: Mon Sep 7 15:32:38 2020 +0300 Add files via upload diff --git a/main.py b/main.py new file mode 100644 index 0000000..fffc20f --- /dev/null +++ b/main.py @@ -0,0 +1,145 @@ +import os +import sys +import json +import threading +import keyboard +import soundfile as sf +import sounddevice as sd +from PyQt5 import QtWidgets, uic, QtGui, QtCore + + +###! JSON !### +def jsonread(file): ## Чтение JSON + with open(file, "r", encoding='utf-8') as read_file: + data = json.load(read_file) + return data + +def jsonwrite(file, data): ## Запись JSON + with open(file, 'w', encoding='utf-8') as write_file: + write_file.write(json.dumps(data)) + + +###! FUNCTIONS !### +def found_device(list_): # Поиск микшера VoiceMeeter + index = 0 + for i in list_: + if 'VoiceMeeter Input' in i['name']: + break + index += 1 + return index + +def sound_get(filename, mode): # Сбор файлов + if os.path.exists(filename) and mode == False: + sounds_list = jsonread(filename) + elif not os.path.exists(filename) or mode == True: + if os.path.exists('sound'): + sounds = os.listdir('sound') + if len(sounds) == 0: + msg = QtWidgets.QMessageBox() + msg.setIcon(QtWidgets.QMessageBox.Critical) + msg.setText("You don't have any sounds in 'sound' folder") + msg.setInformativeText('download sound in .wav format') + msg.setWindowTitle('Error') + msg.exec_() + exit() + if os.path.exists('settings.json'): + hotkeys = jsonread(filename)[1] + sounds_list = [sounds, hotkeys] + else: + sounds_list = [sounds, ['', '', '', '', '', '', '', '', '', '', '', '']] + + for i in COMBOS: + i.addItems(sounds) + jsonwrite(filename, sounds_list) + else: + os.mkdir('sound') + msg = QtWidgets.QMessageBox() + msg.setIcon(QtWidgets.QMessageBox.Critical) + msg.setText("You don't have any sounds in 'sound' folder") + msg.setInformativeText('download sound in .wav format') + msg.setWindowTitle('Error') + msg.exec_() + exit() + return sounds_list + +def play_sound(index): # Проигрываение звука + #filename = sound_get('settings.json', False)[1][index] + filename = COMBOS[index].currentText() + try: + data, fs = sf.read(os.path.join('sound', filename), dtype='float32') + sd.play(data, fs) + sd.wait() + except: + pass + +def start(): + hotkeys = [] + sounds = sound_get('settings.json', False) + for i in COMBOS: + hotkeys.append(i.currentText()) + jsonwrite('settings.json', [sounds, hotkeys]) + sounds = None + hotkeys = None + + + +###! CONTROL !### +def key(arg): # Хоткеи + keyboard.add_hotkey('f1', play_sound, args=[0]) + keyboard.add_hotkey('f2', play_sound, args=[1]) + keyboard.add_hotkey('f3', play_sound, args=[2]) + keyboard.add_hotkey('f4', play_sound, args=[3]) + keyboard.add_hotkey('f5', play_sound, args=[4]) + keyboard.add_hotkey('f6', play_sound, args=[5]) + keyboard.add_hotkey('f7', play_sound, args=[6]) + keyboard.add_hotkey('f8', play_sound, args=[7]) + keyboard.add_hotkey('f9', play_sound, args=[8]) + keyboard.add_hotkey('f10', play_sound, args=[9]) + keyboard.add_hotkey('f11', play_sound, args=[10]) + keyboard.add_hotkey('f12', play_sound, args=[11]) + keyboard.wait(hotkey='alt+x') + main() + +def main(): # Интерфейс + win.show() + win.start_button.setText('Save') + sounds = sound_get('settings.json', True)[1] + + combo = 0 + for i in sounds: + index = COMBOS[combo].findText(i) + COMBOS[combo].setCurrentIndex(index) + combo += 1 + + x = threading.Thread(target=key, args=(1,)) + x.setDaemon(True) + x.start() + win.start_button.clicked.connect(start) + + +if __name__ == '__main__': + # Поиск устроства ввода + list_ = list(sd.query_devices()) + index = found_device(list_) + sd.default.device = list_[index]['name'] + + app = QtWidgets.QApplication([]) + win = uic.loadUi("sundpood.ui") + + COMBOS = [ + win.combo0, + win.combo1, + win.combo2, + win.combo3, + win.combo4, + win.combo5, + win.combo6, + win.combo7, + win.combo8, + win.combo9, + win.combo10, + win.combo11, + ] + + main() + sys.exit(app.exec()) diff --git a/sundpood.ui b/sundpood.ui new file mode 100644 index 0000000..c851a68 --- /dev/null +++ b/sundpood.ui @@ -0,0 +1,263 @@ + + + MainWindow + + + + 0 + 0 + 420 + 450 + + + + + 0 + 0 + + + + + 420 + 450 + + + + + 420 + 450 + + + + SundPood + + + + + + + true + + + + 0 + 0 + + + + + 420 + 450 + + + + + 420 + 450 + + + + + + 10 + 330 + 401 + 101 + + + + + Consolas + 28 + + + + START + + + + + + 110 + 10 + 301 + 308 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + 10 + 91 + 308 + + + + + + + F1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F2 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F3 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F4 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F5 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F6 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F7 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F8 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F9 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F10 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F11 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + F12 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + +