Gravitational wave cosmology and astrophysics with large spectroscopic galaxy surveys