You read this incorrectly. The animal spoke for herself. It was Balaam who did wrong later.
"28 And the LORD opened the mouth of the ass, and she said unto Balaam, What have I done unto thee, that thou hast smitten me these three times?" Maybe the ass wasn't quoting but obviously spoke by G-ds power. And many an ass still claims to.