Hi Mathew,
Yes, as Mister Micawber says, native English-speakers instinctively know which pronunciation of 'the' to use before a noun (or an adjective + noun), but I can see that it may be a problem for some people learning the language.
As you have yourself noted, we generally use the '
thee' version before a vowel (as in '
the apple'), and the "
theh' version before a consonant (as in '
the pen'), and the reason native English-speakers know which version to use, is because they read (or think of) the two words together, not separately!
From your name, I would guess that your mother-tongue is probably Mandarin Chinese (Ni shi zhong guo ren ma?), and if so, then you'll know that there's sometimes a similar situation in Chinese with tones (e.g. 'bu' meaning 'not' is normally pronounced as a fourth tone, but changes to a second tone when followed by another word that is pronounced with a fourth tone), and the only way you know which tone to use is by thinking of the two words together, not as individual characters.
By the way, there is an exception to the general rule of pronouncing 'the' as '
theh' before a consonant, but it's a special case, as the 'the' is being used less as a definite article, and more like an adjective. For example:
"Beijing is
the (pronounced as '
thee') place to be this August!" (because of the Olympic Games!).