|
From: Ulrich K. <ul...@ch...> - 2012-12-30 22:56:53
|
Peter Shute <ps...@nu...>: > I need to generate a spectrogram for some wav files, but sox only > allows a maximum spectrogram width of 5000 pixels. The horizontal > scale I need means that this will only be good for about 3 minutes, > but my files are much longer than that. > I've been generating spectrograms with commands like: > sox test.wav -r 16k -n rate remix 1 spectrogram -S 0:00 -d 3:00 -m > -l -x 5000 -y 642 -o spectrogram1.png > (I've cobbled those together from examples I've found. The intention > is to resample the 44.1kHz file to 16kHz because I only want the > spectrograms to show up to 8kHz, and I only want the left channel. > Are my commands correct?) Generally, yes, but it would be more efficient to - use "trim" to extract the relevant part (as you already suspected), as in "trim 0:00 3:00", - reverse the order of remix and rate (no need to resample the channels that are discarded anyway), and - unless you absolutely need a height of exactly 642 pixels, go to either 513 (= 2^9+1) or 1025 (= 2^10+1). So a faster version is: sox test.wav -n trim 0:00 3:00 remix 1 rate 16k spectrogram -m -l -x 5000 -y 1023 -o spectrogram1.png (The last point is the most important. In an example I ran, -y 642 took 110 seconds, while -y 1025 only took 9. And I don't mean 109, but 9.) > I'll join these images together to form one long one. > I.e. I have to manually create a command per 3 minute segment. Is > there a better way? ... Can I use the newfile and restart effects to > do it in one command without generating intermediate files? Not directly, because the spectrogram output will use the same file name each time, overwriting the previous output. (You could write to a named pipe, though, or something like that.) Probably the easiest way is to lift the width limit of 5000 pixels, as it appears to be arbitrary. I don't know if there is a real limit (imposed by PNG/libpng perhaps?), but I changed it to 20000 in the source code and that seems to have worked. How many pixels do you need? Ulrich |