To say words aloud when alone, directing speech at oneself rather than another person.
"She caught herself talking to herself while trying to solve the maths problem."
To be, or not to be, that is the question.
— William Shakespeare, Hamlet, Act 3 Scene 1 (Hamlet's soliloquy — canonical example of a character talking to himself)