If you have an iPhone 12 and can’t hear anything on the phone, the small speaker in the earpiece might be defective. Apple will replace it free of charge.
The iPhone 12 and iPhone 12 Pro are affected, but not the Phone 12 mini and iPhone 12 Pro Max. Although affected devices are still under warranty, which is valid for one year, Apple is now extending the period to two years after purchase. It is likely a defective batch of speakers. However, if the defect occurs after these two years, you will probably be stuck with the costs.
Affected devices are from the production period October 2020 to April 2021. Apple does not provide exact serial numbers. It is also important to note that Apple does not simply replace the potentially defective part, but only when it is really defective.
If you have an affected device from the mentioned period, you can find the official Apple page about the repair program here.