1 /// speech plot module on GGplotD 2 module dspeech.plot; 3 4 import std.array : array; 5 import std.algorithm : map; 6 7 import ggplotd.aes : aes; 8 import ggplotd.axes : xaxisLabel, yaxisLabel; 9 import ggplotd.ggplotd : GGPlotD, putIn; 10 import ggplotd.geom : geomPoint, geomRectangle; 11 import ggplotd.colour : colourGradient; 12 import ggplotd.colourspace : XYZ; 13 14 static immutable docDir = "generated-docs/"; 15 16 /// retrieved from http://www.voxforge.org/home/downloads/speech/english/1snoke-20120412-hge 17 /// prompt: He could feel a new stir in the land. 18 // static immutable docWav = docDir ~ "a0409.wav"; 19 static immutable docWav = docDir ~ "english.wav"; 20 21 auto geomPointRect(AES)(AES aesRange) 22 { 23 import ggplotd.aes : aes, Pixel, DefaultValues, merge; 24 import ggplotd.range : mergeRange; 25 26 return DefaultValues.mergeRange(aesRange) 27 .map!((a) => a.merge(aes!("sizeStore", "width", "height", "fill") 28 (a.size, a.width, a.height, a.alpha))).geomRectangle; 29 } 30 31 auto plotMatrix(T)(T array2d) 32 { 33 import std.algorithm : cartesianProduct; 34 import std.range : iota; 35 auto xstep = 1; 36 auto ystep = 1; 37 auto xlen = array2d[0].length; 38 auto ylen = array2d.length; 39 auto xys = cartesianProduct(xlen.iota, ylen.iota); 40 auto gg = xys.map!(xy => aes!("x", "y", "colour", "size", "width", 41 "height")(xy[0], xy[1], array2d[$-1-xy[1]][xy[0]], 1.0, xstep, ystep)) 42 .array.geomPointRect.putIn(GGPlotD()); 43 gg = colourGradient!XYZ("mediumblue-limegreen-orangered").putIn(gg); 44 // gg = "time".xaxisLabel.putIn(gg); 45 // gg = "freq".yaxisLabel.putIn(gg); 46 return gg; 47 } 48 49 auto plotVector(T)(T array) 50 { 51 import std.range : enumerate; 52 import ggplotd.geom : geomLine; 53 54 auto gg = GGPlotD(); 55 gg = enumerate(array).map!(a => aes!("x", "y", "colour", "size")(a[0], a[1], 0, 0.1)) 56 .array.geomLine.putIn(gg); 57 // gg = "time".xaxisLabel.putIn(gg); 58 // gg = "gain".yaxisLabel.putIn(gg); 59 return gg; 60 }