He told his servants to not kill two snakes, and he in turn learned the language of the Animals.
When Melampus lived with Neleus, he dwelt outside the town of Pylos, and before his house there stood an oak tree containing a serpent's nest. The old serpents were killed by his servants, and burnt by Melampus himself, who reared the young ones. One day, when they had grown up, and Melampus was asleep, they approached from both sides and cleaned his ears with their tongues. Being thus roused from his sleep, he started up, and to his surprise perceived that he now understood the language of birds, and that with their assistance he could foretell the future. In addition to this he acquired the power of prophesying, from the victims that were offered to the gods, and, after having had an interview with Apollo on the banks of the Alpheius, he became a most renowned soothsayer (Apollod. i. 9. § 11; Eustath. ad Hom. p. 1685).
Specifically from Apollodorus's Library,
Amythaon dwelt in Pylus and married Idomene, daughter of Pheres, and there were born to him two sons, Bias and Melampus. The latter lived in the country, and before his house there was an oak, in which there was a lair of snakes. His servants killed the snakes, but Melampus gathered wood and burnt the reptiles, and reared the young ones. And when the young were full grown, they stood beside him at each of his shoulders as he slept, and they purged his ears with their tongues. He started up in a great fright, but understood the voices of the birds flying overhead, and from what he learned from them he foretold to men what should come to pass. He acquired besides the art of taking the auspices, and having fallen in with Apollo at the Alpheus he was ever after an excellent soothsayer.