If it's when speaking a foreign language, then that's entirely normal. I have a fairly intermediate level of Spanish - when I'm reading or writing. The second I try to speak to anyone, everything I know disappears out of my head and I speak complete rubbish!!
If it happens when you're speaking your native language, then it could be a self-confidence/shyness issue.
In both cases, my suggestions is practice! Practice at home, alone, in front of the mirror. Talk to the TV. Talk to the radio. Talk talk talk. Record yourself speaking. Don't read something from a book. Just switch on your webcam or a voice recorder and just start talking as if you were talking to another person. Talk more than usual to people in shops, on buses, people you don't know and probably won't ever see again!
Student or Learner