Heralded single-photon generation using imperfect single-photon sources and a two-photon-absorbing medium