I want to play a beep sound when there's a face show on webcam. The program works, but it slows down when I use winsound.Beep(). Is there any other way where I can play a sound like an alarm sound when someone's face shows up without lagging? Here is my code, thanks in advance.
import cv2
import random
import winsound
trained_face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
webcam = cv2.VideoCapture(0)
while True:
success_read, frame1 = webcam.read()
gray = cv2.cvtColor(frame1, cv2.COLOR_RGB2GRAY)
face_coordinates = trained_face.detectMultiScale(gray)
print(face_coordinates)
if len(face_coordinates) > 0:
winsound.Beep(500, 200)
for (x, y, w, h) in face_coordinates:
cv2.rectangle(frame1, (x, y), (x + w, y + h),(random.randrange(128, 256), random.randrange(128, 256), random.randrange(128, 256)), 2)
if cv2.waitKey(10) == ord('q'):
break
cv2.imshow('Face Detector', frame1)