You could try restoring the OS to new. If that doesn't fix it - it's toast. Repair or discard. The problem you describe is very common with the iPhone 7.
Happened to me with my iPhone 11 Pro Max - Apple replaced under warranty as it was a hardware issue. Try playing music and it’ll only fire from the bottom
Speaker and sound off.
Contact Apple.