Answer:
The story of Balaam and his talking donkey is found in Numbers 22. Balaam was a pagan prophet who practiced divination and other magic arts, led Israel into apostasy, and was identified as a false prophet by Peter and Jude (2 Peter 2:15-16; Jude 1:11). Fearing the encroaching Israelites, King Balak of Moab sent for Balaam and enlisted his aid in repelling the Israelites by cursing them. The Lord spoke to Balaam and told him to refuse to go to Balak, although the Lord relented under the condition that Balaam would speak only His words. So Balaam saddled his donkey and went with the princes of Moab back to Balak.

But knowing Balaam’s heart, the Lord’s anger burned against Balaam for what He knew was Balaam’s rebelliousness, and He sent an angel with a drawn sword to bar his way. Although Balaam couldn’t see the angel, his donkey could, and she tried to discontinue the journey by going off the path, crushing Balaam’s foot against the wall and lying down on the path. Angered by her behavior, Balaam used his staff to beat the donkey three times. Then in Numbers 22:28, we learn that “the LORD opened the donkey's mouth, and she said to Balaam, ‘What have I done to you to make you beat me these three times?’” Then Balaam and the donkey proceeded to have a conversation about the situation, with Balaam angrily berating the donkey, after which the Lord opened Balaam’s eyes to see the angel and understand why his journey was stopped.

There is no doubt that Balaam’s donkey spoke to him. The question that arises is whether the donkey was suddenly given the power of speech, which would also mean she was given the power to reason because she answered Balaam’s questions, asked some of her own, and carried on a rational conversation. While it is certainly possible that God granted human powers to the donkey, it’s more likely that He opened her mouth and spoke through her. The angel that barred his way is identified as the angel of the Lord, likely a manifestation of the presence of God Himself (Genesis 16:9-16; Exodus 3:1-6). After the donkey “spoke” to Balaam, and Balaam’s eyes were opened, the angel proceeded to ask the identical questions that came from the mouth of the donkey, further evidence that God, not the donkey, was actually speaking both times. This is reiterated by Peter, who identifies the donkey as “a beast without speech” and who “spoke with a man’s voice” (2 Peter 2:16). Whatever the method, the donkey was able to speak by a miraculous working of God’s power.

Why was Balaam not shocked into silence by the donkey speaking to him? Surely, it must have come as a surprise to him, and under normal circumstances, the obvious reaction would be for him to at least ask how she came to be speaking. The Bible doesn’t tell us why he didn’t find it odd to be addressed by a donkey, but we do know something about his state of mind. First, he was in rebellion against the Lord, going to Balak for his own purposes and not those of the Lord. Second, the donkey’s refusal to continue down the path enraged him so that he beat her out of anger because she had mocked him and made a fool of him. Anger has a way of curtailing rational thought, and perhaps he was so intent on exerting his dominance over the animal that he lost the ability to think clearly. It wasn’t until the angel opened Balaam’s eyes to see reality that he relented in his anger against the donkey, listened to the angel, and repented. Verse 38 tells us that Balaam went to Balak and told the king, “I must speak only what God puts in my mouth," which just goes to show that God can use anyone, even a donkey and a rebellious prophet, to do His will and speak His truth.