Hey tereza114,
Thanks for reaching back out and letting us know the sound quality issues occur when using headphones and the speaker.
If you've already tried updating and restarting, try reinstalling the iOS. Before you proceed, please back up your data using the steps below. Reinstalling the iOS only overwrites the iOS on the device, and does not affect personal data, but it’s always recommended to have a backup first: How to back up your iPhone, iPad, and iPod touch.
Once you've verified that your backup is current, follow the steps below to reinstall iOS on your iPhone. Keep in mind that this article was written for a different issue, but these steps will still be helpful. Also be aware, you'll want to click the "Update" button and not the "Restore" button when prompted as the "Restore" button will restore the device to factory settings: If your iPhone, iPad, or iPod touch won't turn on or is frozen.
Have a great day.