People could not hear me speaking when calling me on my iPhone 4, but the voice recorder app worked fine. I had read this might be related to different microphones being used for different applications, and a noise cancelling feature might be further complicating things.
I tried cleaning both the grills on the bottom, and the microphone on the top near the headphone jack. This seemed to give intermittent respite. I then tried a full restore, to no effect. I took it to the store this morning, explained the research I had done and yes, I had done a restore, and 10 minutes later I was walking out of the store with a replacement handset.
The problem hasn't recurred, but I've not tested it thoroughly. If it was a software problem, it would be annoying to have added it back to the new handset in the restore process. But it could be that in the half-year or so of having had the iPhone 4 mostly in a pocket, the top microphone just gets clogged with dirty. Maybe Apple just take them back, clean them out and send them out again.