| """ |
| Project Friday β Identity Enrollment Utility |
| Run this script to teach FRIDAY your face and voice. |
| """ |
|
|
| import os |
| import sys |
| import time |
| import numpy as np |
| import cv2 |
| import sounddevice as sd |
|
|
| |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) |
|
|
| from app.core.identity import identity |
| from app.services.camera import camera |
|
|
| def enroll(): |
| print("=" * 60) |
| print(" FRIDAY SOVEREIGN IDENTITY ENROLLMENT") |
| print("=" * 60) |
| print("\n[STEP 1/2] FACE ENROLLMENT") |
| print("Please look directly at your camera and smile.") |
| time.sleep(2) |
| |
| |
| print("Initializing hardware sensor...") |
| for _ in range(10): |
| camera.capture_snapshot() |
| time.sleep(0.1) |
|
|
| while True: |
| frame = camera.capture_snapshot() |
| if frame is not None: |
| |
| cv2.imwrite("debug_face.jpg", frame) |
| |
| success = identity.enroll_face(frame) |
| if success: |
| print("β Face Identity Encoded.") |
| if os.path.exists("debug_face.jpg"): os.remove("debug_face.jpg") |
| break |
| else: |
| print("β Face not detected. (Saved 'debug_face.jpg' for your review)") |
| input("Ensure you are well-lit and press Enter to retry...") |
| else: |
| print("β Camera Hardware Not Accessible.") |
| print("TIP: If you just granted permissions, please restart your Terminal.") |
| return |
|
|
| print("\n[STEP 2/2] VOICE ENROLLMENT") |
| print("I need to hear you say 'Hey Friday' 3 times to learn your voice.") |
| |
| samples = [] |
| for i in range(3): |
| print(f"\nPrompt {i+1}: Say 'Hey Friday' now...") |
| |
| duration = 2.0 |
| fs = 16000 |
| recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16') |
| sd.wait() |
| samples.append(recording.flatten()) |
| print("β Sample Captured.") |
|
|
| success = identity.enroll_voice(samples) |
| if success: |
| print("\n" + "=" * 60) |
| print(" ENROLLMENT COMPLETE!") |
| print(" FRIDAY is now bound to your unique identity, Sir.") |
| print("=" * 60) |
| else: |
| print("\nβ Voice Enrollment Failed.") |
|
|
| if __name__ == "__main__": |
| enroll() |
|
|