Speech recognition is not an easy task. Oracle offers an API.
The Java Speech API allows Java applications to incorporate speech technology into their user interfaces. It defines a cross-platform API to support command and control recognizers, dictation systems, and speech synthesizers.
You can view the full documentation here.