I don't buy the brainwave explanation. Aside from it being nearly impossible, it doesn't fit in with the rest of the show.
It would have to scan the brain of a an unknown race, understand how it works, assume it uses "brainwaves", know which of those waves controls thought and speech, and figure out what the waves mean. And it's not just translating broad thoughts, it's getting every nuance and word. The translation is often very eloquent. It's just absurd.
And most importantly, it requires mind-reading at a very deep level. Nothing else in any of the series suggests the Federation can read minds. They would have used that for many other things (e.g. is a suspect lying?, is this guy on the viewscreen bluffing or is he going to fire, is my crewmate a clone taken over by an alien). They wouldn't need Troi to guess using fuzzy feelings (they would also be able to hear telepaths telepathing).
The universal translator does not read brainwaves.
While the brainwave explanation was mentioned in one TOS episode, everything else in every other series has clearly shown it's a language learning process. ENT covered this a lot and showed the fallibility of earlier technology.
So How Could It Work?
There are two parts to this. First, is the theoretical nature of the translator and what it would do if you were using one. And second, what we, as viewers, hear and see (subtitles) for storytelling convenience.
Single Race Present - Speaking Own Language
When a race is by itself, with no aliens present, a translator could determine that and not translate. As viewers we may see subtitles or we may hear English. But we can assume no translation is happening.
Multiple Races Present - Speaking Own Language
When multiple races are present, each speaking their own language, the translator has to hear what you're saying, translate it into every language of those present, and alter the sound wave in the direction of each person listening. We saw this on VOY when they found Amelia Earhart.
Sound research today can already completely block out sounds with alternate waves and project sound in very precise directions. So it isn't hard to imagine the mechanics of this working in a few hundred years.
A translator can accurately determine those present and what language they speak based on their race. We've seen the translator mess this up before when a smaller group of people of a particular race speak a different language. So it can determine you're human, and decide to use English, but can't determine if you're a human that doesn't speak English unless it hears you speaking first.
It would be easy enough to determine (or at least predict very accurately) who you were speaking to in a room based on vocal and body cues. If you're Vulcan near another Vulcan and speaking directly to them, it could choose not translate. We see this sometimes when a Klingon captain will turn to one of his crew and shout a command and we, as viewers, hear it in Klingon (sometime with subtitles), even with people from other races around. We can assume the translator didn't translate this.
Any Race - Speaking Another Language
With all that in mind, it's easy to see how Picard can speak French, or Hoshi can speak Denobulan. The translator knows your race and what language you speak. When it hears you speaking a different language, it would know that was deliberate and wouldn't translate it.
Personal Translator
Also, it seems at least some translators are embedded in your body (Little Green Men, DS9). A translator could learn your preferences and proficiencies over time (and you could set them as well). If you know a lot of Klingon, for example, it could stop translating things you hear all the time, like greetings.
Inconsistencies
Where this doesn't work is when two people are speaking another language when someone from another race is around and one of them says something like, "Speak <guest language> around the guest." There is no reason why the translator wouldn't translate if the guest was part of the conversation, and no expectation that any other aliens would speak or even know <guest language>. But brainwaves don't solve this either.
I can't think of any examples other than Troi to her mom, but they're speaking telepathically. So that doesn't really count (but it does show that the translator isn't reading brainwaves).