Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: [Help Needed] Script for making Spectograms for multiple audio files with SoX (Read 6607 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[Help Needed] Script for making Spectograms for multiple audio files with SoX

Hi

Need help with making a script for making spectograms for multiple audio files using SoX.

I've found batch script info for *nix out there but that doesn't really say a thing to me. Im a Windows dude.

What im after is that i want to generate spectograms in PNG for single and/or multiple lossless audio files. For example FLAC.
I want to see the the file name in the spectogram and the image size should be around 800 x 800. I know that this is possible but i just dont know how to make a BAT file(s) for it.

Is there any kind souls here that can help me out with this or?


SoX v14.4.2 (Win x86/x64)
Built on January 20, 2023, GCC 12.2.0
https://www.mediafire.com/file/6dpd2nb3p22d51x/

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #1
Use latest ffmpeg to generate spectrograms, faster and better with better support.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #2
@mycroft
Care to tell me how to do that with ffmpeg and make into a BAT file?

 

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #3
When using  ffmpeg, height of image must be power of 2 to show full spectrum. Not very convenient.

SoX doesn't support unicode. It can take audio from pipe from ffmpeg (and ffmpeg then can take picture from pipe from SoX to write unicode text on it), but to generate spectrogram from pipe, it is needed to set duration in SoX command.

Because, i am not good in writing complicated batch  scripts, i personally use foobar2000 with foo_run and ffmpeg together with SoX to avoid aforementioned problems.
Command for foo_run:
Code: [Select]
cmd.exe /d /c ffmpeg -v 16 -i "%path%" -f sox -|sox -p -n spectrogram -d %length_samples%s -x 1600 -Y 1200 -t " " -o -|ffmpeg -v 16 -y -i - -vf "drawtext=''text=$replace(%filename_ext%,'',$char(8217)):font=ArialUnicodeMS:fontcolor=white:fontsize=$ifgreater($len(%filename_ext%),170,16,20):x=5:y=10''" "%path%.png"
I use font ArialUnicodeMS because it has very many symbols of unicode in it. In case, some symbols are not present in used font, they will be replaced by squares.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #4
Save as .CMD then drag & drop audio files into the .CMD script.
Code: [Select]
@echo off
pushd %~dp0
for %%1 in (%*) do sox -V %%1 -n spectrogram -z 180 -w dolph -h -o "%~dp1%%~n1.png" -c "%%~nx1"
pause
-z is the dB range
-w dolph is window type
-c is comment (file name)
-h means high contrast palette

As mentioned, unicode path or some symbols in path may cause issue.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #5
@Bogozo Thnx

@bennetng Thnx a lot. That's exactly what im after.


Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #7
Quote
New compile due to updated external dependencies.
Can you please tell, what exactly was updated?

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #8
External dependencies of SoX is the following

opencore-amr
twolame
lame
flac
sndfile
libopus
libvorbis

If i recall correctly so when i ran my media-autobuild_suite setup that time so had sndfile & opus been updated.

sndfile - https://github.com/libsndfile/libsndfile
opus - https://github.com/xiph/opus

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #9
Was pretty sure that SoX had support for Monkey's Audio (APE) but the script/sox didn't like it.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #10
SoX doesn't support Monkey's Audio.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #11
It would be great if DSD is included as well. I've got some sox.exe files with DSD support but they don't support spectrogram, and I don't know how to compile everything into a single executable.
https://github.com/mansr/sox

What I can do for now is rename the DSD capable executable to dsd.exe, and pipe it to another sox.exe, like this:
Code: [Select]
@echo off
pushd %~dp0
set spec=-n spectrogram -Z-0 -z155 -w dolph -h -o "%~dp1%%~n1.png" -c "%%~nx1"
for %%1 in (%*) do (
if exist "%~dp1%%~n1.d?f" (
dsd -S %%1 -p rate -v 88200 | sox -p %spec%
) else (
sox -S %%1 %spec%
)
)
pause


Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #13
SoX doesn't support Monkey's Audio.

A friend use an discontinued tool called 'auCDtect Task Manager' and that one outputs spectograms generated by SoX. That was why i was pretty sure that SoX had support for APE.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #14
There are some builds around, but I can't find where anymore 😕
The most recent one I have is named SoX-14.4.2-Unicode.2017-04-14.r2.zip
Here it is - https://sourceforge.net/projects/muldersoft/files/SoX%20(Unicode)/. But it is compiled without support for spectrogram generation. And without decoders.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #15
auCDtect Task Manager
It simply uses mac.exe to decode to temporary wav file. BTW, ffmpeg can decode APE too.




Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #19
NetRanger's SoX binaries have been added to the "Others" page at rarewares. :)

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #20
For foobar2000 users, I have a component/script which uses ffmpeg to generate images and uses them as a background for a seekbar. The images are generated the first time a track is played and then stored indefinitely inside your fb2k profile folder. You can check the cache size/clear it from the right click menu.

There are 2 variants, One just stretches the image to fill the panel like this...



The other displays an album art thumbnail/artist/title and buttons as well..



Details here...

https://jscript-panel.github.io/gallery/spectrogram-seekbar/

General component download/setup instructions...

https://jscript-panel.github.io/docs/





Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #22
SoX v14.4.2
Built on March 21, 2023, GCC 12.2.0

New compile due to external depencencies
- sndfile
Thanks for the build but is libsndfile built-in ? If not, do you know where to find a 64-bit libsndfile ?

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #23
It should be in there. ;)
SoX binaries works just fine.

Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX

Reply #24
Perfect, thanks  :)👍