Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • IBM Tackles New Approach to Quantum Error Correction
    • How Unfiltered AI Video Tools Are Redefining Accessibility
    • Royal Enfield Himalayan to feature 750cc engine
    • EIT Digital Venture Incubation Program 2025: Turn your digital tech idea into a real venture!
    • How Waymo Handles Footage From Events Like the LA Immigration Protests
    • Today’s NYT Connections: Sports Edition Hints, Answers for June 12 #262
    • Three Stages of Planetary Defense for Asteroid Threats
    • Exploring the Proportional Odds Model for Ordinal Logistic Regression
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Thursday, June 12
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»Audio Spectrogram Transformers Beyond the Lab
    Artificial Intelligence

    Audio Spectrogram Transformers Beyond the Lab

    Editor Times FeaturedBy Editor Times FeaturedJune 11, 2025No Comments8 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    Need to know what attracts me to soundscape evaluation?

    It’s a discipline that mixes science, creativity, and exploration in a method few others do. Initially, your laboratory is wherever your toes take you — a forest path, a metropolis park, or a distant mountain path can all turn out to be areas for scientific discovery and acoustic investigation. Secondly, monitoring a selected geographic space is all about creativity. Innovation is on the coronary heart of environmental audio analysis, whether or not it’s rigging up a customized system, hiding sensors in tree canopies, or utilizing solar energy for off-grid setups. Lastly, the sheer quantity of information is actually unimaginable, and as we all know, in spatial evaluation, all strategies are truthful sport. From hours of animal calls to the delicate hum of city equipment, the acoustic knowledge collected may be huge and sophisticated, and that opens the door to utilizing every little thing from deep studying to geographical data programs (GIS) in making sense of all of it.

    After my earlier adventures with soundscape analysis of one of Poland’s rivers, I made a decision to lift the bar and design and implement an answer able to analysing soundscapes in actual time. On this weblog submit, you’ll discover a description of the proposed technique, together with some code that powers the complete course of, primarily utilizing an Audio Spectrogram Transformer (AST) for sound classification.

    Out of doors/City model of the sensor prototype (picture by creator)

    Strategies

    Setup

    There are lots of explanation why, on this explicit case, I selected to make use of a mixture of Raspberry Pi 4 and AudioMoth. Imagine me, I examined a variety of units — from much less power-hungry fashions of the Raspberry Pi household, by numerous Arduino variations, together with the Portenta, all the way in which to the Jetson Nano. And that was just the start. Selecting the best microphone turned out to be much more difficult.

    Finally, I went with the Pi 4 B (4GB RAM) due to its stable efficiency and comparatively low energy consumption (~700mAh when working my code). Moreover, pairing it with the AudioMoth in USB microphone mode gave me plenty of flexibility throughout prototyping. AudioMoth is a strong system with a wealth of configuration choices, e.g. sampling charge from 8 kHz to beautiful 384 kHz. I’ve a robust feeling that — in the long term — this may show to be an ideal alternative for my soundscape research.

    AudioMoth USB Microphone configuration app. Keep in mind about flashing the system with the right firmware earlier than configuring.

    Capturing sound

    Capturing audio from a USB microphone utilizing Python turned out to be surprisingly troublesome. After fighting numerous libraries for some time, I made a decision to fall again on the nice previous Linux arecord. The entire sound seize mechanism is encapsulated with the next command:

    arecord -d 1 -D plughw:0,7 -f S16_LE -r 16000 -c 1 -q /tmp/audio.wav

    I’m intentionally utilizing a plug-in system to allow computerized conversion in case I want to introduce any adjustments to the USB microphone configuration. AST is run on 16 kHz samples, so the recording and AudioMoth sampling are set to this worth.

    Take note of the generator within the code. It’s vital that the system repeatedly captures audio on the time intervals I specify. I aimed to retailer solely the latest audio pattern on the system and discard it after the classification. This strategy shall be particularly helpful later throughout larger-scale research in city areas, because it helps guarantee individuals’s privateness and aligns with GDPR compliance.

    import asyncio
    import re
    import subprocess
    from tempfile import TemporaryDirectory
    from typing import Any, AsyncGenerator
    
    import librosa
    import numpy as np
    
    
    class AudioDevice:
        def __init__(
            self,
            identify: str,
            channels: int,
            sampling_rate: int,
            format: str,
        ):
            self.identify = self._match_device(identify)
            self.channels = channels
            self.sampling_rate = sampling_rate
            self.format = format
    
        @staticmethod
        def _match_device(identify: str):
            traces = subprocess.check_output(['arecord', '-l'], textual content=True).splitlines()
            units = [
                f'plughw:{m.group(1)},{m.group(2)}'
                for line in lines
                if name.lower() in line.lower()
                if (m := re.search(r'card (d+):.*device (d+):', line))
            ]
    
            if len(units) == 0:
                elevate ValueError(f'No units discovered matching `{identify}`')
            if len(units) > 1:
                elevate ValueError(f'A number of units discovered matching `{identify}` -> {units}')
            return units[0]
    
        async def continuous_capture(
            self,
            sample_duration: int = 1,
            capture_delay: int = 0,
        ) -> AsyncGenerator[np.ndarray, Any]:
            with TemporaryDirectory() as temp_dir:
                temp_file = f'{temp_dir}/audio.wav'
                command = (
                    f'arecord '
                    f'-d {sample_duration} '
                    f'-D {self.identify} '
                    f'-f {self.format} '
                    f'-r {self.sampling_rate} '
                    f'-c {self.channels} '
                    f'-q '
                    f'{temp_file}'
                )
    
                whereas True:
                    subprocess.check_call(command, shell=True)
                    knowledge, sr = librosa.load(
                        temp_file,
                        sr=self.sampling_rate,
                    )
                    await asyncio.sleep(capture_delay)
                    yield knowledge

    Classification

    Now for probably the most thrilling half.

    Utilizing the Audio Spectrogram Transformer (AST) and the wonderful HuggingFace ecosystem, we will effectively analyse audio and classify detected segments into over 500 classes.
    Word that I’ve ready the system to help numerous pre-trained fashions. By default, I exploit MIT/ast-finetuned-audioset-10–10–0.4593, because it delivers one of the best outcomes and runs effectively on the Raspberry Pi 4. Nonetheless, onnx-community/ast-finetuned-audioset-10–10–0.4593-ONNX can be price exploring — particularly its quantised model, which requires much less reminiscence and serves the inference outcomes faster.

    You might discover that I’m not limiting the mannequin to a single classification label, and that’s intentional. As a substitute of assuming that just one sound supply is current at any given time, I apply a sigmoid operate to the mannequin’s logits to acquire impartial chances for every class. This permits the mannequin to specific confidence in a number of labels concurrently, which is essential for real-world soundscapes the place overlapping sources — like birds, wind, and distant visitors — usually happen collectively. Taking the high 5 outcomes ensures that the system captures the almost definitely sound occasions within the pattern with out forcing a winner-takes-all choice.

    from pathlib import Path
    from typing import Optionally available
    
    import numpy as np
    import pandas as pd
    import torch
    from optimum.onnxruntime import ORTModelForAudioClassification
    from transformers import AutoFeatureExtractor, ASTForAudioClassification
    
    
    class AudioClassifier:
        def __init__(self, pretrained_ast: str, pretrained_ast_file_name: Optionally available[str] = None):
            if pretrained_ast_file_name and Path(pretrained_ast_file_name).suffix == '.onnx':
                self.mannequin = ORTModelForAudioClassification.from_pretrained(
                    pretrained_ast,
                    subfolder='onnx',
                    file_name=pretrained_ast_file_name,
                )
                self.feature_extractor = AutoFeatureExtractor.from_pretrained(
                    pretrained_ast,
                    file_name=pretrained_ast_file_name,
                )
            else:
                self.mannequin = ASTForAudioClassification.from_pretrained(pretrained_ast)
                self.feature_extractor = AutoFeatureExtractor.from_pretrained(pretrained_ast)
    
            self.sampling_rate = self.feature_extractor.sampling_rate
    
        async def predict(
            self,
            audio: np.array,
            top_k: int = 5,
        ) -> pd.DataFrame:
            with torch.no_grad():
                inputs = self.feature_extractor(
                    audio,
                    sampling_rate=self.sampling_rate,
                    return_tensors='pt',
                )
                logits = self.mannequin(**inputs).logits[0]
                proba = torch.sigmoid(logits)
                top_k_indices = torch.argsort(proba)[-top_k:].flip(dims=(0,)).tolist()
    
                return pd.DataFrame(
                    {
                        'label': [self.model.config.id2label[i] for i in top_k_indices],
                        'rating': proba[top_k_indices],
                    }
                )

    To run the ONNX model of the mannequin, it’s essential add Optimum to your dependencies.

    Sound strain stage

    Together with the audio classification, I seize data on sound strain stage. This strategy not solely identifies what made the sound but in addition good points perception into how strongly every sound was current. In that method, the mannequin captures a richer, extra reasonable illustration of the acoustic scene and may ultimately be used to detect finer-grained noise air pollution data.

    import numpy as np
    from maad.spl import wav2dBSPL
    from maad.util import mean_dB
    
    
    async def calculate_sound_pressure_level(audio: np.ndarray, acquire=10 + 15, sensitivity=-18) -> np.ndarray:
        x = wav2dBSPL(audio, acquire=acquire, sensitivity=sensitivity, Vadc=1.25)
        return mean_dB(x, axis=0)

    The acquire (preamp + amp), sensitivity (dB/V), and Vadc (V) are set primarily for AudioMoth and confirmed experimentally. In case you are utilizing a unique system, you should determine these values by referring to the technical specification.

    Storage

    Knowledge from every sensor is synchronised with a PostgreSQL database each 30 seconds. The present city soundscape monitor prototype makes use of an Ethernet connection; due to this fact, I’m not restricted by way of community load. The system for extra distant areas will synchronise the information every hour utilizing a GSM connection.

    label           rating        system   sync_id                                sync_time
    Hum             0.43894055   yor      9531b89a-4b38-4a43-946b-43ae2f704961   2025-05-26 14:57:49.104271
    Mains hum       0.3894045    yor      9531b89a-4b38-4a43-946b-43ae2f704961   2025-05-26 14:57:49.104271
    Static          0.06389702   yor      9531b89a-4b38-4a43-946b-43ae2f704961   2025-05-26 14:57:49.104271
    Buzz            0.047603738  yor      9531b89a-4b38-4a43-946b-43ae2f704961   2025-05-26 14:57:49.104271
    White noise     0.03204195   yor      9531b89a-4b38-4a43-946b-43ae2f704961   2025-05-26 14:57:49.104271
    Bee, wasp, and so on. 0.40881288   yor      8477e05c-0b52-41b2-b5e9-727a01b9ec87   2025-05-26 14:58:40.641071
    Fly, housefly   0.38868183   yor      8477e05c-0b52-41b2-b5e9-727a01b9ec87   2025-05-26 14:58:40.641071
    Insect          0.35616025   yor      8477e05c-0b52-41b2-b5e9-727a01b9ec87   2025-05-26 14:58:40.641071
    Speech          0.23579548   yor      8477e05c-0b52-41b2-b5e9-727a01b9ec87   2025-05-26 14:58:40.641071
    Buzz            0.105577625  yor      8477e05c-0b52-41b2-b5e9-727a01b9ec87   2025-05-26 14:58:40.641071

    Outcomes

    A separate software, constructed utilizing Streamlit and Plotly, accesses this knowledge. At present, it shows details about the system’s location, temporal SPL (sound strain stage), recognized sound courses, and a variety of acoustic indices.

    Dashboard
    Streamit analytical dashboard (picture by creator)

    And now we’re good to go. The plan is to increase the sensor community and attain round 20 units scattered round a number of locations in my city. Extra details about a bigger space sensor deployment shall be obtainable quickly.

    Furthermore, I’m amassing knowledge from a deployed sensor and plan to share the information bundle, dashboard, and evaluation in an upcoming weblog submit. I’ll use an fascinating strategy that warrants a deeper dive into audio classification. The principle concept is to match completely different sound strain ranges to the detected audio courses. I hope to discover a higher method of describing noise air pollution. So keep tuned for a extra detailed breakdown quickly.

    Within the meantime, you may learn the preliminary paper on my soundscapes research (headphones are compulsory).


    This submit was proofread and edited utilizing Grammarly to enhance grammar and readability.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    How Unfiltered AI Video Tools Are Redefining Accessibility

    June 12, 2025

    Exploring the Proportional Odds Model for Ordinal Logistic Regression

    June 12, 2025

    Trying to Stay Sane in the Age of AI

    June 12, 2025

    Model Context Protocol (MCP) Tutorial: Build Your First MCP Server in 6 Steps

    June 11, 2025

    Mobile App Development with Python | Towards Data Science

    June 11, 2025

    Exploratory Data Analysis: Gamma Spectroscopy in Python

    June 11, 2025
    Leave A Reply Cancel Reply

    Editors Picks

    IBM Tackles New Approach to Quantum Error Correction

    June 12, 2025

    How Unfiltered AI Video Tools Are Redefining Accessibility

    June 12, 2025

    Royal Enfield Himalayan to feature 750cc engine

    June 12, 2025

    EIT Digital Venture Incubation Program 2025: Turn your digital tech idea into a real venture!

    June 12, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    The Best Air Fryer and More for Your Super Bowl Watch Party

    February 6, 2025

    German police identify TrickBot and Conti ransomware leader “Stern” as Vitaly Nikolaevich Kovalev, believed to be in Russia and shielded from extradition (Wired)

    May 30, 2025

    China Develops The World’s First Light-based Al Chip

    August 18, 2024
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

    Type above and press Enter to search. Press Esc to cancel.