Spaces:
Running
title: Speechkid API
emoji: ποΈ
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
SpeechKid API - Hebrew 'Sh' Sound Pronunciation Trainer
AI-powered pronunciation trainer for children learning the Hebrew 'Sh' (Χ©) sound. Uses Wav2Vec2 forced alignment + acoustic physics to grade pronunciation as CORRECT or INCORRECT in real-time. No reference audio needed β pure AI inference.
Technology Stack
| Layer | Technology |
|---|---|
| AI Model | Wav2Vec2 (imvladikon/wav2vec2-large-xlsr-53-hebrew) β CTC forced alignment |
| Audio Processing | librosa, torchaudio, scipy β spectral analysis, bandpass filtering |
| Backend | FastAPI + Uvicorn |
| Deployment | Hugging Face Spaces (Docker SDK), PyTorch CPU-only |
| Clinical Engine | OpenAI GPT-4o Structured Outputs β diagnostic report generation |
| Frontend | Expo React Native app (separate repo) |
How the Algorithm Works
Processing Pipeline
Recording β Silence Trimming β Wav2Vec2 Forced Alignment β Χ© Segment Extraction
β Bandpass Filter (3-8kHz) β Spectral Centroid β Binary Diagnosis
Silence Trimming β Removes leading silence (
librosa.effects.trim, top_db=25) so the AI model sees speech immediately. Mobile recordings often have 1-2s of dead air.Wav2Vec2 Forced Alignment β CTC forced alignment (
torchaudio.functional.forced_align) maps each Hebrew character to a time span + confidence score. The model identifies exactly where the Χ© sound starts.Segment Extraction β Extracts 120ms forward from the Wav2Vec2 onset of Χ©. Forward-only extraction avoids capturing pre-speech silence. Falls back to energy-peak scanning if alignment fails.
Bandpass Filter β 4th-order Butterworth bandpass (3-8kHz) isolates the fricative frequency range.
Spectral Centroid β Computes the frequency center of gravity on the bandpassed audio. This is device-invariant β doesn't change with recording volume or distance.
Binary Diagnosis β Two gates, both must pass:
Diagnosis Gates
| Gate | Threshold | What it catches |
|---|---|---|
| AI Score | Wav2Vec2 confidence β₯ 0.70 | Lisps, substitutions, wet CH, omission |
| Centroid | 2700β5500 Hz | Too low = wet/lateral distortion; too high = S substitution |
Result: CORRECT (score 100) or INCORRECT (score 0).
Key Techniques
- CTC Forced Alignment: Aligns Hebrew characters to audio frames using Connectionist Temporal Classification, providing per-character timestamps and confidence scores
- Spectral Centroid Analysis: Frequency center of gravity β robust across devices, volumes, and recording distances (unlike energy-based measures)
- Forward-Only Extraction: Always extract audio forward from the detected onset, never backward into silence
- Leading Silence Trimming: Prevents alignment failure caused by long pre-speech silence on mobile recordings
- Model Warmup: Pre-loads Wav2Vec2 at startup via FastAPI lifespan to eliminate cold-start latency (~10s warmup vs ~2min on first request)
API Endpoints
POST /evaluate
Score a pronunciation recording.
- file: Audio file (WAV, M4A, AAC, WebM, etc.)
- word: Target word key (shalom, shemesh, shir, shuk, geshem, shshshsh, shaon, shulchan)
- Returns:
{ score, status, diagnosis, feedback, details, evidence }
POST /diagnose_profile
Generate a clinical diagnostic report via GPT-4o.
- Body: Intake questionnaire (child age, error patterns, history)
- Returns: Clinical hypothesis, intervention recommendation, exercises, app roadmap
Supported Words
Χ©ΧΧΧ (shalom), Χ©ΧΧ© (shemesh), Χ©ΧΧ¨ (shir), Χ©ΧΧ§ (shuk), ΧΧ©Χ (geshem), Χ©Χ©Χ©Χ© (shshshsh), Χ©Χ’ΧΧ (shaon), Χ©ΧΧΧΧ (shulchan)
Project Structure
speechkid-api/
βββ score_engine.py # Main scoring pipeline β trimming, extraction, diagnosis
βββ phoneme_extractor.py # Wav2Vec2 forced alignment & Χ© isolation
βββ main.py # FastAPI backend (HF Spaces deployment)
βββ simulate_remote.py # Terminal simulator β records mic, calls HF API
βββ simulate.py # Local terminal simulator β scores without API
βββ calibrate.py # Batch calibration tool
βββ Dockerfile # HF Spaces Docker deployment
βββ requirements.txt # Python dependencies
βββ CLAUDE.md # AI assistant context file
Quick Start
# Install
pip install -r requirements.txt
# Test via terminal (calls HF Spaces API)
python simulate_remote.py
# Score a single file locally
python score_engine.py "recording.wav" shalom --pretty
Deployment
Deployed on Hugging Face Spaces (Docker SDK) at:
https://yoavzamir-speechkid-api.hf.space
License
MIT License