withmorten / spek-alternative

Acoustic spectrum analyser
Other
314 stars 18 forks source link

Command line #1

Closed sstativa closed 6 years ago

sstativa commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

withmorten commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Great news. Thanks.

withmorten commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

Thanks a lot.

withmorten commented 6 years ago

Good to know, glad it works!

KoalaBear84 commented 5 years ago

Checked it on Windows. Also works great, thanks!

Mouseboy007 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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