This happened to me when I was visiting a relative in Oakland. I hit the floor when I heard gunshots and crawled to the back of the house then wondered why it was going on so long. Finally realized it was fireworks at 1:00 in the afternoon. WTF?!
While solitary noises may be difficult to tell if it is a firecracker or gunshot if there are more than one listen to the rhythm and number. With practice you can tell if it is celebratory air shots or serious and whether or not it is a revolver or semiauto. I've been living on the southside of Chicago for over 20 years so I've had lots of practice.
I like firearms and shoot regularly, and if you hear both somewhat frequently, it isn't that hard to tell the difference.