Gamma-ray spectroscopy in astrophysics