Spectroscopic modelling of astrophysical mergers and kilonovae