Friday-Subconscious / backend /identity_setup.py
Paritosh Upadhyay
Neural Core: Cloud Anchor
5196bf2
"""
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
# Add project root to path
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)
# WARM UP: Capture several frames to allow auto-exposure to adjust
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:
# SAVE DEBUG FRAME: So user can see what's wrong if it fails
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...")
# Record 2 seconds at 16kHz
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()