Spaces:
Running
Running
Update README with current algorithm, tech stack, and architecture
Browse files
README.md
CHANGED
|
@@ -6,118 +6,110 @@ colorTo: purple
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
-
#
|
| 10 |
|
| 11 |
-
|
| 12 |
|
| 13 |
-
##
|
| 14 |
|
| 15 |
-
|
| 16 |
-
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
##
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
โโโ calibrate.py # ืืืื ืืืืืงืช ืืืืื
|
| 26 |
-
โโโ score_engine.py # ืื ืืข ืื ืืงืื ืืืืืืื
|
| 27 |
-
โโโ simulate.py # ืืืฉืง ืืื ืืจืืงืืืื ืืืงืืื
|
| 28 |
-
โโโ requirements.txt # ืชืืืืืช Python
|
| 29 |
-
โโโ README.md
|
| 30 |
```
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
git clone https://github.com/YOUR_USERNAME/speechai.git
|
| 38 |
-
cd speechai
|
| 39 |
-
```
|
| 40 |
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
# Windows
|
| 45 |
-
python -m venv venv
|
| 46 |
-
venv\Scripts\activate
|
| 47 |
|
| 48 |
-
|
| 49 |
-
python3 -m venv venv
|
| 50 |
-
source venv/bin/activate
|
| 51 |
-
```
|
| 52 |
|
| 53 |
-
###
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
###
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
python calibrate.py
|
| 67 |
-
```
|
| 68 |
|
| 69 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
``
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
```json
|
| 77 |
-
{
|
| 78 |
-
"score": 85,
|
| 79 |
-
"status": "PASS",
|
| 80 |
-
"error_type": "none",
|
| 81 |
-
"feedback": "Great job! Your 'Sh' sound is clear and accurate!"
|
| 82 |
-
}
|
| 83 |
-
```
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
```
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
```
|
| 92 |
|
| 93 |
-
##
|
| 94 |
-
|
| 95 |
-
| ืกืื ืฉืืืื | ืชืืืืจ | ืืฉืื |
|
| 96 |
-
|-----------|--------|------|
|
| 97 |
-
| `s_substitution` | ืืืืคืช "ืฉ" ื-"ืก" | "ืืื ืืช ืืืฉืื ืืืืจื" |
|
| 98 |
-
| `lateral_sh` | "ืฉ" ืจืืืื/ืฆืืืืช | "ืฉืืืจ ืืช ืืืฉืื ืืืจืื" |
|
| 99 |
-
| `omission` | ืืฉืืืช ืืฆืืื | "ืืืจื ืืช ืืฆืืื" |
|
| 100 |
-
| `distortion` | ืขืืืืช ืืืื | "ืขืื ืืช ืืฉืคืชืืื" |
|
| 101 |
-
|
| 102 |
-
## ๐ ืคืืจืื ืงืืฆื ืืืืืื
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
- `variation`: ืืจืืืฆืื (normal, fast, slow, sub_s, wet_ch)
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
##
|
| 115 |
|
| 116 |
-
|
| 117 |
-
-
|
| 118 |
-
- Windows / Linux / macOS
|
| 119 |
|
| 120 |
-
##
|
| 121 |
|
| 122 |
MIT License
|
| 123 |
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
+
# SpeechKid API - Hebrew 'Sh' Sound Pronunciation Trainer
|
| 10 |
|
| 11 |
+
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.
|
| 12 |
|
| 13 |
+
## Technology Stack
|
| 14 |
|
| 15 |
+
| Layer | Technology |
|
| 16 |
+
|-------|-----------|
|
| 17 |
+
| **AI Model** | Wav2Vec2 (`imvladikon/wav2vec2-large-xlsr-53-hebrew`) โ CTC forced alignment |
|
| 18 |
+
| **Audio Processing** | librosa, torchaudio, scipy โ spectral analysis, bandpass filtering |
|
| 19 |
+
| **Backend** | FastAPI + Uvicorn |
|
| 20 |
+
| **Deployment** | Hugging Face Spaces (Docker SDK), PyTorch CPU-only |
|
| 21 |
+
| **Clinical Engine** | OpenAI GPT-4o Structured Outputs โ diagnostic report generation |
|
| 22 |
+
| **Frontend** | Expo React Native app (separate repo) |
|
| 23 |
|
| 24 |
+
## How the Algorithm Works
|
| 25 |
+
|
| 26 |
+
### Processing Pipeline
|
| 27 |
|
| 28 |
```
|
| 29 |
+
Recording โ Silence Trimming โ Wav2Vec2 Forced Alignment โ ืฉ Segment Extraction
|
| 30 |
+
โ Bandpass Filter (3-8kHz) โ Spectral Centroid โ Binary Diagnosis
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
```
|
| 32 |
|
| 33 |
+
1. **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.
|
| 34 |
|
| 35 |
+
2. **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.
|
| 36 |
|
| 37 |
+
3. **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.
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
4. **Bandpass Filter** โ 4th-order Butterworth bandpass (3-8kHz) isolates the fricative frequency range.
|
| 40 |
|
| 41 |
+
5. **Spectral Centroid** โ Computes the frequency center of gravity on the bandpassed audio. This is device-invariant โ doesn't change with recording volume or distance.
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
6. **Binary Diagnosis** โ Two gates, both must pass:
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
### Diagnosis Gates
|
| 46 |
|
| 47 |
+
| Gate | Threshold | What it catches |
|
| 48 |
+
|------|-----------|-----------------|
|
| 49 |
+
| **AI Score** | Wav2Vec2 confidence โฅ 0.70 | Lisps, substitutions, wet CH, omission |
|
| 50 |
+
| **Centroid** | 2700โ5500 Hz | Too low = wet/lateral distortion; too high = S substitution |
|
| 51 |
|
| 52 |
+
Result: **CORRECT** (score 100) or **INCORRECT** (score 0).
|
| 53 |
|
| 54 |
+
### Key Techniques
|
| 55 |
|
| 56 |
+
- **CTC Forced Alignment**: Aligns Hebrew characters to audio frames using Connectionist Temporal Classification, providing per-character timestamps and confidence scores
|
| 57 |
+
- **Spectral Centroid Analysis**: Frequency center of gravity โ robust across devices, volumes, and recording distances (unlike energy-based measures)
|
| 58 |
+
- **Forward-Only Extraction**: Always extract audio forward from the detected onset, never backward into silence
|
| 59 |
+
- **Leading Silence Trimming**: Prevents alignment failure caused by long pre-speech silence on mobile recordings
|
| 60 |
+
- **Model Warmup**: Pre-loads Wav2Vec2 at startup via FastAPI lifespan to eliminate cold-start latency (~10s warmup vs ~2min on first request)
|
| 61 |
|
| 62 |
+
## API Endpoints
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
### `POST /evaluate`
|
| 65 |
+
Score a pronunciation recording.
|
| 66 |
+
- **file**: Audio file (WAV, M4A, AAC, WebM, etc.)
|
| 67 |
+
- **word**: Target word key (shalom, shemesh, shir, shuk, geshem, shshshsh, shaon, shulchan)
|
| 68 |
+
- **Returns**: `{ score, status, diagnosis, feedback, details, evidence }`
|
| 69 |
|
| 70 |
+
### `POST /diagnose_profile`
|
| 71 |
+
Generate a clinical diagnostic report via GPT-4o.
|
| 72 |
+
- **Body**: Intake questionnaire (child age, error patterns, history)
|
| 73 |
+
- **Returns**: Clinical hypothesis, intervention recommendation, exercises, app roadmap
|
| 74 |
|
| 75 |
+
## Supported Words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
ืฉืืื (shalom), ืฉืืฉ (shemesh), ืฉืืจ (shir), ืฉืืง (shuk), ืืฉื (geshem), ืฉืฉืฉืฉ (shshshsh), ืฉืขืื (shaon), ืฉืืืื (shulchan)
|
| 78 |
|
| 79 |
+
## Project Structure
|
| 80 |
|
| 81 |
+
```
|
| 82 |
+
speechkid-api/
|
| 83 |
+
โโโ score_engine.py # Main scoring pipeline โ trimming, extraction, diagnosis
|
| 84 |
+
โโโ phoneme_extractor.py # Wav2Vec2 forced alignment & ืฉ isolation
|
| 85 |
+
โโโ main.py # FastAPI backend (HF Spaces deployment)
|
| 86 |
+
โโโ simulate_remote.py # Terminal simulator โ records mic, calls HF API
|
| 87 |
+
โโโ simulate.py # Local terminal simulator โ scores without API
|
| 88 |
+
โโโ calibrate.py # Batch calibration tool
|
| 89 |
+
โโโ Dockerfile # HF Spaces Docker deployment
|
| 90 |
+
โโโ requirements.txt # Python dependencies
|
| 91 |
+
โโโ CLAUDE.md # AI assistant context file
|
| 92 |
```
|
| 93 |
|
| 94 |
+
## Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
```bash
|
| 97 |
+
# Install
|
| 98 |
+
pip install -r requirements.txt
|
| 99 |
|
| 100 |
+
# Test via terminal (calls HF Spaces API)
|
| 101 |
+
python simulate_remote.py
|
|
|
|
| 102 |
|
| 103 |
+
# Score a single file locally
|
| 104 |
+
python score_engine.py "recording.wav" shalom --pretty
|
| 105 |
+
```
|
| 106 |
|
| 107 |
+
## Deployment
|
| 108 |
|
| 109 |
+
Deployed on **Hugging Face Spaces** (Docker SDK) at:
|
| 110 |
+
`https://yoavzamir-speechkid-api.hf.space`
|
|
|
|
| 111 |
|
| 112 |
+
## License
|
| 113 |
|
| 114 |
MIT License
|
| 115 |
|