HydrogenAudio

Hydrogenaudio Forum => General Audio => Topic started by: NetRanger on 2023-01-29 18:28:21

Title: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 18:28:21
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/
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: mycroft on 2023-01-29 19:15:29
Use latest ffmpeg to generate spectrograms, faster and better with better support.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 19:19:09
@mycroft
Care to tell me how to do that with ffmpeg and make into a BAT file?
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-01-29 19:22:28
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.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: bennetng on 2023-01-29 19:41:40
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.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 20:06:19
@Bogozo Thnx

@bennetng Thnx a lot. That's exactly what im after.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 20:15:54
Here is SoX & Script in one folder with info if anyone else wanna use it

SoX Spectogram
https://www.mediafire.com/file/u9uhy0nbotrp8hx
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-01-29 20:28:39
Quote
New compile due to updated external dependencies.
Can you please tell, what exactly was updated?
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 20:33:37
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 (https://github.com/m-ab-s/media-autobuild_suite) setup that time so had sndfile & opus been updated.

sndfile - https://github.com/libsndfile/libsndfile
opus - https://github.com/xiph/opus
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-29 22:17:08
Was pretty sure that SoX had support for Monkey's Audio (APE) but the script/sox didn't like it.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-01-29 22:39:04
SoX doesn't support Monkey's Audio.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: bennetng on 2023-01-30 05:29:15
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
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Brazil2 on 2023-01-30 11:30:22
SoX doesn't support unicode.
There is a patch for Unicode support:
https://sourceforge.net/p/sox/patches/105/

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
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-30 13:29:10
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.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-01-30 14:37:23
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.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-01-30 14:45:50
auCDtect Task Manager
It simply uses mac.exe to decode to temporary wav file. BTW, ffmpeg can decode APE too.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-01-30 15:37:45
auCDtect Task Manager
It simply uses mac.exe to decode to temporary wav file. BTW, ffmpeg can decode APE too.

Exactly :)

Gonna take a look on your foo_run/ffmpeg/sox solution tonight or so.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-02-08 18:03:01
Updated the 'SoX Spectogram' folder with a newly compiled SoX binary
https://www.mediafire.com/file/u9uhy0nbotrp8hx/
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-02-14 17:41:56
Updated 'SoX Spectogram' folder with SoX binary that's compiled from the Official Repo
https://www.mediafire.com/file/u9uhy0nbotrp8hx/SoX_Spectogram.7z/file


For those who wants the SoX binaries (x86/x64)
https://www.mediafire.com/file/8ngwny2m9eyx13n/
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: john33 on 2023-02-14 18:20:18
NetRanger's SoX binaries have been added to the "Others" page at rarewares. :)
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: marc2k3 on 2023-02-15 12:37:35
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...

(https://jscript-panel.github.io/images/spectrogram-seekbar.png)

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

(https://i.imgur.com/qyyjA8y.png)

Details here...

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

General component download/setup instructions...

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



Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-03-22 10:15:55
SoX v14.4.2
Built on March 21, 2023, GCC 12.2.0

http://sox.sourceforge.net

Built from source repo.

New compile due to external depencencies
- sndfile


DL :
https://www.mediafire.com/file/tp5wtj0ub8u44fo
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Brazil2 on 2023-03-22 15:32:56
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 ?
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-03-22 17:39:17
It should be in there. ;)
SoX binaries works just fine.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Brazil2 on 2023-03-26 23:57:38
Perfect, thanks  :)👍
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-03-27 21:36:06
SoX v14.4.2
Built on March 21, 2023, GCC 12.2.0

http://sox.sourceforge.net

Built from source repo.

New compile due to external dependencies
- sndfile

DL :
https://www.mediafire.com/file/y6qb4fxfhskd3tm/
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-05-08 16:37:19
The 'SoX Spectogram' package in Post #6 have been updated with the latest compile of SoX.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-05-15 17:35:42
The 'SoX Spectogram' package in Post #6 have been updated with the latest compile of SoX.

SoX v14.4.2
Built on May 10, 2023, GCC 13.1.0
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: Bogozo on 2023-05-29 22:08:14
When using  ffmpeg, height of image must be power of 2 to show full spectrum.
Oops, i'm wrong. In modern version of ffmpeg this limitation doesn't exist anymore.
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: marc2k3 on 2023-05-30 02:00:32
Another random ffmpeg comment: showspectrumpic used to choke on tracks longer than 55m in length but since v6 was released, this limitation no longer applies. But I've only gone as far as testing 3hr (the longest DJ mix I have  :P )
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2023-08-07 11:29:21
SoX Binary v14.4.2
Built on August 05, 2023, GCC 13.1.0

http://sox.sourceforge.net

Built from source repo.

New compile due to external depencencies
- sndfile


DL :
https://www.mediafire.com/file/2tzvrob294neu5n/

---------------------

Updated 'SoX Spectogram' folder with the SoX binary from above
https://www.mediafire.com/file/u9uhy0nbotrp8hx/
Title: Re: [Help Needed] Script for making Spectograms for multiple audio files with SoX
Post by: NetRanger on 2024-02-18 20:27:20
SoX Binary v14.4.2
Built on February 18, 2024, GCC 13.2.0

http://sox.sourceforge.net

Built from source repo.

New compile due to external depencencies
-libopus


DL :
https://www.mediafire.com/file/3d0ems9i5k9x3f0

-------------------

Updated 'SoX Spectogram' folder with the SoX binary from above
https://www.mediafire.com/file/u9uhy0nbotrp8hx/SoX+Spectogram.7z/file