Sorry to spoil the fun, but the snakes don’t actually respond to the music. In the wild, they sway whichever way their opponents go, and the snake charmer uses the flute as an enemy by hitting the snake on the nose with it during practice sessions with it, so that when it comes out of its basket it sees the flute and starts following it.