|
| 1 | +from io import BytesIO |
| 2 | +from tkinter import * |
| 3 | +from tkinter import messagebox |
| 4 | +import pygame |
| 5 | +from random import * |
| 6 | +from captcha.audio import AudioCaptcha |
| 7 | + |
| 8 | +audio = AudioCaptcha() |
| 9 | +pygame.mixer.init() |
| 10 | +captcha_text="" |
| 11 | + |
| 12 | +def create_audio_captcha(): |
| 13 | + global captcha_text |
| 14 | + captcha_text=str(randint(1000, 9999)) |
| 15 | + print(captcha_text) |
| 16 | + audio.write(captcha_text, "audio"+'.wav') |
| 17 | + |
| 18 | +create_audio_captcha() |
| 19 | + |
| 20 | +root=Tk() |
| 21 | +root.title("Audio Captcha") |
| 22 | + |
| 23 | +def play_audio(): |
| 24 | + pygame.mixer.music.load("audio"+'.wav') |
| 25 | + pygame.mixer.music.play() |
| 26 | + |
| 27 | +def verify_audio(): |
| 28 | + text = check.get("1.0", "end-1c") |
| 29 | + global captcha_text |
| 30 | + if(text==captcha_text): |
| 31 | + messagebox.showinfo("SUCCESS", "Verified") |
| 32 | + else: |
| 33 | + messagebox.showinfo("ALERT", "Not Verified") |
| 34 | + |
| 35 | +heading_label = Label(root, text="Enter the Audio Captcha", height=2, width=50) |
| 36 | +check = Text(root, height=2, width=50) |
| 37 | +play_button = Button(root, text="Play Audio", command=play_audio) |
| 38 | +submit=Button(root, text="Submit", command=verify_audio) |
| 39 | +renew=Button(root, text="Renew", command=create_audio_captcha) |
| 40 | + |
| 41 | +heading_label.pack() |
| 42 | +check.pack() |
| 43 | +play_button.pack(side=LEFT, padx=35, pady=5) |
| 44 | +renew.pack(side=LEFT, padx=40, pady=5) |
| 45 | +submit.pack(side=RIGHT, padx=35, pady=5) |
| 46 | + |
| 47 | +root.mainloop() |
| 48 | + |
0 commit comments