# AI Audio Detector
A machine learning system for detecting AI-generated audio using Benford's Law analysis and advanced audio feature extraction. The system employs ensemble learning with adaptive model updating capabilities.
## Features
- **Multi-Model Ensemble**: Uses Random Forest, Gradient Boosting, SGD, and Passive Aggressive classifiers
- **Benford's Law Analysis**: Analyzes frequency distributions for AI detection patterns
- **Comprehensive Audio Features**: Extracts spectral, temporal, and compression-related features
- **Adaptive Learning**: Supports incremental model updates with new data
- **Batch Processing**: Parallel processing for large audio datasets
- **Spectrogram Generation**: Creates and compares various types of spectrograms
- **Interactive CLI**: User-friendly command-line interface
## Supported Audio Formats
- WAV (.wav)
- MP3 (.mp3)
- FLAC (.flac)
- OGG (.ogg)
- M4A (.m4a)
- AAC (.aac)
## Installation
### Option 1: Install from PyPI (Recommended)
```bash
pip install ai-audio-detector
```
### Option 2: Install from Source
1. Clone the repository:
```bash
git clone https://github.com/ajprice16/AI_Audio_Detection.git
cd AI_Audio_Detection
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
### System Dependencies
On Ubuntu/Debian:
```bash
sudo apt-get install libsndfile1 ffmpeg
```
On macOS:
```bash
brew install libsndfile ffmpeg
```
## Quick Start
### Training Initial Models
1. **Prepare your data**: Organize your audio files into two directories:
- `human_audio/` - Human-generated audio files
- `ai_audio/` - AI-generated audio files
2. **Run the detector**:
**If installed from PyPI:**
```bash
ai-audio-detector --interactive
# or
ai-audio-detector --predict-file path/to/audio.wav
```
**If running from source:**
```bash
python -m ai_audio_detector --interactive
# or
python -m ai_audio_detector --predict-file path/to/audio.wav
```
3. **Choose option 1** to train new models and follow the prompts.
### Command Line Usage
**Train models:**
```bash
ai-audio-detector --train --human-dir path/to/human/audio --ai-dir path/to/ai/audio
```
**Predict single file:**
```bash
ai-audio-detector --predict-file path/to/audio.wav
```
**Predict batch:**
```bash
ai-audio-detector --predict-batch path/to/audio/directory
```
**Interactive mode:**
```bash
ai-audio-detector --interactive
```
### Predicting Single Files
**Interactive mode:**
```bash
ai-audio-detector --interactive
# Choose option 2 and enter the path to your audio file
```
**Direct command:**
```bash
ai-audio-detector --predict-file path/to/audio.wav
```
### Batch Prediction
**Interactive mode:**
```bash
ai-audio-detector --interactive
# Choose option 3 and enter the directory path
```
**Direct command:**
```bash
ai-audio-detector --predict-batch path/to/audio/directory
```
## Advanced Usage
### Programmatic Usage
```python
from ai_audio_detector import AIAudioDetector
from pathlib import Path
# Initialize detector
detector = AIAudioDetector(base_dir=Path.cwd())
# Train models
human_features = detector.extract_features_from_directory("human_audio/", is_ai_directory=False)
ai_features = detector.extract_features_from_directory("ai_audio/", is_ai_directory=True)
all_features = human_features + ai_features
df_results = pd.DataFrame(all_features)
training_results = detector.train_models(df_results)
# Make predictions
result = detector.predict_file("test_audio.wav")
print(f"Prediction: {'AI' if result['is_ai'] else 'Human'}")
print(f"Confidence: {result['confidence']:.3f}")
```
### Adaptive Learning
The system supports adaptive learning to improve accuracy with new data:
```python
# Add new AI data
detector.add_ai_data("new_ai_audio/", retrain_batch_models=True)
# Add new human data
detector.add_human_data("new_human_audio/", retrain_batch_models=True)
# Add mixed data batch
directories = [
{'path': 'dataset1/', 'is_ai': True},
{'path': 'dataset2/', 'is_ai': False}
]
detector.add_mixed_data_batch(directories, retrain_batch_models=True)
```
## Features Extracted
### Benford's Law Features
- Chi-square test statistics
- Kolmogorov-Smirnov test statistics
- Mean absolute deviation from expected distribution
- Maximum deviation
- Entropy measures
### Spectral Features
- Spectral centroid, bandwidth, rolloff
- MFCCs (13 coefficients + standard deviations)
- Chroma features
- Spectral contrast
- Zero crossing rate
### Temporal Features
- RMS energy (mean and standard deviation)
- Tempo estimation
- Spectral flatness
- Dynamic range
- Peak-to-RMS ratio
### Compression Features
- Estimated bit depth
- Clipping detection
- DC offset
- High frequency content ratio
## Model Architecture
The system uses an ensemble of four different models:
1. **Incremental Models** (for adaptive learning):
- SGD Classifier with log loss
- Passive Aggressive Classifier
2. **Batch Models** (for maximum accuracy):
- Random Forest (200 estimators)
- Gradient Boosting (200 estimators)
All features are standardized using StandardScaler, and final predictions use ensemble averaging.
## Configuration
Modify `config.yaml` to customize:
- Model parameters
- Feature extraction settings
- Processing options
- Output directories
## Command Line Options
1. **Train new models** - Initial training from audio directories
2. **Predict single file** - Analyze one audio file
3. **Predict batch** - Analyze all files in a directory
4. **Update models** - Adaptive learning with new data
5. **Add AI data** - Add new AI samples to existing models
6. **Add Human data** - Add new human samples to existing models
7. **Batch directories** - Add multiple directories at once
8. **Training history** - View model training history
9. **Data balance** - Check AI vs Human data balance
10. **Create visualizations** - Generate analysis plots
11. **Generate spectrograms** - Create spectrograms for audio files
12. **Spectrogram comparison** - Compare AI vs Human spectrograms
## Output Files
- `models/ai_audio_detector.joblib` - Trained models and metadata
- `training_results.csv` - Detailed training data and features
- `ai_detection_analysis.png` - Visualization plots
- `spectrograms/` - Generated spectrogram images
- `spectrogram_comparisons/` - Side-by-side comparisons
## Performance Considerations
- **Multiprocessing**: Automatically used for batches > 3 files
- **Memory Management**: Spectrograms are generated efficiently with proper cleanup
- **Scalability**: Incremental learning allows handling large datasets over time
## Requirements
- Python 3.7+
- librosa (audio processing)
- scikit-learn (machine learning)
- pandas, numpy (data manipulation)
- matplotlib (visualization)
- scipy (statistical tests)
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request
## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Acknowledgments
- Uses Benford's Law for detecting artificial patterns in audio
- Built on librosa for robust audio feature extraction
- Employs scikit-learn for machine learning capabilities
## Citation
If you use this work in your research, please cite:
```bibtex
@software{ai_audio_detector,
title={AI Audio Detector: Machine Learning System for Detecting AI-Generated Audio},
author={Alex Price},
year={2025},
url={https://github.com/yourusername/ai-audio-detector}
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ajprice16/AI_Audio_Detection",
"name": "ai-audio-detector",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "ai detection audio machine-learning benford-law audio-analysis",
"author": "Alex Price",
"author_email": "ajprice@mail.wlu.edu",
"download_url": "https://files.pythonhosted.org/packages/f5/e1/7cb726ed353a1c8f3e28801b9a9da25e2c7d52e501ced47d8b44c56b2560/ai_audio_detector-1.0.7.tar.gz",
"platform": null,
"description": "# AI Audio Detector\n\nA machine learning system for detecting AI-generated audio using Benford's Law analysis and advanced audio feature extraction. The system employs ensemble learning with adaptive model updating capabilities.\n\n## Features\n\n- **Multi-Model Ensemble**: Uses Random Forest, Gradient Boosting, SGD, and Passive Aggressive classifiers\n- **Benford's Law Analysis**: Analyzes frequency distributions for AI detection patterns\n- **Comprehensive Audio Features**: Extracts spectral, temporal, and compression-related features\n- **Adaptive Learning**: Supports incremental model updates with new data\n- **Batch Processing**: Parallel processing for large audio datasets\n- **Spectrogram Generation**: Creates and compares various types of spectrograms\n- **Interactive CLI**: User-friendly command-line interface\n\n## Supported Audio Formats\n\n- WAV (.wav)\n- MP3 (.mp3)\n- FLAC (.flac)\n- OGG (.ogg)\n- M4A (.m4a)\n- AAC (.aac)\n\n## Installation\n\n### Option 1: Install from PyPI (Recommended)\n\n```bash\npip install ai-audio-detector\n```\n\n### Option 2: Install from Source\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/ajprice16/AI_Audio_Detection.git\ncd AI_Audio_Detection\n```\n\n2. Install dependencies:\n```bash\npip install -r requirements.txt\n```\n\n### System Dependencies\n\nOn Ubuntu/Debian:\n```bash\nsudo apt-get install libsndfile1 ffmpeg\n```\n\nOn macOS:\n```bash\nbrew install libsndfile ffmpeg\n```\n\n## Quick Start\n\n### Training Initial Models\n\n1. **Prepare your data**: Organize your audio files into two directories:\n - `human_audio/` - Human-generated audio files\n - `ai_audio/` - AI-generated audio files\n\n2. **Run the detector**:\n\n**If installed from PyPI:**\n```bash\nai-audio-detector --interactive\n# or\nai-audio-detector --predict-file path/to/audio.wav\n```\n\n**If running from source:**\n```bash\npython -m ai_audio_detector --interactive\n# or\npython -m ai_audio_detector --predict-file path/to/audio.wav\n```\n\n3. **Choose option 1** to train new models and follow the prompts.\n\n### Command Line Usage\n\n**Train models:**\n```bash\nai-audio-detector --train --human-dir path/to/human/audio --ai-dir path/to/ai/audio\n```\n\n**Predict single file:**\n```bash\nai-audio-detector --predict-file path/to/audio.wav\n```\n\n**Predict batch:**\n```bash\nai-audio-detector --predict-batch path/to/audio/directory\n```\n\n**Interactive mode:**\n```bash\nai-audio-detector --interactive\n```\n\n### Predicting Single Files\n\n**Interactive mode:**\n```bash\nai-audio-detector --interactive\n# Choose option 2 and enter the path to your audio file\n```\n\n**Direct command:**\n```bash\nai-audio-detector --predict-file path/to/audio.wav\n```\n\n### Batch Prediction\n\n**Interactive mode:**\n```bash\nai-audio-detector --interactive\n# Choose option 3 and enter the directory path\n```\n\n**Direct command:**\n```bash\nai-audio-detector --predict-batch path/to/audio/directory\n```\n\n## Advanced Usage\n\n### Programmatic Usage\n\n```python\nfrom ai_audio_detector import AIAudioDetector\nfrom pathlib import Path\n\n# Initialize detector\ndetector = AIAudioDetector(base_dir=Path.cwd())\n\n# Train models\nhuman_features = detector.extract_features_from_directory(\"human_audio/\", is_ai_directory=False)\nai_features = detector.extract_features_from_directory(\"ai_audio/\", is_ai_directory=True)\n\nall_features = human_features + ai_features\ndf_results = pd.DataFrame(all_features)\ntraining_results = detector.train_models(df_results)\n\n# Make predictions\nresult = detector.predict_file(\"test_audio.wav\")\nprint(f\"Prediction: {'AI' if result['is_ai'] else 'Human'}\")\nprint(f\"Confidence: {result['confidence']:.3f}\")\n```\n\n### Adaptive Learning\n\nThe system supports adaptive learning to improve accuracy with new data:\n\n```python\n# Add new AI data\ndetector.add_ai_data(\"new_ai_audio/\", retrain_batch_models=True)\n\n# Add new human data\ndetector.add_human_data(\"new_human_audio/\", retrain_batch_models=True)\n\n# Add mixed data batch\ndirectories = [\n {'path': 'dataset1/', 'is_ai': True},\n {'path': 'dataset2/', 'is_ai': False}\n]\ndetector.add_mixed_data_batch(directories, retrain_batch_models=True)\n```\n\n## Features Extracted\n\n### Benford's Law Features\n- Chi-square test statistics\n- Kolmogorov-Smirnov test statistics\n- Mean absolute deviation from expected distribution\n- Maximum deviation\n- Entropy measures\n\n### Spectral Features\n- Spectral centroid, bandwidth, rolloff\n- MFCCs (13 coefficients + standard deviations)\n- Chroma features\n- Spectral contrast\n- Zero crossing rate\n\n### Temporal Features\n- RMS energy (mean and standard deviation)\n- Tempo estimation\n- Spectral flatness\n- Dynamic range\n- Peak-to-RMS ratio\n\n### Compression Features\n- Estimated bit depth\n- Clipping detection\n- DC offset\n- High frequency content ratio\n\n## Model Architecture\n\nThe system uses an ensemble of four different models:\n\n1. **Incremental Models** (for adaptive learning):\n - SGD Classifier with log loss\n - Passive Aggressive Classifier\n\n2. **Batch Models** (for maximum accuracy):\n - Random Forest (200 estimators)\n - Gradient Boosting (200 estimators)\n\nAll features are standardized using StandardScaler, and final predictions use ensemble averaging.\n\n## Configuration\n\nModify `config.yaml` to customize:\n- Model parameters\n- Feature extraction settings\n- Processing options\n- Output directories\n\n## Command Line Options\n\n1. **Train new models** - Initial training from audio directories\n2. **Predict single file** - Analyze one audio file\n3. **Predict batch** - Analyze all files in a directory\n4. **Update models** - Adaptive learning with new data\n5. **Add AI data** - Add new AI samples to existing models\n6. **Add Human data** - Add new human samples to existing models\n7. **Batch directories** - Add multiple directories at once\n8. **Training history** - View model training history\n9. **Data balance** - Check AI vs Human data balance\n10. **Create visualizations** - Generate analysis plots\n11. **Generate spectrograms** - Create spectrograms for audio files\n12. **Spectrogram comparison** - Compare AI vs Human spectrograms\n\n## Output Files\n\n- `models/ai_audio_detector.joblib` - Trained models and metadata\n- `training_results.csv` - Detailed training data and features\n- `ai_detection_analysis.png` - Visualization plots\n- `spectrograms/` - Generated spectrogram images\n- `spectrogram_comparisons/` - Side-by-side comparisons\n\n## Performance Considerations\n\n- **Multiprocessing**: Automatically used for batches > 3 files\n- **Memory Management**: Spectrograms are generated efficiently with proper cleanup\n- **Scalability**: Incremental learning allows handling large datasets over time\n\n## Requirements\n\n- Python 3.7+\n- librosa (audio processing)\n- scikit-learn (machine learning)\n- pandas, numpy (data manipulation)\n- matplotlib (visualization)\n- scipy (statistical tests)\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests if applicable\n5. Submit a pull request\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Acknowledgments\n\n- Uses Benford's Law for detecting artificial patterns in audio\n- Built on librosa for robust audio feature extraction\n- Employs scikit-learn for machine learning capabilities\n\n## Citation\n\nIf you use this work in your research, please cite:\n\n```bibtex\n@software{ai_audio_detector,\n title={AI Audio Detector: Machine Learning System for Detecting AI-Generated Audio},\n author={Alex Price},\n year={2025},\n url={https://github.com/yourusername/ai-audio-detector}\n}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Machine learning system for detecting AI-generated audio using Benford's Law and advanced spectral features",
"version": "1.0.7",
"project_urls": {
"Bug Reports": "https://github.com/ajprice16/AI_Audio_Detection/issues",
"Documentation": "https://github.com/ajprice16/AI_Audio_Detection#readme",
"Homepage": "https://github.com/ajprice16/AI_Audio_Detection",
"Source": "https://github.com/ajprice16/AI_Audio_Detection"
},
"split_keywords": [
"ai",
"detection",
"audio",
"machine-learning",
"benford-law",
"audio-analysis"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "aa096a026e41b5f3bce0ac153ce591e697aec2934ea5c750057a24adbf9234ce",
"md5": "7823253c803a1d48a652a3aafd7d1221",
"sha256": "2cc598f362791287ff27986d63751fbcbbb9944c304eecaaecad2d89040a741b"
},
"downloads": -1,
"filename": "ai_audio_detector-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7823253c803a1d48a652a3aafd7d1221",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 34359,
"upload_time": "2025-07-18T23:01:55",
"upload_time_iso_8601": "2025-07-18T23:01:55.544602Z",
"url": "https://files.pythonhosted.org/packages/aa/09/6a026e41b5f3bce0ac153ce591e697aec2934ea5c750057a24adbf9234ce/ai_audio_detector-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f5e17cb726ed353a1c8f3e28801b9a9da25e2c7d52e501ced47d8b44c56b2560",
"md5": "9cc1dd71fa5b2038dc7bd1b5b98beafd",
"sha256": "4d5bb9475f59ca27053960b63ad5c9a2b6b61d62869b83e9f67ae773a8886d91"
},
"downloads": -1,
"filename": "ai_audio_detector-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "9cc1dd71fa5b2038dc7bd1b5b98beafd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 36624,
"upload_time": "2025-07-18T23:01:56",
"upload_time_iso_8601": "2025-07-18T23:01:56.955458Z",
"url": "https://files.pythonhosted.org/packages/f5/e1/7cb726ed353a1c8f3e28801b9a9da25e2c7d52e501ced47d8b44c56b2560/ai_audio_detector-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-18 23:01:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ajprice16",
"github_project": "AI_Audio_Detection",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.21.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"1.3.0"
]
]
},
{
"name": "librosa",
"specs": [
[
">=",
"0.9.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.7.0"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.4.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.62.0"
]
]
},
{
"name": "joblib",
"specs": [
[
">=",
"1.1.0"
]
]
},
{
"name": "pyyaml",
"specs": [
[
">=",
"6.0"
]
]
},
{
"name": "pathlib",
"specs": []
}
],
"lcname": "ai-audio-detector"
}