'The' has two pronunciations in both UK and US English: weak /ðə/ before consonant sounds and strong /ðiː/ before vowel sounds. It is normally unstressed; /ðiː/ also appears when the word is emphasized.
Mouth cues
Place the tip of your tongue lightly between or just behind your teeth, then voice a soft th. The air flows out gently; your tongue does not tap or stop the sound.
For /ðə/ before consonant sounds, as in the book, let the mouth rest half open and keep the vowel short and relaxed, like a quick uh.
For /ðiː/ before vowel sounds, as in the apple, spread into an ee shape and stretch it slightly longer. Same tongue position both times; only the vowel changes.
Test the switch with one pair, said slowly: the car, then the orange. The first keeps the short vowel, the second the longer ee vowel.
In a speakable phrase: Turn at the corner, then cross at the entrance. Hear the short vowel before corner, the long one before entrance.
headingLabelingNote
Say it in a phrase
The university is old. Even though university starts with the letter u, it begins with the consonant sound /juː/, so the takes its short form: /ðə/.
The hour has come. The h in hour is silent, so the word begins with a vowel sound, and the lengthens to /ðiː/.
Trust your ear for the next sound, not the spelling. The house uses /ðə/ because the h is heard here, while the hour uses /ðiː/ because it is not.
Say this pair slowly: the one o'clock train and the eight o'clock train. The first keeps the short vowel before the consonant sound /w/ in one; the second lengthens to /ðiː/ before the true vowel sound in eight.