how could I convert an audio file such as a aiff into a svg using gnuplot? I used sox (sound exchange) to convert an .aiff into a .dat, which I can load now in gnuplot.
I did something similar to:
set terminal svg
set output "test.svg"
plot "test.dat"
I get a svg file, but only with dots / or a lot of x.
How could I connect the dots?
To draw lines between the points, use
Or to keep the point markers as well as the lines, use
So your example becomes
Further tips:
Don’t consider every sample:
With large files you may also find it useful to plot only every nth sample with “every n”. This will make the plot much faster to generate and will also yield a smaller (but less detailed) svg file.
e.g.
Ignore .dat file header:
If your sox-produced .dat file has some lines of introductory metadata, such as
you can add the following to have gnuplot consider those lines comments and ignore them.
This will save you having to pre-process your .dat file in order to remove those lines before gnuplot chokes on them.
Plot both left and right channels of stereo audio:
If you’re working with a stereo file, you probably want to see both channels.
We can use “multiplot” to lay out the following two plots (of left then right channel) one above the other on a shared x-axis, as many sound-editing programs do.
The 1:2 and 1:3 instruct gnuplot which columns of the dat file to use as x and y sources. I’m assuming your stereo .dat file produced by sox looks as mine does, with columns for
– 1: time since beginning of first sample
– 2: normalized sample value of left channel
– 3: normalized sample value of right channel
example snippet:
Putting it together:
Here’s a script which puts all of the above together. If you don’t have a stereo data file to try this with, you’ll want to remove the plot of 1:3 and the multiplot setting.
Prettification
Finally, I’ve tweaked the script for presentation (borrowing heavily from the excellent “gnuplot in action” book by Philipp K. Janert):
Here’s an example output (albeit png):

How to make a .dat file
For anyone following along at home, you can use sox to generate a .dat file from an audio file with the following command:
Big file warning: Converting even just 10 seconds of stereo audio at 40kHz will produce a 25Mb output file.