bytebard101/urbanecho

By bytebard101

β€’Updated 6 months ago

A ML classifier which predicts urban sound types from .wav files

Image
Languages & frameworks
Machine learning & AI
Data science
0

671

bytebard101/urbanecho repository overview

⁠πŸ’₯ UrbanEcho

This project regualarly maintained in Github. So please check out UrbanEcho GitHub Repo⁠.

UrbanEcho is a web-based audio classification project that predicts urban sound types from .wav files. It is built with Python, scikit-learn, and Flask, and uses a RandomizedSearchCV-tuned ML pipeline trained on tabular audio features extracted from the UrbanSound8K dataset.


β πŸš€ Features

  • Accepts .wav audio file uploads via a simple web interface.
  • Extracts 34 audio features per sample (MFCCs, Chroma, Spectral Contrast, Zero Crossing Rate, Spectral Centroid).
  • Predicts 10 classes of urban sounds:
    • air_conditioner
    • car_horn
    • children_playing
    • dog_bark
    • drilling
    • engine_idling
    • gun_shot
    • jackhammer
    • siren
    • street_music
  • Displays predicted class with class probabilities using visual progress bars.
  • Automatically cleans uploaded files after prediction.
  • Self-healing: if model files are missing, it retrains the pipeline automatically.

β πŸ–Ό Screenshots

Upload Page:
Upload Page

Prediction Result Page:
Result Page


β πŸ“ Project Structure

UrbanEcho/
β”œβ”€β”€ datasets/                         # Datasets used for training
β”‚ └── extracted_audio_features.csv
β”œβ”€β”€ models/                           # .pkl files go here
β”‚ β”œβ”€β”€ feature_names.pkl               # Not included with the repo
β”‚ └── pipe.pkl                        # Not included with the repo
β”œβ”€β”€ static/                           # Static files for the web app
β”‚ └── uploads/   
β”‚ └── style.css
β”œβ”€β”€ templates/                        # HTML code for front-end
β”‚ β”œβ”€β”€ index.html
β”‚ └── result.html
β”œβ”€β”€ utils/                            # Utility code for feature engineering
β”‚ └── feature_extractor.py
β”œβ”€β”€ app.py                            # Flask app
β”œβ”€β”€ fit.py                            # Python script for training the model
β”œβ”€β”€ requirements.txt                  # Libraries required for this project
└── research.ipynb                    # Notebook used for testing, visualization and many more

β πŸ—‚ Dataset

  • Source: UrbanSound8K Tabular Form⁠
  • Contains audio features extracted from real-world urban sounds.
  • 34 features per sample:
    • MFCC_1 … MFCC_13
    • Chroma_1 … Chroma_12
    • SpectralContrast_1 … SpectralContrast_7
    • ZeroCrossingRate
    • SpectralCentroid
  • 10 classes of urban sound.

β βš™ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/UrbanEcho.git
cd UrbanEcho
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the Web App:
python app.py

β πŸƒ How to use

  1. After running the app, open your browser and go to localhost:5000⁠
  2. The interface should appear instantly. Upload a .wav file and hit Predict
  3. The app will display:
    • Predicted class (human-readable label)
    • Probabilities for all classes in a progress-bar style visualization.

⁠🐳 Run the app directly via Dockerhub Image

This is my first project where I have implemented Docker containerization. I have created a Dockerhub repository⁠ where I have pushed the docker container.

The container is built on both ARM64 and AMD64 architectures, so that it can run on almost all major computers. You can run the app easily by using the Dockerhub Image. Here's how you can do it:

  1. Install Docker Desktop⁠ and sign-in

  2. Open Terminal and run this:

docker pull bytebard101/urbanecho:latest
docker run --rm -p 5000:5000 bytebard101/urbanecho:latest
  1. If your machine does not have the port 5000 free, you need to run in a different port. Try to run this:
docker run --rm -p 5001:5000 bytebard101/urbanecho:latest

If you followed Step 2 and the command ran successfully, then DO NOT follow this step.

  1. The app will be live at localhost:5000. Open your browser and navigate to http://127.0.0.1:5000⁠ (or http://127.0.0.1:5001⁠ if you followed Step 3).

Check Docker Documentation⁠ to learn more about Docker and it's commands.


β πŸ“Š Model Performance

  • Algorithm: RandomForest (RandomizedSearchCV tuned)
  • Cross-validated F1-score: 0.91

Classification report on test set:

ClassPrecisionRecallF1-scoreSupport
0 (air_conditioner)0.940.970.96334
1 (car_horn)0.910.830.87143
2 (children_playing)0.800.870.84328
3 (dog_bark)0.880.840.86326
4 (drilling)0.940.910.93333
5 (engine_idling)0.950.950.95333
6 (gun_shot)0.990.840.91125
7 (jackhammer)0.910.990.95334
8 (siren)0.940.930.94307
9 (street_music)0.850.830.84329
Accuracy / Weighted avg0.910.910.912892

⁠⚑️ Notes / Limitations

  • Single .wav predictions can show messy probabilities due to PCA and class overlap.

  • Model is trained on tabular features, not raw audio β€” deep learning could improve predictions significantly.

  • If models/pipe.pkl or models/feature_names.pkl are deleted, the app will retrain the model automatically (may take a few minutes).

  • Because of the lack of extra contributors and my lack of front-end expertise, I had to use AI tools (mostly LLM services like ChatGPTβ„’, Grokβ„’, Geminiβ„’) in order to create a sophisticated front end for the web app. The HTML and CSS were written by those tools.

  • The static/style.css file is currently blank. I have used <style/> tag and inline method in HTML files to generate the style. It will be updated in future if needed.


β πŸ“Œ Author

Sakib ( ByteBard58 )

Student | Aspiring Computer Engineer | AI & ML Enthusiast

πŸ“ GitHub Profile: ByteBard58⁠


β πŸ˜ƒ Appreciation

Thank you for taking the time to review my work. I hope you enjoyed it and found it intriguing. It would mean a lot to me if you could star it on GitHub. 🌟 If you would like to contribute to this repository, please do so. It will be a great help!

If you have any questions, suggestions, or anything else you’d like to discuss, please don’t hesitate to reach out. You can find my contact information on my GitHub profile page⁠. I’m all ears! 😊

Have a great day!

Tag summary

Content type

Image

Digest

sha256:858036ef3…

Size

1.3 GB

Last updated

6 months ago

docker pull bytebard101/urbanecho