There are do it yourself kits, but I've yet to do it.
I go to a "ear doctor" in an effort to get a good job done.
They fill your ear with a quick set foam of some sort, feels like toothpaste, then send it off.
There are different ones available, some to block more sounds or frequencies and such, some to accommodate ear phones, etc.
You can hear your machine just fine, in some cases better, because it muffles all the extra clanging and banging going on.
At first it's like a knew pair of shoes, can kinda hurt your ears as they are so full, but you get used to it. You ca