If you lose sound for keyboard clicks, games or other apps, email and other notifications, system sounds have probably been muted.
System sounds can be muted and controlled in two different ways: either by the side switch (located next to the volume up/down controls) or in the Recent Apps tray. The initial default is via the side switch.
Check the status of Settings > General > Use Side Switch to:. If this is set to Mute, the switch on the side of the iPad will mute system sounds.
If this is set to Lock rotation then the mute system sounds control is in the Recent Apps tray. Double tap the home button and, in the tray which appears at the bottom, swipe all the way to the right. The speaker icon is on the left. Is it is crossed-out tap on it and mute will be turned off and system sounds will be turned ON.
This Apple Support article explains in more detail how the side switch works.
I had the same problem as well for nearly 3 months.
I had tried bring the Iphone into my phone carrier and they sent me to the AppleStore. When I brought it to them they hooked it up to the diagnostic machine and they told me just to restart the Iphone from the factory settings.
This didn't work either. To complicate things more, other "solutions" seem to only yield temporary success. These temporary solutions included: blowing compressed air into every port, various restart combinations, various factory restore methods.
I had nearly given up until I stumbled upon a support post on Apple's website that finally yielded success.
The solution for me is listed as line 7, which reads:
"Check the receiver mesh (which is on the top front of the device, above the display). If it appears blocked, use a clean, small, dry, soft-bristled brush to carefully and gently brush away any debris."
Apparently, this cylinder shaped, mesh area is in some way tied to what triggers the headphones/speaker selection. I am not sure how, but I can say that after gently brushing it out my sounds are working again; specifically my music is now able to play directly off the speakers and my Iphone apps all play their sounds agian.
Hope this helps you as well!