I Built an AI Human That Reads Emotions: The Artificial Emotion Engine Explained
The Artificial Emotion Engine reads visible signals from a webcam and microphone (a smile, a raised brow, a wave, a raised voice), then answers through a 3D avatar named Arjun. Faces are read in seven steps: MediaPipe landmarks, an upright face snapshot, an EfficientNet-B0 CNN, FACS muscle rules, a 65/35 fusion, a personal resting-face baseline and smoothing. In this video, its builder explains each step and shares its real accuracy: 100% on happy faces and 64.9% across seven expressions on 209 real faces.
Key points
- The engine reads visible signals, not feelings, and every label carries a confidence.
- Computer vision runs in the browser, so raw video never leaves the laptop.
- A face is read in seven steps: landmarks, snapshot, CNN, FACS rules, fusion, personalisation, smoothing.
- A small EfficientNet-B0 matched a bigger B2 (69.3%) and was faster (34 ms vs 46 ms per face).
- On 209 real faces: 100% for happy, 31% for fear, 64.9% mean through the full pipeline.
- Arjun's emotions are a simulation with two safety rules. The language model can't set them.
- Never use emotion recognition to judge people.
How does the Artificial Emotion Engine read a face?
- Landmarks: MediaPipe finds 478 face points and 52 blendshapes in the browser, smoothed by a One Euro filter.
- Snapshot: about six times a second, an upright 224×224 face crop goes to the local engine. It's analysed in memory and never stored.
- CNN: EmotionNet (HSEmotion EfficientNet-B0, trained on AffectNet) classifies the face and its mirror image, then averages them.
- FACS rules: muscle-movement rules, for example laugh = cheek raise + lip-corner pull + lips part + jaw drop.
- Fusion: 65% CNN and 35% rules, weighted by image quality.
- Personalisation: each expression is measured against the user's own relaxed face.
- Smoothing: a label changes only when a new expression clearly leads.
Why does vision run in the browser?
Two Web Workers run MediaPipe on the laptop's GPU through WebGL, so raw video never leaves the page. Only packets of numbers, about 1.5 KB each, travel over a WebSocket to a FastAPI engine on 127.0.0.1. That is faster and lighter than streaming frames to Python, and it keeps the video private.
How accurate is it?
| Expression | Full pipeline | CNN alone |
|---|---|---|
| Happy | 100% | 93% |
| Surprise | 73% | 73% |
| Neutral | 70% | 40% |
| Sad | 67% | 73% |
| Disgust | 67% | 80% |
| Anger | 47% | 73% |
| Fear | 31% | 52% |
| Mean | 64.9% | 69.3% |
The pipeline scores below the CNN on still photos on purpose. People lower their brows to concentrate on live calls, so a frown now needs the CNN's agreement. That cut false "frowning" on relaxed faces from 21 cases to 9, and raised correct "neutral" readings from 40% to 70%. Figures are from the project's evaluation, re-run on 28 November 2026.
How does "artificial emotion" work?
Arjun's feelings are not a neural network. A small dynamical model tracks seven emotions (happiness, sadness, curiosity, surprise, excitement, calmness and empathy) plus a slow mood. A reflex mirrors a smile in about 26 ms, while his emotion label changes in about 0.4 seconds, so his mood doesn't flicker. A frown is never mirrored back as anger, and the language model can't set his emotions.
What are the limits?
The engine reads visible signals, not feelings. Expressions vary with culture, neurodiversity, lighting and camera angle, so emotion recognition should never be used for hiring, grading, credit or policing. The EU AI Act prohibits it in workplaces and schools, with narrow exceptions.
Chapters
- Meet Arjun, my AI human
- What is the Artificial Emotion Engine?
- The architecture: three layers
- Deep learning and CNNs, simply
- How a face is read: 7 steps
- Why personalisation matters
- The deep-learning models inside
- Why a small CNN beat bigger ones
- How accurate is it on real faces?
- What broke while building it
- Artificial emotion and the 3D avatar
- Privacy, limits and my take
Transcript
Show the full transcript
That's Arjun. He isn't a recording, and there's no actor behind him. He's a 3D AI human I built, and he watches my face, my hands and my voice through an ordinary laptop webcam, then reacts the way a person would. Smile, and he smiles back. Look sad for a few seconds, and he asks if you want to talk. Say "dance karo", and he does bhangra. In this video, I'll show you exactly how I built him: the deep learning, the CNN that reads expressions, how artificial emotion works, what broke along the way, and how accurate it really is. And all of it runs on a normal laptop, with no special GPU. I call the project the Artificial Emotion Engine. It runs in your web browser, with a small Python service on the same computer. And one rule shaped every decision I made: it reads visible signals, not feelings. A smile is a muscle movement. No camera can see what someone actually feels. So every label says "appears" or "looks", with a confidence score. And Arjun's own emotions are a simulation, designed to communicate clearly. He notices more than faces, too: a wave, a namaste, a handshake, a nod, eating, a phone call, a yawn. If you turn away to talk to someone else, he waits quietly, instead of answering words that weren't meant for him. And he speaks Hindi, English and Hinglish, replying in whatever language you use. Here's the big picture. There are three layers. The browser sees. A local Python engine reads and feels. And the 3D avatar answers. The most important decision was running computer vision inside the browser. Two Web Workers, which are background threads, run Google's MediaPipe models on the laptop's GPU through WebGL. So raw video never leaves the page. Only small packets of numbers, about one and a half kilobytes each, travel over a WebSocket to an engine on 127.0.0.1, which is your own computer. Compared with streaming video frames to a Python OpenCV process, that cuts latency and bandwidth, and keeps your video private. The engine uses FastAPI, with three layers whose dependencies point only one way: perception, then emotion, then expression. Before we go deeper, what is deep learning? It's machine learning with neural networks that have many layers. Each layer learns slightly more complex patterns than the one before. For images, the classic network is a CNN, a convolutional neural network. Picture a small window, called a filter, sliding across the image. Early filters find simple things, like edges and corners. Deeper layers combine them into shapes: an eye, the curve of a lip, a raised brow. And the last layer turns all of that into probabilities. How likely is this face to be happy, sad or surprised? Nobody writes these filters by hand. The network learns them from labelled examples. The expression CNN I use was trained on AffectNet, a dataset of about 400,000 real-world face photos. So how does Arjun read a face? Seven steps. Step one: landmarks. MediaPipe finds 478 points on your face, 52 blendshapes, which are scores for movements like a smile, a brow raise or a blink, and the angle of your head. A One Euro filter smooths them, removing jitter without adding lag. Step two: a face snapshot. About six times a second, the browser turns your face upright using the eye corners, crops it, and sends a 224 pixel image to the engine. It's analysed in memory and never stored. Step three: the CNN. EmotionNet classifies the snapshot and its mirror image, and averages the two. That trick is called test-time augmentation. Step four: FACS rules. The Facial Action Coding System is a standard catalogue of facial muscle movements. For example, a laugh is a cheek raise, plus a lip-corner pull, plus parted lips, plus a jaw drop. Step five: fusion. The engine blends 65% CNN with 35% rules. The rules catch subtle sadness the CNN misses, and the CNN vetoes rule mistakes, like crying being read as laughing. Step six: personalisation. And step seven: smoothing, so a label only changes when a new expression clearly leads, and the reading doesn't flicker. Personalisation matters more than it sounds. Some people rest with low brows, and look angry to a model trained on other faces. In one test, a user's relaxed face read 0.30–0.45 "sad" to the CNN, while their genuinely sad face read 0.60–0.78. Subtracting the resting level left too little signal. So now the engine also counts the rise in odds over that person's own resting reading. On that user's sessions, clear sad moments were caught 89% of the time, instead of eighty-five. So which neural networks are inside? Five handle perception and speech. MediaPipe's Face Landmarker, its Gesture Recognizer for 21 points per hand, and its Pose Landmarker for 33 body points, all run on the browser's GPU. EmotionNet is an EfficientNet-B0 CNN from the open-source HSEmotion project. It runs on the CPU through ONNX Runtime, and it's only sixteen megabytes. And Whisper turns speech into text, offline. For conversation, with an OpenAI key, the engine uses the Realtime API for a live voice call that answers in under a second. The classic chain of speech-to-text, a reply and text-to-speech takes two to four seconds. And without a key, a local model through Ollama, or built-in offline replies, take over. Everything else is plain rules, on purpose, because rules are explainable and instant. Here's something that surprised me. I compared seven CNNs on the same 209 face crops, on a laptop CPU. The small EfficientNet-B0 scored 69.3%, in 34 milliseconds per face. The bigger B2 tied it exactly, but took forty-six. MobileViT reached 65.5%, and needed 97 milliseconds. An ensemble of three models gained at most two points, for about four times the CPU, and none of them improved sadness. So here, bigger was slower, not better. So how accurate is it? I tested the full pipeline on 209 faces from AffectNet-HQ, about thirty per expression. Every happy face was read correctly. Surprise, seventy-three percent. Neutral, seventy. Sad and disgust, sixty-seven. Anger, forty-seven. And fear, just thirty-one. The mean is 64.9%, a bit lower than the CNN alone, at 69.3%. And that gap is deliberate. In live video calls, people lower their brows to concentrate or while talking. An early version labelled users "frowning" 57% of the time in a live call. So now a frown needs the CNN's support. That cut false frowns on relaxed faces from 21 cases to nine, and raised correct neutral readings from forty percent to seventy. The cost shows up in anger and fear. The system is tuned for a calm, friendly conversation on a live webcam, not for scoring well on still photos. Now, what broke? A lot. First, laughs were read as smiles. MediaPipe's jaw-open score barely moved, even in big laughs. The opening showed up somewhere else, so I used both signals. Second, Arjun thought you were surprised after every smile, because the resting-face baseline learned at the wrong moments. Now it only learns while your face is calm. Third, adding a second CNN made results worse. Its outputs sat on a different scale, and happiness on smiling faces fell from 0.79 to 0.53. Fourth, laptop cameras sit above the screen, and people tip their heads back to laugh, so the head-angle limits had to widen. And fifth, battery saver slowed face tracking two to three times. Today the project has 231 automated tests, and all of them pass. So how does Arjun feel? His feelings are not a neural network. They come from a small dynamical model of seven emotions: happiness, sadness, curiosity, surprise, excitement, calmness and empathy, plus a slow mood. Your expression, tone and gestures push targets, and each emotion rises and falls at its own speed. He reacts at two speeds, like people do. A reflex starts mirroring your smile in about 26 milliseconds. But his emotion label changes slowly, about 0.4 seconds to happy, so his mood doesn't flip on every flicker. Two safety rules live inside the engine. A frown is never mirrored back as anger. It's met with concern. And the language model can't set Arjun's emotions. It only suggests what your words mean, and the engine decides, with a cap on every step. The avatar itself is a rigged character from Microsoft's Rocketbox library, rendered with three.js at about sixty frames per second. His face uses 52 blendshapes, his arms are placed with two-bone inverse kinematics, like in games, and his lips follow the real audio. Privacy was a design rule, not an afterthought. Camera video never leaves the browser. Face numbers and the small crop stay in the local engine, analysed in memory and never stored. Your words go to OpenAI only if you set a key. And chat memory is off by default. One more important limit. Displayed expressions vary with culture, neurodiversity, lighting and camera angle. So this kind of technology should never be used for hiring, grading, credit or policing. The EU's AI Act already bans emotion recognition in workplaces and schools, with narrow exceptions. And it can't detect lies or intent. My honest take? The deep-learning models were the easy part. The hard part was everything around them: learning each person's resting face, not mistaking concentration for anger, and choosing concern over mirroring when someone frowns. The full write-up, with every number, is on bytemuni.com. Tell me in the comments: what would you want an AI like Arjun to do?




