The two tenses in your examples are called:
- Present perfect (yo he hablado).
- Pluperfect (yo había hablado).
The name of the tenses already give us a clue of what they imply: perfect is what the Latin called a situation that had happened in the past, but the consequences of it were already affecting the present. So, the present perfect is used when something has happened recently in the past, and the speaker is in the present. The pluperfect comes from the Latin expression plus quam perfect (more than perfect), and is used in similar situations, with the difference that the speaker is also in the past.
It is easier to see with some examples:
- Acabo de salir de la ponencia sobre los últimos avances en astrofísica.
- ¿Y de qué has hablado?
- He hablado acerca de las ondas gravitaciones.
Some examples with other verbs:
Me he despertado muy pronto y ahora tengo sueño.
Hoy he comido macarrones, estaban muy buenos.
This tense is widely used in Spain and some Spanish-speaking American countries. Other countries just use the preterite tense (actions that happened and ended completely in the past). This tense would replace the present perfect when the action has happened further in the past:
Ayer me desperté muy pronto y tuve sueño todo el día.
La semana pasada me comí unos macarrones que estaban buenísimos.
And finally the pluperfect. As I said, this tense is used the same way as the present perfect, but when the speaker is also in the past:
La ponencia sobre los últimos avances en astrofísica acababa de terminar. Aquel día había hablado sobre las ondas gravitacionales...
As you see, the narration puts the speaker in the past, and the action referred has just happened as something before that moment. This characteristic makes this tense only used in narrative:
Aquel día me había despertado muy pronto, por lo que estuve todo el día durmiéndome por los rincones.
Salí del restaurante con el sabor de los macarrones que había devorado aún en la boca.
You have more information in the Nueva Gramática Española: