Hi,
It could be a cleaning issue or perhaps a faulty speaker.
Either way you may have to open the phone to find out
Here’s the ifixit [guide|119328] guide which may be of some help.
If it is determined that the earpiece speaker is the problem [https://www.ebay.com/b/Ear-Speakers-for-Samsung-Galaxy-S9/43304/bn_118260132|replacement earpiece speakers - examples only] are available online. Just search for ''Galaxy S9 earpiece speaker part'' to get results for suppliers that suit you.