A scheme is presented to find single-particle spectroscopic factors (SF) of magic and semimagic nuclei within the self-consistent theory of finite Fermi systems (TFFS). In addition to the energy dependence of the mass operator Σ induced by the surface-phonon coupling effects which are commonly considered in this problem, the in-volume energy dependence of the operator Σ inherent in the self-consistent TFFS is also taken into account. This dependence arises due to the effect of high-lying particle-hole excitations and persists in nuclear matter. The self-consistent basis of the energy density functional method by Fayans et al. is used. Both the surface and in-volume contributions to the SFs turned out to be of comparable magnitude. The results for magic 40,48Ca and 208Pb nuclei and semimagic lead isotopes are presented.