|
| 1 | +import sounddevice |
| 2 | +from scipy.io.wavfile import write |
| 3 | +from tkinter import * |
| 4 | +from tkinter.messagebox import showinfo, showwarning |
| 5 | +from tkinter.filedialog import askdirectory |
| 6 | + |
| 7 | +PRIMARY_FONT = ("Comic Sans MS", 18) |
| 8 | +SECONDARY_FONT = ("Comic Sans MS", 12) |
| 9 | + |
| 10 | + |
| 11 | +addr = "" |
| 12 | + |
| 13 | + |
| 14 | +def file_path(): |
| 15 | + global addr |
| 16 | + addr = askdirectory() |
| 17 | + l4["text"] = "Path : \n" + addr |
| 18 | + # print(addr) |
| 19 | + |
| 20 | + |
| 21 | +def savefile(): |
| 22 | + global addr |
| 23 | + global filename |
| 24 | + try: |
| 25 | + time = int(sec.get()) |
| 26 | + add = addr + "/" + str(filename.get()) + ".wav" |
| 27 | + showinfo(title="Start", message="Recording started") |
| 28 | + rece = sounddevice.rec(frames=time * 44100, samplerate=44100, channels=2) |
| 29 | + sounddevice.wait() |
| 30 | + write(add, rate=44100, data=rece) |
| 31 | + showinfo(title="End", message="Recording stopped") |
| 32 | + |
| 33 | + except: |
| 34 | + showwarning(title="Wrong Time", message="Wrong format of time!!!") |
| 35 | + |
| 36 | + |
| 37 | +def main_window(): |
| 38 | + global sec, filename, l4 |
| 39 | + win = Tk() |
| 40 | + win.geometry("500x600") |
| 41 | + win.resizable(False, False) |
| 42 | + win.title("Voice Recorder") |
| 43 | + win.config(bg="Lightblue") |
| 44 | + |
| 45 | + img1 = PhotoImage(file="Images/voice.png") |
| 46 | + l1 = Label(win, image=img1, bg="Lightblue") |
| 47 | + l1.place(x=186, y=20, height=128, width=128) |
| 48 | + |
| 49 | + l2 = Label(win, text="Time in Sec", font=PRIMARY_FONT, bg="Lightblue") |
| 50 | + l2.place(x=0, y=180, height=50, width=200) |
| 51 | + |
| 52 | + sec = Entry(win, font=(20)) |
| 53 | + sec.place(x=180, y=180, height=50, width=200) |
| 54 | + |
| 55 | + b = Button(win, text="Select Path", font=SECONDARY_FONT, command=file_path) |
| 56 | + b.place(x=150, y=280, height=50, width=200) |
| 57 | + |
| 58 | + l4 = Label( |
| 59 | + win, text="Path : Path name here..." + addr, font=SECONDARY_FONT, bg="Lightblue" |
| 60 | + ) |
| 61 | + l4.place(x=10, y=330, height=50, width=500) |
| 62 | + |
| 63 | + img2 = PhotoImage(file="Images/mic.png") |
| 64 | + |
| 65 | + l3 = Label(text="File name : ", font=PRIMARY_FONT, bg="Gray") |
| 66 | + l3.place(x=60, y=400, height=50, width=150) |
| 67 | + |
| 68 | + filename = Entry(win, font=(20)) |
| 69 | + filename.place(x=210, y=400, height=50, width=250) |
| 70 | + filename.insert(0, "file1") |
| 71 | + |
| 72 | + start = Button(win, image=img2, bg="Darkgray", command=savefile) |
| 73 | + start.place(x=220, y=480, height=60, width=60) |
| 74 | + |
| 75 | + win.mainloop() |
| 76 | + |
| 77 | + |
| 78 | +# savefile(5) |
| 79 | +main_window() |
0 commit comments