# How to reproduce Spectrogram from SpectrogramArray?

I'm trying to reproduce the result of Spectrogram from SpectrogramArray, but having no luck, any help?

What I've got so far:

x = "some-audio.wav";
colorFunc = (Blend[{White, Orange, Red, Black}, #] &);

(* The spectrogram plotted by the Spectrogram function *)
Spectrogram[
Audio[x], 400, 160, HammingWindow, ColorFunction -> colorFunc,
Frame -> None]

(* Trying to reproduce it *)
spect = SpectrogramArray[Audio[x], 400, 160, HammingWindow];
half = spect[[All, 1 ;; Dimensions[spect][[2]]/2]];
data = Abs[half];
ArrayPlot[Reverse@Transpose[data], AspectRatio -> 1/3, Frame -> None,
ColorFunction -> colorFunc]


The result:

• Have you tried InverseSpectrogram[ data ] ? – LouisB Feb 5 at 6:13
• Might be a headache, there’s a lot of preprocessing and formatting logic inside Spectrogram – M.R. Feb 13 at 17:47
• @M.R. do you have access to the Spectrogram source code? – Incömplete Feb 14 at 2:42
• @Incömplete Just do this: <<GeneralUtilities; PrintDefinitions[Spectrogram] – M.R. Feb 14 at 3:07
• @M.R. The actual definition is not printed by it, it just prints the options of the function, and some other stuff. – Incömplete Feb 14 at 7:05

There are two ways, both showing the same result. I use the sound of an empty glass when hitting a side surface - see here

x=AudioCapture["C:\\Users\\...\\Desktop\\\\glass0.wav", MaxDuration -> 2]
colorFunc = (Blend[{White, Orange, Red, Black}, #] &);

(*The spectrogram plotted by the Spectrogram function*)
Spectrogram[Audio[x], 400, 160, HammingWindow,
ColorFunction -> colorFunc, FrameTicks -> None]

(*Trying to reproduce it*)
spect = SpectrogramArray[Audio[x], 400, 160, HammingWindow];
half = spect[[All, 1 ;; Dimensions[spect][[2]]/2]];
data = Abs[half];
ArrayPlot[Reverse@Transpose[data], AspectRatio -> 1/3,
ColorFunction -> colorFunc, FrameTicks -> None,
ColorFunctionScaling -> False]
(* Second way*)
ListDensityPlot[Transpose[Abs[spect]][[;; 200]], AspectRatio -> 1/3,
PlotRange -> All, ColorFunction -> colorFunc,
ColorFunctionScaling -> False, FrameTicks -> None]
`

• Unfortunately, the two graphs doesn't look the same. I also tried on my data, it doesn't look the same either – Incömplete Feb 17 at 8:11