Draw a waveform from wav file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Adam_S

Hi,
does anyone know how to draw a waveform like the one in the inspector when double clicking an audio file in the file system dock?

There doesn’t seem to be any property or function to get that information… maybe you should do a feature request.

Zylann | 2019-08-10 14:54

:bust_in_silhouette: Reply From: uriel

hi adam_s, did you found the way to get the waveform ?

Hey Uriel, unfortunately not.

What I do at the moment, is play the sample, get the bus peak volume and append it to an array.
Then I use this array with the draw_line() function to draw something like a waveform.

However, the result is not as accurate as I would like.

Adam_S | 2019-09-27 18:59

:bust_in_silhouette: Reply From: Matt_UV

Hi!
Unfortunately, I don’t have the answer to your question :frowning:

However, here are some clues. I need a waveform too in my project, and I’m using ffmpeg for that, with OS.execute()

OS.execute("./ffmpeg/ffmpeg.exe", ["-i", audio.ogg, "-filter_complex", "compand=gain=-6,showwavespic=s=1280x240:colors=blue,drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:replace=1:color=blue-frames:v", "1", waveform.png, "-y"], true)
It might seem obscure, but here is the doc for that
It generates a png image that I scale afterward.Not the best solution, but it fits my needs.

If you want to know how they did it in Godot, here are useful links in the source code:

I’m not really good in audio technology, nor C++, so I have difficulties analysing that code, but you might find it intersting :wink:

:bust_in_silhouette: Reply From: vfpe

Hey!
I had the same problem, so I created a custom module based on the engine preview code. You can grab the source from GitHub repo https://github.com/v-pukman-gd/godot-audio-waveform-module

I hope it helps you!