Started working on recorder. Using python, Tkinter, and Arecord

This commit is contained in:
Jacob Stevens 2022-07-21 11:14:58 -05:00
parent 216d88e3ce
commit 9fd7115e6e
1 changed files with 76 additions and 0 deletions

76
Pi-Recorder.py Normal file
View File

@ -0,0 +1,76 @@
#!/usr/bin/python
from ntpath import altsep
import os
import tkinter as tk
from tkinter import *
def checkUSB():
stream = os.popen('lsusb | grep "Audio" | cut -d" " -f7')
output = stream.read()
if (output.find("PreSonus") != -1):
return True
else:
return False
def checkRecordStatus():
stream = os.popen('screen -list | grep -c "Pi-ARecord" || true')
output = stream.read()
if (output.find("1")):
return True
else:
return False
def record():
if checkRecordStatus():
os.system('screen -S record -X stuff "^C"')
btn_record_var.set('Start Recording')
else:
if (checkUSB()):
os.system('screen -S record -d -m arecord -D plughw:2,0 -f dat -vv /home/pi/test_input.wav')
btn_record_var.set('Stop Recording')
else:
btn_record_var.set('PreSonus N/A')
### tkinter variables
run_tk = True
light_mode = True
### tkinter theme
btn_light_color = '#BA09C6'
btn_dark_color = '#3C0340'
bg_light_color = '#F171DA'
bg_dark_color = '#8a3f7c'
text_light_color = '#000000'
text_dark_color = '#adadad'
### tkinter functions
def onExit():
global run_tk
if checkRecordStatus():
record()
run_tk = False
main_window.destroy()
exit()
def btnRecord():
record()
### tkinter main window setup
main_window = Tk()
main_window.attributes("-fullscreen", False)
main_window.protocol("WM_DELETE_WINDOW", onExit)
main_window.configure(background=bg_light_color)
main_window.title("Momo\'s Awesome Recorder")
main_window.columnconfigure(0, weight=1)
main_window.columnconfigure(1, weight=1)
main_window.columnconfigure(2, weight=1)
### tkinter record button
btn_record_var = tk.StringVar()
btn_record_var.set('Start Recording')
btn_record = Button(main_window, textvariable=btn_record_var, bg=btn_light_color, command=btnRecord)
btn_record.grid(column=0, row=0, sticky='NSEW', padx=5, pady=5)
while run_tk:
main_window.update_idletasks()
main_window.update()