It could be hardware related, or a dirty mic slot. From what I have read over the past few years, its' almost always software related though. Have you tried a simple Cache Clear & reboot? Here are the instructions:
If that doesn't help, run the phone in Safe Mode. If the mic works in Safe Mode then you know it's an app from the Play Store causing the issue (normally), and then you can take action from there. Safe Mode instructions:
You could just jump right in and do a factory reset (FDR), but that might be overly aggressive right now. I would suggest going to Settings > Apps > Downloaded. This is the list of apps you have downloaded from the Play Store. Start Uninstalling one or two at a time, reboot the phone, try the mic again. Keep a list of which ones you are uninstalling so you can figure out which one it is and then you know which ones you can safely re-install. I would look at the list and see if any would have anything to do with the microphone and start with those. Voice recorder apps, telephone type apps, anything that would be using the microphone. Hope that makes sense and helps out.