Most software-level glitches can be resolved either by restarting your phone or by performing a soft reset. If the software-level glitch is more than minor, then a hard-reset may work. If the software-level error is severe (corruption), then the Lumia Software Recovery Tool might work.
However, none of these methods will work if the glitch is at the hardware-level.
There once was a way to enable the diagnostics tool/app native to the phone by pressing ##634#, but that doesn't seem to work now after recent OS updates. The
Diagnostics App of Microsoft is also no longer published.
You may use the
Signal Generator App to test the speakers of your phone. If you want to test the earpiece, try simply dialing any invalid number and see if you hear something like "The number you dialed is incorrect" through the earpiece.
Then, use your headset and try generating any sound or calling any number. If you hear something in your headset, then the problem (either with your phone speakers or with the earpiece, depending on which one you tested) might be hardware-level already. Hardware-level defects can only be resolved by having it repaired in a service center.