Flutter Snore Detection

A Flutter package for detecting snoring in real-time audio streams or pre-recorded audio files using TensorFlow Lite.

Features

  • 🎀 Live Audio Detection: Real-time snoring detection from device microphone
  • πŸ“ File-Based Detection: Analyze pre-recorded audio files
  • πŸš€ Easy Integration: Simple API for developers
  • ⚑ Efficient: Uses quantized TensorFlow Lite model optimized for mobile devices
  • πŸ“± Cross-Platform: Works on Android and iOS

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  snore_detection: ^0.2.0

Then run:

flutter pub get

For detailed installation instructions and platform setup, see the Installation Guide.

Usage

Live Audio Detection

import 'package:snore_detection/snore_detection.dart';

// Initialize detector
final detector = SnoreDetector();
await detector.initialize();

// Start live detection
detector.startLiveDetection(
  onResult: (result) {
    print('Snoring detected: ${result.isSnoring}');
    print('Confidence: ${result.confidence}');
  },
);

// Stop detection
await detector.stopLiveDetection();

File-Based Detection

import 'package:snore_detection/snore_detection.dart';

// Initialize detector
final detector = SnoreDetector();
await detector.initialize();

// Analyze audio file
final result = await detector.detectFromFile('/path/to/audio.wav');
print('Snoring detected: ${result.isSnoring}');
print('Confidence: ${result.confidence}');

Running the Example App

To see the package in action, run the example app:

cd example
flutter pub get
flutter run

The example app demonstrates:

  • Live audio detection with real-time results
  • Visual feedback (icons, colors, confidence scores)
  • Start/stop controls
  • History of recent detections

Make sure you have a device or emulator connected, then select your target platform when prompted.

Permissions

Android

Add to your AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

iOS

Add to your Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access to detect snoring</string>

Model Information

  • Input: 16 kHz mono audio, 1-second windows
  • Output: Binary classification (noise vs snoring)
  • Model Type: Quantized TensorFlow Lite (INT8)
  • Model Size: 214 KB
  • Processing: Spectrogram-based feature extraction
  • Inference Time: ~50-100ms per 1-second window

Documentation

Troubleshooting

Issue: Microphone permission denied

  • Ensure permissions are properly configured in platform-specific files
  • The package automatically requests permission on first use

Issue: Model fails to load

  • Make sure flutter pub get has been run
  • Check that the asset is accessible in your build

Issue: Low accuracy

  • Ensure quiet environment with minimal background noise
  • Check microphone quality and placement
  • Consider using confidence thresholds (e.g., > 0.85)

License

MIT License - see LICENSE file for details

Credits

Based on the Snoring Guardian project.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Libraries

snore_detection
A Flutter package for real-time and file-based snoring detection using TensorFlow Lite.