It’s really a street theatre trick. Snakes don’t have outer ears and can only sense sounds loud enough to vibrate their skeleton. Although it appears to be dancing in time to the music from the snake charmer’s pipe, or pungi, it is actually tracking the movements of the pipe itself, as a threat.
Cobras can’t reach farther than a third of their body length when they lunge so charmers sit comfortably out of range. Often they will remove the snake’s fangs. The fangs regrow in a few days, so this procedure has to be repeated.
Answered by Luis Villazon