A soliloquy is a dramatic device in which a character speaks his or her thoughts out loud.
The purpose of such a device is to illustrate what is going on in the character's head in a way that can not be done quite as well through dialogue or action. This can be very important in a play because the character's thoughts can be quite central to the development of the play.
For example, in Hamlet's "to be or not to be" soliloquy, we are given an insight into his psyche and we are allowed to understand what his thoughts are about life and death.
A soliloquy is a literary device used by writers to give insight into a character's inner feelings. By definition, it is a dramatic convention in which a character, usually alone on stage or at least not heard by other characters on stage, speaks his thoughts aloud. Soliloquies are usually meant for the audience's ears only and informs them about the character's motivations and state of mind. A similar literary convention is an "Aside," in which the speaker directs his dialog to the audience while members onstage are unable to hear. Shakespeare's "To be or not to be" speech in Hamlet is probably the most famous example of a dramatic soliloquy. (The Bedford Introduction to Literature, 6th Edition)