yoavzamir Claude Opus 4.6 commited on
Commit
020dc73
ยท
1 Parent(s): 4fb96f1

Update README with current algorithm, tech stack, and architecture

Browse files
Files changed (1) hide show
  1. README.md +71 -79
README.md CHANGED
@@ -6,118 +6,110 @@ colorTo: purple
6
  sdk: docker
7
  pinned: false
8
  ---
9
- # ๐ŸŽค Speech Analysis MVP - 'Sh' Sound Trainer
10
 
11
- ืžืขืจื›ืช ืœื ื™ืชื•ื— ื•ื–ื™ื”ื•ื™ ื”ื’ื™ื™ื” ืฉืœ ืฆืœื™ืœ ื”-"ืฉ" ื‘ืขื‘ืจื™ืช, ืขื ื™ื›ื•ืœืช ืื‘ื—ื•ืŸ ืฉื’ื™ืื•ืช ืกืคืฆื™ืคื™ื•ืช.
12
 
13
- ## โœจ ืชื›ื•ื ื•ืช
14
 
15
- - **ื ื™ืชื•ื— DTW**: ื”ืฉื•ื•ืื” ืžื‘ื•ืกืกืช Dynamic Time Warping ืขืœ ืชื›ื•ื ื•ืช MFCC
16
- - **ื–ื™ื”ื•ื™ ืคื•ื ืžื•ืช**: ื‘ื™ื“ื•ื“ ืื•ื˜ื•ืžื˜ื™ ืฉืœ ืฆืœื™ืœ ื”-"ืฉ" ืžืชื•ืš ื”ืžื™ืœื”
17
- - **ืื‘ื—ื•ืŸ ืฉื’ื™ืื•ืช**: ื–ื™ื”ื•ื™ ืกื•ื’ ื”ืฉื’ื™ืื” (ื”ื—ืœืคื” ื‘-ืก', ื”ืฉืžื˜ื”, ืขื™ื•ื•ืช)
18
- - **ืžืžืฉืง ืื™ื ื˜ืจืืงื˜ื™ื‘ื™**: ื”ืงืœื˜ื” ื‘ื–ืžืŸ ืืžืช ืขื ืžืฉื•ื‘ ืžื™ื™ื“ื™
 
 
 
 
19
 
20
- ## ๐Ÿ“ ืžื‘ื ื” ื”ืคืจื•ื™ืงื˜
 
 
21
 
22
  ```
23
- speechai/
24
- โ”œโ”€โ”€ audio_data/ # ืงื‘ืฆื™ ืื•ื“ื™ื• ืœืื™ืžื•ืŸ (ref_* = ืชืงื™ืŸ, err_* = ืฉื’ื•ื™)
25
- โ”œโ”€โ”€ calibrate.py # ื›ื™ื•ืœ ื•ื‘ื“ื™ืงืช ื”ืžื•ื“ืœ
26
- โ”œโ”€โ”€ score_engine.py # ืžื ื•ืข ื”ื ื™ืงื•ื“ ื•ื”ืื‘ื—ื•ืŸ
27
- โ”œโ”€โ”€ simulate.py # ืžืžืฉืง ืื™ื ื˜ืจืืงื˜ื™ื‘ื™ ืœื”ืงืœื˜ื”
28
- โ”œโ”€โ”€ requirements.txt # ืชืœื•ื™ื•ืช Python
29
- โ””โ”€โ”€ README.md
30
  ```
31
 
32
- ## ๐Ÿš€ ื”ืชืงื ื”
33
 
34
- ### 1. ืฉื›ืคื•ืœ ื”ืคืจื•ื™ืงื˜
35
 
36
- ```bash
37
- git clone https://github.com/YOUR_USERNAME/speechai.git
38
- cd speechai
39
- ```
40
 
41
- ### 2. ื™ืฆื™ืจืช ืกื‘ื™ื‘ื” ื•ื™ืจื˜ื•ืืœื™ืช
42
 
43
- ```bash
44
- # Windows
45
- python -m venv venv
46
- venv\Scripts\activate
47
 
48
- # Linux/Mac
49
- python3 -m venv venv
50
- source venv/bin/activate
51
- ```
52
 
53
- ### 3. ื”ืชืงื ืช ืชืœื•ื™ื•ืช
54
 
55
- ```bash
56
- pip install -r requirements.txt
57
- ```
 
58
 
59
- ## ๐Ÿ“– ืฉื™ืžื•ืฉ
60
 
61
- ### ื›ื™ื•ืœ ื”ืžืขืจื›ืช
62
 
63
- ื‘ื“ื™ืงืช ื”ืคืจื“ื” ื‘ื™ืŸ ื”ืงืœื˜ื•ืช ืชืงื™ื ื•ืช ืœืฉื’ื•ื™ื•ืช:
 
 
 
 
64
 
65
- ```bash
66
- python calibrate.py
67
- ```
68
 
69
- ### ื ื™ืงื•ื“ ื”ืงืœื˜ื” ื‘ื•ื“ื“ืช
 
 
 
 
70
 
71
- ```bash
72
- python score_engine.py "path/to/recording.wav" shalom --pretty
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
- ```bash
90
- python simulate.py
 
 
 
 
 
 
 
 
 
91
  ```
92
 
93
- ## ๐Ÿ”ง ืกื•ื’ื™ ืฉื’ื™ืื•ืช ืžื–ื•ื”ื•ืช
94
-
95
- | ืกื•ื’ ืฉื’ื™ืื” | ืชื™ืื•ืจ | ืžืฉื•ื‘ |
96
- |-----------|--------|------|
97
- | `s_substitution` | ื”ื—ืœืคืช "ืฉ" ื‘-"ืก" | "ื”ื–ื– ืืช ื”ืœืฉื•ืŸ ืื—ื•ืจื”" |
98
- | `lateral_sh` | "ืฉ" ืจื˜ื•ื‘ื”/ืฆื“ื“ื™ืช | "ืฉืžื•ืจ ืืช ื”ืœืฉื•ืŸ ื‘ืžืจื›ื–" |
99
- | `omission` | ื”ืฉืžื˜ืช ื”ืฆืœื™ืœ | "ื”ืืจืš ืืช ื”ืฆืœื™ืœ" |
100
- | `distortion` | ืขื™ื•ื•ืช ื›ืœืœื™ | "ืขื’ืœ ืืช ื”ืฉืคืชื™ื™ื" |
101
-
102
- ## ๐Ÿ“Š ืคื•ืจืžื˜ ืงื‘ืฆื™ ื”ืื•ื“ื™ื•
103
 
104
- ืฉื ื”ืงื•ื‘ืฅ: `type_word_variation.wav`
 
 
105
 
106
- - `type`: `ref` (ืชืงื™ืŸ) ืื• `err` (ืฉื’ื•ื™)
107
- - `word`: ื”ืžื™ืœื” (ืœืžืฉืœ: shalom, shemesh)
108
- - `variation`: ื•ืจื™ืืฆื™ื” (normal, fast, slow, sub_s, wet_ch)
109
 
110
- ื“ื•ื’ืžืื•ืช:
111
- - `ref_shalom_normal.wav` - ื”ื’ื™ื™ื” ืชืงื™ื ื” ืฉืœ "ืฉืœื•ื"
112
- - `err_shalom_sub_s.wav` - ื”ื—ืœืคืช ืฉ' ื‘-ืก' ื‘ืžื™ืœื” "ืฉืœื•ื"
113
 
114
- ## ๐Ÿ› ๏ธ ื“ืจื™ืฉื•ืช ืžืขืจื›ืช
115
 
116
- - Python 3.9+
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