-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_voice_analysis.py
More file actions
305 lines (238 loc) · 8.15 KB
/
Copy pathsetup_voice_analysis.py
File metadata and controls
305 lines (238 loc) · 8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
"""
Quick Setup Script for Voice Analysis
Run this to set up your project structure and check dependencies
"""
import os
import sys
import subprocess
def check_dependencies():
"""Check if required packages are installed"""
print("="*60)
print("Checking Dependencies...")
print("="*60)
required = {
'librosa': 'Audio processing',
'parselmouth': 'Praat analysis (jitter, shimmer)',
'sklearn': 'Machine learning',
'joblib': 'Model persistence',
'pandas': 'Data handling',
'numpy': 'Numerical computing',
'tensorflow': 'Deep learning',
'flask': 'Web framework'
}
missing = []
for package, description in required.items():
try:
__import__(package)
print(f"✅ {package:20} - {description}")
except ImportError:
print(f"❌ {package:20} - {description} (MISSING)")
missing.append(package)
if missing:
print(f"\n⚠️ Missing packages: {', '.join(missing)}")
print("\nInstall them with:")
print(f"pip install {' '.join(missing)}")
return False
else:
print("\n✅ All dependencies installed!")
return True
def create_folder_structure():
"""Create necessary folders"""
print("\n" + "="*60)
print("Creating Folder Structure...")
print("="*60)
folders = [
'models/voice_model',
'static/uploads',
'static/voice_uploads',
'templates',
'voice_dataset/healthy',
'voice_dataset/parkinson'
]
for folder in folders:
os.makedirs(folder, exist_ok=True)
print(f"✅ Created: {folder}")
print("\n✅ Folder structure created!")
def download_sample_dataset():
"""Provide instructions for downloading dataset"""
print("\n" + "="*60)
print("Dataset Setup")
print("="*60)
print("""
📦 To train the voice model, you need audio data:
Option 1 - Download Existing Dataset:
🔗 UCI Parkinson's Speech: https://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset
🔗 Kaggle Dataset: https://www.kaggle.com/datasets/dipayanbiswas/parkinsons-disease-speech-signal-features
Option 2 - Create Your Own:
1. Record "Aaaah" sounds (5-10 seconds each)
2. Save healthy recordings in: voice_dataset/healthy/
3. Save parkinson recordings in: voice_dataset/parkinson/
4. Minimum: 50 samples per class
5. Format: WAV files (16kHz or 22kHz sample rate)
Recording Guidelines:
• Quiet room
• Clear pronunciation
• Consistent distance from microphone
• Natural voice (don't force)
""")
def create_test_script():
"""Create a simple test script"""
test_code = '''#!/usr/bin/env python
"""
Quick test script for voice analysis system
"""
def test_feature_extraction():
"""Test if feature extraction works"""
print("Testing feature extraction...")
try:
from audio_features import VoiceFeatureExtractor
extractor = VoiceFeatureExtractor()
print("✅ Feature extractor loaded")
return True
except Exception as e:
print(f"❌ Error: {e}")
return False
def test_model_files():
"""Check if model files exist"""
import os
print("\\nChecking model files...")
model_path = 'models/voice_model'
required_files = ['voice_model.h5', 'scaler.pkl', 'model_type.txt']
if not os.path.exists(model_path):
print("❌ Model folder not found")
print(" Run training first: python train_voice_model.py")
return False
missing = []
for file in required_files:
filepath = os.path.join(model_path, file)
if os.path.exists(filepath):
print(f"✅ {file}")
else:
print(f"❌ {file} (missing)")
missing.append(file)
if missing:
print("\\n⚠️ Train the model first: python train_voice_model.py")
return False
return True
def test_spiral_model():
"""Check spiral model"""
import os
print("\\nChecking spiral model...")
if os.path.exists('models/parkinson_model.h5'):
print("✅ Spiral model found")
return True
else:
print("❌ Spiral model not found at models/parkinson_model.h5")
return False
if __name__ == "__main__":
print("="*60)
print("Voice Analysis System - Quick Test")
print("="*60)
results = []
results.append(test_feature_extraction())
results.append(test_spiral_model())
results.append(test_model_files())
print("\\n" + "="*60)
if all(results):
print("✅ All tests passed! System ready.")
print("\\nRun: python app_combined.py")
else:
print("⚠️ Some tests failed. Check messages above.")
print("="*60)
'''
with open('test_system.py', 'w') as f:
f.write(test_code)
print("\n✅ Created test_system.py")
print(" Run: python test_system.py")
def create_readme():
"""Create README file"""
readme = """# Parkinson's Disease Detection - Voice Analysis Extension
## Quick Start
### 1. Install Dependencies
```bash
pip install -r requirements_voice.txt
```
### 2. Prepare Dataset
- Place healthy voice recordings in `voice_dataset/healthy/`
- Place parkinson voice recordings in `voice_dataset/parkinson/`
- Minimum 50 samples per class
### 3. Train Model
```bash
python train_voice_model.py
```
### 4. Run Application
```bash
python app_combined.py
```
Then open: http://localhost:5000
## Features
- 🌀 **Spiral Drawing Analysis** - Tests motor control
- 🎤 **Voice Analysis** - Detects speech abnormalities
- 🔬 **Combined Testing** - Multi-modal assessment
## File Structure
```
project/
├── app_combined.py # Main application
├── audio_features.py # Feature extraction
├── train_voice_model.py # Model training
├── predict_voice.py # Voice prediction
├── models/
│ ├── parkinson_model.h5 # Spiral model
│ └── voice_model/ # Voice model
└── voice_dataset/ # Training data
```
## Testing
```bash
python test_system.py
```
## Troubleshooting
See IMPLEMENTATION_GUIDE.md for detailed help.
"""
with open('README_VOICE.md', 'w') as f:
f.write(readme)
print("✅ Created README_VOICE.md")
def main():
"""Main setup function"""
print("""
╔══════════════════════════════════════════════════════════════╗
║ ║
║ 🧠 Parkinson's Disease Detection - Voice Analysis Setup ║
║ ║
╚══════════════════════════════════════════════════════════════╝
""")
# Check dependencies
deps_ok = check_dependencies()
# Create folders
create_folder_structure()
# Create helper files
create_test_script()
create_readme()
# Dataset instructions
download_sample_dataset()
# Final instructions
print("\n" + "="*60)
print("Setup Complete!")
print("="*60)
if deps_ok:
print("""
✅ Next Steps:
1. Add your voice dataset:
- voice_dataset/healthy/*.wav
- voice_dataset/parkinson/*.wav
2. Train the voice model:
$ python train_voice_model.py
3. Test the system:
$ python test_system.py
4. Run the application:
$ python app_combined.py
📚 For detailed guide, see: IMPLEMENTATION_GUIDE.md
""")
else:
print("""
⚠️ Please install missing dependencies first:
$ pip install -r requirements_voice.txt
Then run this script again.
""")
print("="*60)
if __name__ == "__main__":
main()