Pro-grammatical detection while recording

How can one implement a custom solution of detecting the phrase “end of message” programmatically. Sending the input upon recognizing it, please?