Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line #1

Closed
sstativa opened this issue Mar 25, 2018 · 16 comments
Closed

Command line #1

sstativa opened this issue Mar 25, 2018 · 16 comments

Comments

@sstativa
Copy link

Hi,

This is not an issue, just a question. Is it possible to add a command line support?

The main functionality that I'm missing is to be able to save the result in PNG directly through the command line.

@withmorten
Copy link
Owner

I've been thinking about that for a while as well, I'll look into it.

The way spek parses the commandline is a bit weird (and somewhat broken under Windows, doesn't print version at all), but at least you can already open files directly.

I'm not sure yet how related the actual window and the spectrogram are, but I think it should be possible to not show the window and instead directly save it to png. I'm assuming you'd also want commandline parameters for width and height, and if none given use default (or the hidden preferences values)?

@sstativa
Copy link
Author

Having optional width and height parameters would be awesome, but for me, even fixed 640x480 will be enough.

@withmorten
Copy link
Owner

withmorten commented Apr 3, 2018

I was able to implement it somewhat hackily. Since Spek is no true commandline program, in fact, it won't even start in a true terminal with no graphical output whatsoever, and the whole program is Window-based, I had to implement it the following way: Spek still opens a Window (I tried hiding the Window, but it won't actually parse the file and write the png then), but after it finishes analyzing the file it writes the output png and then closes instantly. The focus also remains on the CMD (at least under Windows, will have to test under macOS and some linux).

Implementing it without it opening a Window whatsoever would require rewriting basically the entire way the spectrograph gets drawn from what I can tell.

Does that sound at least somewhat allright? It means you can't start analyzing for example a whole folder and do something else on the same computer in the meantime, but it would still be significantly faster than opening and saving each file by hand.

@sstativa
Copy link
Author

sstativa commented Apr 4, 2018

The solution you propose will be great. I have no problem with "flickering" window at all.

In fact, I was trying to implement the same logic you described (open-save-close) using AppleScript, but I failed.

@withmorten
Copy link
Owner

Glad that works for you. You're on macOS then? Allright, I'll make a build for that once I'm done.

I still need to finish up checking at least somewhat if the output file will be writable (and actually test the commandline saving on Mac, so far I only tested on debian and Windows) and add height and width commandline parameters, so you can probably expect it in the next few days.

@sstativa
Copy link
Author

sstativa commented Apr 5, 2018

Great news. Thanks.

@withmorten
Copy link
Owner

Allright, finally ironed out a weird issue on Mac where Spek tried to open the last commandline argument as a file, meaning it analyzed the png as wav if no height and width parameters were given and then saved that completely useless spec to file ... should be fixed now, though.

I'll just sleep another night over the PNG saving changes and if everything seems allright I'll commit it and upload a build tomorrow.

@withmorten
Copy link
Owner

withmorten commented Apr 6, 2018

Here you go: https://morten.with.de/spek-builds/spek-alternative-cf02f3c4c4bf794a479dcb8939546c3d06a83786.dmg

Let me know if there are any problems, you can check the usage with spek -h, but it should simply be spek test.wav test.wav.png 640 480. Or just leave the 640 480 and spek will use the default values (which are 640x480).

For Windows users happening to stumble upon this:

https://morten.with.de/spek-builds/spek-alternative-cf02f3c4c4bf794a479dcb8939546c3d06a83786.msi
https://morten.with.de/spek-builds/spek-alternative-cf02f3c4c4bf794a479dcb8939546c3d06a83786.zip

VERY IMPORTANT for Windows users: Call the programm with start /wait Spek.exe in a for loop. Only programs specifically set to be for the console subsystem "stick" in CMD and otherwise Spek will open each file in the for loop at the same time.

@sstativa
Copy link
Author

sstativa commented Apr 8, 2018

I've just tested it on my Mac. It works great.

Thanks a lot.

@withmorten
Copy link
Owner

Good to know, glad it works!

@KoalaBear84
Copy link

Checked it on Windows. Also works great, thanks!

@Mouseboy007
Copy link

If anyone plans to output graphs via Powershell this might save you a few mins typing it up yourself:
https://github.com/Mouseboy007/PowershellStuff/blob/master/Music/GenerateSpekAcousticSpectrumGraphs.ps1

@GitDwellers01
Copy link

VERY IMPORTANT for Windows users: Call the programm with start /wait Spek.exe in a for loop. Only programs specifically set to be for the console subsystem "stick" in CMD and otherwise Spek will open each file in the for loop at the same time.

Can you provide a ready-made example for processing multiple files?

@KoalaBear84
Copy link

I use this to do it for all flac files for example.

for %%f in (*.flac) do (
    echo %%~nf
    "Spek.exe" "%%f" "%%~nf.png" 640 480
)

@Mouseboy007
Copy link

Mouseboy007 commented Jul 26, 2020

VERY IMPORTANT for Windows users: Call the programm with start /wait Spek.exe in a for loop. Only programs specifically set to be for the console subsystem "stick" in CMD and otherwise Spek will open each file in the for loop at the same time.

Can you provide a ready-made example for processing multiple files?

Hi,

My earlier post with the Powershell Script will (now!) do what you ask.
I realised I was missing an 'Out-Null' statement so it wasn't pausing, and instead was opening multiple graphs simultaneously. The script will now wait until each graph has been generated before opening the next item to process. It's a little slower, but will stop your computer from being flooded with spek graphs - hope that helps :)

@GitDwellers01
Copy link

GitDwellers01 commented Aug 4, 2020

I use this to do it for all flac files for example.

KoalaBear84 thanks for the example.
Mouseboy007 thanks for the command line support.

Several ready-made .bat files for automatic processing of tracks in Spek-alternative 0.8.2.3 [Command line version]

I added a little code to make it more convenient to use. Place tracks in the "Music" folder.

@echo off
rem github.com/withmorten/spek-alternative/issues/1
rem Created by KoalaBear84
rem spek /h - Help
rem Music File types to scan "mp3|m4a|flac|wav|ogg|wv"
for %%f in ("Music\*.flac" "Music\*.mp3") do (
	echo %%~nf
	"Spek.exe" "%%f" "%%f.png" 640 480
)
pause
exit

Extended .bat file, with input of the path to the music folder and output of the log. Convenient when processing a large number of tracks.

@echo off
rem github.com/withmorten/spek-alternative/issues/1
rem Created by XAH
rem spek /h - Help
rem Music File types to scan "mp3|m4a|flac|wav|ogg|wv"
echo [Enter the full path to the folder with music]
echo [Example] X:\Music\Tracks
set /p musicpath=" "
echo.
set DATE_TIME=%DATE:~0,2%.%DATE:~3,2%.%DATE:~6,4% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2%
echo [%DATE_TIME%] - Starting
echo [%DATE_TIME%][%musicpath%] - ### Starting ### >> "%musicpath%"\Log.txt
echo.
for %%f in ("%musicpath%"\*.flac "%musicpath%"\*.mp3) do (
	echo %%~nf & echo %%~nf >> "%musicpath%"\Log.txt
	start /wait Spek.exe "%%f" "%%f.png"
)
echo.
set DATE_TIME=%DATE:~0,2%.%DATE:~3,2%.%DATE:~6,4% %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2%
echo [%DATE_TIME%] - Ending
echo [%DATE_TIME%] - ### Ending ### >> "%musicpath%"\Log.txt
echo. >> "%musicpath%"\Log.txt
pause
exit

.bat files should be next to Spek.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants