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/
Use latest ffmpeg to generate spectrograms, faster and better with better support.
@mycroft Care to tell me how to do that with ffmpeg and make into a BAT file?
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:
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.
Save as .CMD then drag & drop audio files into the .CMD script.
@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.
@Bogozo Thnx
@bennetng Thnx a lot. That's exactly what im after.
Here is SoX & Script in one folder with info if anyone else wanna use it
SoX Spectogram
https://www.mediafire.com/file/u9uhy0nbotrp8hx
New compile due to updated external dependencies.
Can you please tell, what exactly was updated?
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
Was pretty sure that SoX had support for Monkey's Audio (APE) but the script/sox didn't like it.
SoX doesn't support Monkey's Audio.
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:
@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
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
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.
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.
auCDtect Task Manager
It simply uses mac.exe to decode to temporary wav file. BTW, ffmpeg can decode APE too.
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.
Updated the 'SoX Spectogram' folder with a newly compiled SoX binary
https://www.mediafire.com/file/u9uhy0nbotrp8hx/
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/
NetRanger's SoX binaries have been added to the "Others" page at rarewares. :)
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/
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
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 ?
It should be in there. ;)
SoX binaries works just fine.
Perfect, thanks :)👍
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/
The 'SoX Spectogram' package in Post #6 have been updated with the latest compile of SoX.
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
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.
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 )
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/
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