UNPKG

proctor-ai-sdk

Version:

A powerful SDK for preventing cheating during online exams using face detection, voice detection, and tab monitoring.

55 lines (44 loc) 1.89 kB
// import * as faceapi from "face-api.js"; // export const loadModels = async (modelUrl) => { // await Promise.all([ // faceapi.nets.tinyFaceDetector.loadFromUri(modelUrl), // faceapi.nets.faceExpressionNet.loadFromUri(modelUrl), // ]); // }; // export const detectSuspiciousBehavior = async (videoElement) => { // const detections = await faceapi // .detectAllFaces(videoElement, new faceapi.TinyFaceDetectorOptions()) // .withFaceExpressions(); // if (!detections.length) return { type: "no-face" }; // if (detections.length > 1) return { type: "multi-face" }; // const expressions = detections[0].expressions; // const sorted = Object.entries(expressions).sort((a, b) => b[1] - a[1]); // const topExpression = sorted[0][0]; // const suspicious = ["angry", "fearful", "sad", "disgusted", "surprised"]; // if (suspicious.includes(topExpression)) { // return { type: "suspicious-emotion", expression: topExpression }; // } // return { type: "normal", expression: topExpression }; // }; // File: index.js import { loadModels } from "./src/face/faceApiHelper.js"; import { startFaceMonitoring, stopMonitoring } from "./src/face/faceMonitor.js"; import { startTabSwitchDetector, stopTabSwitchDetector } from "./src/events/tabSwitchDetector.js"; import { startVoiceDetection, stopVoiceDetection } from "./src/audio/voiceDetector.js"; import { compareFaces } from "./src/face/faceMatcher.js"; import { exportLogs, onSuspiciousEvent, clearLogs } from "./src/logs/logger.js"; import { setReferenceFace } from "./src/face/faceMatcher.js"; export { loadModels, startFaceMonitoring, stopMonitoring, startTabSwitchDetector, stopTabSwitchDetector, startVoiceDetection, stopVoiceDetection, compareFaces, exportLogs, onSuspiciousEvent, clearLogs, setReferenceFace };