Mohamed Ali Bedair
Published © Apache-2.0

SmartListener - Ambient Sound Classifier using AI

The Smart Listener is a machine learning-based system that classifies ambient sounds in a home environment. Using the Infineon PSoC 6 AI Kit

IntermediateProtipOver 3 days487

Things used in this project

Hardware components

PSOC™ 6 AI Evaluation Kit (CY8CKIT-062S2-AI)
Infineon PSOC™ 6 AI Evaluation Kit (CY8CKIT-062S2-AI)
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1

Software apps and online services

ModusToolbox™ Software
Infineon ModusToolbox™ Software
Infineon DEEPCRAFT
MQTT
MQTT
FreeCAD

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

smartlistener_enclosure_OrOwUCStiQ.stl

Sketchfab still processing.

Code

ESC-50 Split script

Python
This script is used to split the ESC-50 data into separate folder one for each label
import pandas as pd
import shutil
import os

# Paths
ESC50_CSV = "./meta/esc50.csv"
ESC50_AUDIO_DIR = "./audio/"
OUTPUT_DIR = "./split_data/"

# Load CSV
df = pd.read_csv(ESC50_CSV)

# Create the base output directory if it doesn't exist
os.makedirs(OUTPUT_DIR, exist_ok=True)

# Loop through each unique category in the dataset
for category in df['category'].unique():
    # Create a folder for each category inside the output folder
    category_folder = os.path.join(OUTPUT_DIR, category)
    os.makedirs(category_folder, exist_ok=True)

    # Filter the filenames for the current category
    category_files = df[df['category'] == category]['filename'].tolist()

    # Copy each file into its respective category folder
    for file_name in category_files:
        src_path = os.path.join(ESC50_AUDIO_DIR, file_name)
        dst_path = os.path.join(category_folder, file_name)
        shutil.copy(src_path, dst_path)

    print(f"Copied {len(category_files)} files to folder: {category_folder}")

print("Finished splitting the dataset!")

Preprocessor script

Python
Used to convert all the training data to .wav format with 16kHz sample rate (compatible with DEEPCRAFT Studio)
from pydub import AudioSegment
import os

# ---- SETTINGS ----
input_folder = "raw_audio_files"   # Folder where your audio files are
output_folder = "processed_audio"  # Where converted files will be saved

target_sample_rate = 16000  # 16 kHz
target_format = "wav"       # DeepCraft needs WAV

# ---- FUNCTION ----
def process_audio(file_path, output_path):
    audio = AudioSegment.from_file(file_path)
    audio = audio.set_frame_rate(target_sample_rate)
    audio = audio.set_channels(1)  # Mono
    audio.export(output_path, format=target_format)

# ---- RUN ----
if not os.path.exists(output_folder):
    os.makedirs(output_folder)

for root, dirs, files in os.walk(input_folder):
    for file in files:
        if file.lower().endswith((".wav", ".mp3", ".flac", ".ogg", ".m4a")):
            input_path = os.path.join(root, file)
            output_path = os.path.join(output_folder, os.path.splitext(file)[0] + ".wav")
            print(f"Processing {input_path} -> {output_path}")
            process_audio(input_path, output_path)

print("\n✅ All files processed!")

Full project repository

Credits

Mohamed Ali Bedair
8 projects • 5 followers
Engineer/Maker

Comments