SpeechSense is an AI-powered mobile application that analyzes speech patterns to detect potential signs of intoxication or cognitive impairment. By having users read randomly generated tongue twisters aloud, the app captures audio, processes it through machine learning models, and provides feedback on cognitive function.
This project consists of a Flutter mobile app and a Python Flask backend server. The app is designed for educational and experimental purposes to explore speech-based cognitive assessment.
- Speech Analysis: Records and analyzes audio while users read tongue twisters
- AI Detection: Uses machine learning to identify speech patterns indicative of impairment
- User Authentication: Firebase-based sign-in and registration
- History Tracking: Stores and displays past analysis results
- Cross-Platform: Built with Flutter for iOS and Android
- Privacy-Focused: Audio data is processed locally and optionally stored securely
- User Registration/Login: Users create an account via Firebase authentication
- Script Generation: The app requests a random tongue twister from the server
- Audio Recording: User reads the script aloud while the app records audio
- Speech Recognition: Server verifies the spoken text matches the script (at least 50% similarity)
- AI Analysis: Machine learning model analyzes audio features (MFCCs) to predict impairment status
- Results Storage: Results are stored in Firebase Firestore with optional audio upload
- Feedback Display: App shows analysis results and history
-
For Server (Raspberry Pi):
- Python 3.7+
- Internet connection for Firebase and speech recognition
- Firebase project with Firestore and Storage enabled
-
For Mobile App:
- Flutter SDK (3.5.4+)
- Android Studio or Xcode for building
- Mobile device or emulator
The backend server handles script generation, speech recognition, AI prediction, and data storage.
cd server
pip install -r requirements.txt- Create a Firebase project at https://console.firebase.google.com/
- Enable Firestore Database and Storage
- Generate a service account key (JSON file)
- Place the JSON file in
server/directory asfirebase_options.py
Example firebase_options.py:
import firebase_admin
from firebase_admin import credentials, firestore, storage
cred = credentials.Certificate('path/to/serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
'storageBucket': 'your-project-id.appspot.com'
})
db = firestore.client()
bucket = storage.bucket()If you need to retrain the model:
cd server
python main.pyThis will train an SVM model using the audio data in data/ and save it as intoxication_model.pkl.
cd server
python server.pyThe server will run on http://0.0.0.0:5000 (accessible from other devices on the network).
Follow the official Flutter installation guide: https://flutter.dev/docs/get-started/install
cd flutter_app
flutter pub getIf using Firebase features:
- Add Firebase to your Flutter project
- Configure authentication and Firestore in the app
For Android:
flutter build apk
flutter installFor iOS:
flutter build ios
flutter installFor Development:
flutter runIn the Flutter app code, update the server URL in API calls (e.g., in customHttpClient.dart) to point to your Raspberry Pi's IP address.
- Start the Server: Run the Flask server on your Raspberry Pi
- Install the App: Build and install the Flutter app on your mobile device
- Register/Login: Create an account in the app
- Perform Analysis: Tap "Perform Analysis" to get a script, read it aloud
- View Results: Check your analysis history in the app
- Frontend: Flutter (Dart)
- Backend: Python Flask
- AI/ML: Scikit-learn SVM, Librosa for audio processing
- Speech Recognition: Google Speech Recognition API
- Database: Firebase Firestore
- Storage: Firebase Cloud Storage
- Authentication: Firebase Auth
SpeechSense/
├── flutter_app/ # Flutter mobile application
│ ├── lib/ # Dart source code
│ ├── android/ # Android build files
│ ├── ios/ # iOS build files
│ └── pubspec.yaml # Flutter dependencies
├── server/ # Python backend server
│ ├── main.py # ML model training
│ ├── server.py # Flask API server
│ ├── tongue_twister.py # Script generation and speech recognition
│ ├── firebase_options.py # Firebase configuration
│ ├── requirements.txt # Python dependencies
│ └── data/ # Training audio data
└── README.md
This application is for educational and experimental purposes only. It does not provide medical diagnoses and should not be used as a substitute for professional medical advice. Results may not be 100% accurate.
Contributions are welcome! Please feel free to submit issues and pull requests.