Gaia Data Release 2. Processing the spectroscopic data