At room temperature, PbTe and SnTe are efficient thermoelectrics with a cubic structure. At low temperature, SnTe undergoes a ferroelectric transition with a critical temperature strongly dependent on the hole concentration, while PbTe is an incipient ferroelectric. By using the stochastic self-consistent harmonic approximation, we investigate the anharmonic phonon spectra and the occurrence of a ferroelectric transition in both systems. We find that vibrational spectra strongly depends on the approximation used for the exchange-correlation kernel in density functional theory. If gradient corrections and the theoretical volume are employed, then the calculation of the free energy Hessian leads to phonon spectra in good agreement with experimental data for both systems. In PbTe, we reproduce the transverse optical mode phonon satellite detected in inelastic neutron scattering and the crossing between the transverse optical and the longitudinal acoustic modes along the ΓX direction. In the case of SnTe, we describe the occurrence of a ferroelectric transition from the high temperature Fm3m structure to the low temperature R3m one.