Another possibility is to turn on the loudspeaker when the keyboard is open and turn off when the keyboard is closed (like in E90 for instance).