Did all this happend after a system update? If so, something is most likely wrong with the drivers - backup your data and restore the phone.
However if that’s not the case, the earpiece speaker might be the problem. But before we dig deeper into that, here are some stuff you should try out:
- Front facing camera
- Ambient light sensor (just hover your finger over the top of the phone and your display should turn darker.
If these are working fine, something is most likely wrong with the earpiece speaker. Try to replace it.
However if the front facing camera and ambient light sensor didn’t work, it could be about a ribbon cable and if that’s the case, try to replace that.