Ab Initio Calculation of Excitonic Effects in the Optical Spectra of Semiconductors