hydr0ph0en1x
I already said under 4 inches, and I suppose under $30 would be reasonable.
Hm. $30 might be difficult to push. most of the electronics that would fit in a case that small tend to be a little on the pricey side.
You could get something like a Teensy ($20), but I'm hard-pressed to think of a small synth you could add that would stay under a $30 total, short of just using a little piezo tweeter ($1.25), but those are hard to make sound like anything but an annoying buzzer.
Piano-like keyswitches that small will be hard to find. You could use SP-ST momentary switches, but they have a tendency to "bounce" and it would only make the whole circuit all the more complicated to get rid of that problem. As an alternative to keyswitches, you could use something like MaKey MaKey with conductive tape, but the MaKey MaKey alone is $50.
Doing proper synth will run over $35, too, unless you can find something more specialized than an Arduino Wave shield. Other than that, you'd have to make your own synth, which isn't as easy as it might sound. Making it sound reasonable is a pain.
If you're willing to bump your budget up past $70, I'd just say get some
conductive tape, a
Wave shield, and an
Arduino. You won't be able to fit it in a 4" box, but you can still make it.
If you have to go smaller, we can discuss options, but they're not many.