diff --git a/alarm.mp3 b/alarm.mp3 new file mode 100644 index 0000000..0dd3fae Binary files /dev/null and b/alarm.mp3 differ diff --git a/camera.py b/camera.py index ef7cc08..1eaa9c5 100644 --- a/camera.py +++ b/camera.py @@ -5,6 +5,7 @@ from datetime import datetime import firebase_admin from firebase_admin import credentials, storage +from playsound import playsound # MQTT settings MQTT_BROKER = "broker.hivemq.com" @@ -15,6 +16,9 @@ FIREBASE_CREDENTIALS_PATH = "ServiceAccountKey.json" FIREBASE_STORAGE_BUCKET = "only-motion-detector.appspot.com" +# Alarm sound file path +ALARM_SOUND_PATH = "alarm.mp3" + # Initialize Firebase Admin SDK cred = credentials.Certificate(FIREBASE_CREDENTIALS_PATH) firebase_admin.initialize_app(cred, {'storageBucket': FIREBASE_STORAGE_BUCKET}) @@ -88,10 +92,11 @@ cv2.rectangle(frame1_macbook, (x, y), (x + w, y + h), (0, 255, 0), 2) motion_detected_macbook = True - # If motion is detected, publish to MQTT and print message + # If motion is detected, publish to MQTT, print message, and sound alarm if motion_detected_macbook: client.publish(MQTT_TOPIC, "Motion Detected (MacBook)") print("Motion Detected (MacBook)") + playsound(ALARM_SOUND_PATH) # Write the frame to the output file for MacBook camera out_macbook.write(frame1_macbook) @@ -121,10 +126,11 @@ cv2.rectangle(frame1_iphone, (x, y), (x + w, y + h), (0, 255, 0), 2) motion_detected_iphone = True - # If motion is detected, publish to MQTT and print message + # If motion is detected, publish to MQTT, print message, and sound alarm if motion_detected_iphone: client.publish(MQTT_TOPIC, "Motion Detected (iPhone)") print("Motion Detected (iPhone)") + playsound(ALARM_SOUND_PATH) # Write the frame to the output file for iPhone camera (if available) if iphone_camera.isOpened():