Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

srushti_kansagara's avatar

Audio sample into a Spectrogram

is that possible to convert the Audio sample to Spectrogram through APIs in laravel ....is there any package which is good for that ? i want to know for apps which are finding the song by listening the music or sample audio of the song

0 likes
5 replies
Glukinho's avatar

I would use locally installed ffmpeg + PHP-FFMpeg package: https://github.com/PHP-FFMpeg/PHP-FFMpeg?tab=readme-ov-file#generate-a-waveform

Other approach would be to invoke ffmpeg manually:

<?php

class SpectrogramCreator
{
    const FFMPEG_BIN =  '/usr/local/bin/ffmpeg'; // adjust to your system

    public function create(string $file_in, string $file_out)
    {
        $p = new \Symfony\Component\Process\Process([
            self::FFMPEG_BIN,
            '-y',
            '-i',
            $file_in,
            '-lavfi',
            'showspectrumpic=s=800x400:mode=separate',
            $file_out,
        ]);

       $p->mustRun();
    }
}

Usage:

(new SpectrogramCreator)->create('/tmp/video.mp4', '/tmp/spectrogram.png');

// /tmp/spectrogram.png created
srushti_kansagara's avatar

@Glukinho as much as i can understand this thing create the audio fingerprint (image in png format) right then how it is comparing to other audios to fetch the matching song ?

Glukinho's avatar

@srushti_kansagara Sorry, it seems I misunterstood the term "spectrogram". I thought you are talking about generating waveforms (images with sound levels), but you are probably looking for something like Shazam...

srushti_kansagara's avatar

@Glukinho yahh like one client want an app which should be able to listen to music or part of the audio and should give the matching song list ... so i want to know that this kind of thing is possible in the laravel .. like i can build an API for this app in laravel

Please or to participate in this conversation.