from spectrograms, how can you tell which peak is really a formant. Like why is the pink arrow the first formant. And in the spectrogram below, which has fewer samples, what makes a value the peak value?
The spectra on the left are two line spectra of two different periodic functions, the top with fundamental frequency of 100 Hz and the bottom has $f_0$ of 200 Hz. While they are not perfectly flat spectral lines, they are broadbanded with no apparent resonance.
It's a gross approximation, but I believe these two broadbanded periodic signals are meant to represent what comes out of one's voicebox in the throat. It's the same broadbanded, except the $f_0$ depends on the pitch that one intends to sing (or speak) at. If it were A above middle C (normally called "A4" or MIDI note 69) then $f_0$=440 Hz.
Now that broadbanded (same spectral envelope, but different $f_0$) driving signal on the left gets passed through an acoustic filter in the middle which is not dependent on $f_0$ but is dependent on the shape of the mouth, position of tongue, amount of nasal coupling, all which is dependent on the vowel one is singing. In the frequency domain, the spectrum of the driving signal is multiplied by the frequency response to become the spectrum of the output.
The cause of the formant frequencies is due to the acoustic filtering of the vocal cavity that is one's head, mouth, lips, and nasel coupling.
A few of us have developed a pitch shifting algorithm that shifts pitch, but does not shift the formant frequencies. I did this a quarter century ago and wrote a short paper about it. You can sorta think of your voicebox as emitting a quasiperiodic string of impulses (or approximations to impulses) from the glottal closure and opening (with fundamental frequency $f_0$) and those impulses being convolved with the impulse response of the formant filter. If the pitch shifting does not stretch or scrunch that impulse response, the formants remain unchanged.
But simple speeding up or slowing down the recording does scrunch or stretch the impulse response, which causes the formants to move. That causes someone to sound like Alvin the Chipmunk (pitching up) or Darth Vader or Satan from hell (pitching down).