Isn't that added in post production? I always thought background extras just move their mouths not saying anything just like there's no music during dance scenes.
Well, of course the practice was used on the stage for millennia before film was invented, and still is. Of course most dialogue and sound effects you hear in movies and TV are added in post-production, but either way, the method of creating background-crowd sounds is the same.
And yes, there is music played back on the set during singing or dancing scenes, so that the performers have something to sync to. It's just that it gets dubbed over with a studio-recorded track in post-production for better audio quality. I have an old bootleg album of discarded Star Trek audio tracks from the third season (which I bought decades ago before I understood what bootlegs were), including some on-set audio of the song scenes from "The Way to Eden." The songs have a doubled-over quality, because the actors on set are actually singing along with the on-set playback of the songs recorded earlier in the studio -- because just silently lip-syncing wouldn't look quite the same as actually vocalizing and putting breath into it. But later on, in post-production, the clean studio tracks of the songs would've been dubbed over the set audio, giving us what we hear in the final episode.