I've had this happen on both my both my iPhone X and XS Max. It has also affected my alarm clock as well, set the alarm, goes off on time but no sound comes out (almost late for work twice). I have noticed the sound does this problem sometimes after using the mic on messages. Have to do a reset to get it working again. Because of this issue I set a backup alarm now and usually check that the volume is working by going into the phone keyboard to make it makes the sound when you dial. Also restart my phone at least once a week and test to make sure the volume works. It is frustrating and I've had this happen at least 8 times in about the same time frame.