The serpent in Genesis 3 has the ability to talk, but it isn't clear where that ability comes from.
In Numbers 22, Balaam the diviner is summoned by the King of Moab to give advice about what to do about the Israelites traveling through Moab. God sends an angel to oppose Balaam and his donkey from riding away. Each time the donkey goes astray from the path and Balaam beats it to get the donkey back to the path. After the third movement, this happens:
Then the Lord opened the donkey’s mouth, and it said to Balaam, “What have I done to you to make you beat me these three times?” (Numbers 22:28)
They go on to have a conversation.
29 Balaam answered the donkey, “You have made a fool of me! If only I had a sword in my hand, I would kill you right now.”
30 The donkey said to Balaam, “Am I not your own donkey, which you have always ridden, to this day? Have I been in the habit of doing this to you?” “No,” he said.
31 Then the Lord opened Balaam’s eyes, and he saw the angel of the Lord standing in the road with his sword drawn. So he bowed low and fell facedown.
32 The angel of the Lord asked him, “Why have you beaten your donkey these three times? I have come here to oppose you because your path is a reckless one before me.
33 The donkey saw me and turned away from me these three times. If it had not turned away, I would certainly have killed you by now, but I would have spared it.”
34 Balaam said to the angel of the Lord, “I have sinned. I did not realize you were standing in the road to oppose me. Now if you are displeased, I will go back.”
35 The angel of the Lord said to Balaam, “Go with the men, but speak only what I tell you.” So Balaam went with Balak’s officials.
It is likely that there were mythical references to animals or things who talked before the Book of Numbers was composed, but this is the earliest instance I can find showing the moment of gaining the ability to talk in an otherwise human-populated narrative.