Is there a term for the habit of talking to oneself?

Some people (I admit I’m one of them) occasionally let their inner voice come out and talk to themselves. In my case, without thinking about it, I will start to move my lips or whisper, or even articulate as though having a dialogue - embarassing if a stranger happens to overhear you.

Does this habit have a name? Is there a theory as to why this might happen?

Thanks.

Soliloquise?

I say to myself, “Self, this topic has come up before, hasn’t it? By gum, it has, Self!” See this thread where I quoted from this abstract from Psychology

Surely we should all be on speaking terms with ourselves.