Stream of consciousness writing
If it is done in context with the surrounding world it is called interior or internal monologue. That means it is unspoken, and in some cases could not be spoken. For example, in Mikhail Bulgakov's Heart of a Dog (1925) the first chapter is entirely based on the dog's unspoken thoughts on the world about him.