Project 02

Spell Caster: Voice-Driven RPG with Emotion-Aware Spell Casting

A voice-controlled spellcasting prototype that hears the spell and the emotion behind it, then hands both to the game.

  • Apr to May 2026
  • Python
  • PyTorch
  • Whisper-Small
  • LoRA
  • +4
An ice spell effect in the Unity game, with snowflakes, a castle, and the player's gauntlet visible.
Fear maps to ice. The microphone indicator shows the client is listening; the spell and emotion come from one API response.

Context

Problem

Voice control in a game is usually a menu shortcut. We wanted the spell and the emotion behind it to matter, which means transcribing a short, noisy utterance and classifying the speaker's affect at the same time, on a laptop CPU.

Reading

Research & prior art

  1. 01

    Radford et al. (2023), “Robust Speech Recognition via Large-Scale Weak Supervision,” ICML.

    Whisper's weak supervision gave us a transcription model that handled short, noisy game commands without a domain-specific corpus. We kept the base model frozen and adapted only the emotion head, because full fine-tuning would have given up the data and latency advantages.

  2. 02

    Gulati et al. (2020), “Conformer: Convolution-augmented Transformer for Speech Recognition,” Interspeech.

    The Conformer's convolution blocks capture local acoustic detail while attention models longer context. We built a 5.05M-parameter version from scratch as the CPU-friendly comparison; it was small enough to export, but not accurate enough to replace Whisper.

  3. 03

    Hu et al. (2021), “LoRA: Low-Rank Adaptation of Large Language Models,” ICLR.

    LoRA let us train 0.73% of Whisper-Small's parameters for the six-class emotion head. The important detail is that the transcription weights stayed stock; only the emotion adapter was fine-tuned.

  4. 04

    Cao et al. (2014), “CREMA-D: Crowd-sourced Emotional Multimodal Actors Dataset,” IEEE Transactions on Affective Computing.

    CREMA-D gave us six acted emotions with controlled variation in speaker, sentence, and intensity. It is cleaner than in-game speech, so the 0.7543 F1 is an upper bound on what the game would see.

  5. 05

    Kendall et al. (2018), “Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics,” CVPR.

    Kendall weighting let the ASR and SER heads contribute to one loss without hand-tuning a fixed ratio. It is a principled alternative to a grid search over loss weights.

Trade-offs

Approaches compared

Whisper-Small with a LoRA-tuned emotion head

Strengths
WER 0.0015 and emotion F1 0.7543 on the evaluation. The base model is robust to short, noisy commands, and only 0.73% of its parameters are trainable.
Limits
The full Whisper path is heavier on CPU, and the report measured only the Conformer's latency, not Whisper's.
Verdict
The quality reference and the model I would start from. The missing Whisper latency measurement is the main gap.

From-scratch Conformer (5.05M parameters)

Strengths
WER 0.1128, emotion F1 0.5253, and 19.3 ms for a batch-1 CPU forward pass after ONNX INT8 export.
Limits
Much worse transcription and emotion quality than Whisper. Training from scratch on this data budget did not close the gap.
Verdict
The CPU-friendly comparison, not the better model. Its latency is real, but it is not worth the accuracy loss for the game.

Method

Approach

  1. 01

    Transcribe with Whisper-Small as the base model. LoRA is fine-tuned for the six-class emotion head only; the transcription weights are the stock ones.

  2. 02

    Train a second, smaller Conformer (5.05M parameters) from scratch with CTC and an attention-pooling SER head, as a CPU-friendly comparison.

  3. 03

    Combine the two objectives with Kendall uncertainty weighting, then export the Conformer to ONNX INT8.

  4. 04

    Return spell and emotion from a single FastAPI endpoint, falling back to neutral below 0.35 confidence.

  5. 05

    Integrate that endpoint into the Unity game with my teammate, who built the game mechanics and the C# client.

Contribution

What I personally built

  • I built the audio pipeline: Whisper-Small with a LoRA-tuned six-class emotion head, and the from-scratch Conformer with CTC and an attention-pooling SER head.
  • I combined the objectives with Kendall uncertainty weighting, exported the Conformer to ONNX INT8, and served spell and emotion from one FastAPI endpoint with a neutral fallback below 0.35 confidence.
  • I integrated the endpoint with my teammate's Unity client. The game mechanics and the C# client were my teammate's work.

Evidence

Results

  • 0.754

    Emotion F1

    Whisper-Small with a LoRA-tuned emotion head

  • 0.0015

    WER (Whisper)

    Whisper-Small, stock transcription weights

  • 0.113

    WER (Conformer)

    From-scratch Conformer, LibriSpeech

  • 19.3 ms

    CPU latency

    Conformer, batch size one, ONNX INT8

Architecture of the Spell Caster pipeline, from the Unity client through FastAPI to Whisper and the Conformer.
A single endpoint receives audio, transcribes it, classifies emotion, and maps the pair to a spell.
A fireball spell effect in the Unity game, with an on-screen readout showing the heard word, emotion, and confidence.
The fireball path. The client prints the recognised spell, emotion, and confidence beside the effect.
Confusion matrix for the six emotion classes predicted by the Whisper-Small emotion head.
Emotion confusion, six classes. Neutral is the easiest to confuse with everything else.
Bar chart of Conformer inference latency on CPU at batch size one after INT8 export, 19.3 ms.
Conformer on CPU at batch size one after INT8 export. The Whisper transcription path was not benchmarked.

Reflection

What I would do differently

The Conformer was the more interesting model to build and the worse one to ship: its WER was 0.113 against Whisper's 0.0015, and its only advantage was running comfortably on CPU. I would start from the strongest base model and spend the effort on the task-specific head, then measure latency on the path users actually take rather than on a benchmark in isolation. The report never measured the Whisper path on CPU, so the latency comparison is incomplete.