Giant spiders in book spoke in their peculiar manner:
,,Their voices were sort of thin creaking and hissing, but he could make out many of the words that they said."
What language they used it's a different matter. It might be that due to their nature as offspring of Shelob's brood (and thus demonic entity of great power Ungoliant, whose daughter Shelob had similar powers and abilities, even some sort of mind influence on Gollum, by the way Ungoliant spoke too), sentient creatures that are more demonic than simply huge bloated animals, they can speak in debased form of westron (better known as Common Speech, even trolls can speak, orcs are billingual, it's a common tongue in Middle Earth as the name implies).
While in The Hobbit Bilbo's magic ring wasn't yet conceived in Tolkien's mind as the Great Ring of Power, the One Ring of Sauron (though already there are certain common elements like the trickster nature, playing tricks on owner like putting itself on finger or coming off on it's own at most inconvenient moments). It is all nicely connected though once the Lotr was published so there is no disrepancy. So it might be retconned to the power of understanding the Ring gives the wearer (so the great spiders of Mirkwood might use form of Black Speech or any other form of language though that sort of speculation is unnecessary as I think they indeed used westron).
I also don't quite understand complains about various talking animals, while in fact there is very few of them that would speak with words in the manner of men (ravens of Erebor come to mind as primary example). Most use their own forms of language or communication and it is the members of sentient races men, elves, dwarves that have ability to understand or talk in the assorted animal languages (Bard has ability to understand and talk with trushes as ,,The Men of Dale used to have the trick of understanding their language, and used them for messengers to fly to the Men of the Lake and elsewhere", Beorn too talks with animals in their own languages, as well as he can somehow breed magical animals, much more intelligent, that serve him in his household, he even kept bees larger than thumb which is not natural in my opinion, dwarf Balin from Thorin's company could understand languages of birds though Bilbo heard only usual bird cries).
There is also category of unnatural creatures like Wargs (semi sentient but very bestial race of huge wolf-like creatures larger than ordinary wolves so much that orcs can ride them, when wargs would allow them) and Great Eagles (and great spiders count here too), that either talk in their own way like ,,dreadful language of Wargs" or were simply able to use language of other races.
I see no disrepancy either as in Lotr we have elves able to speak with trees, sense aura of places like some sort of emphatic ability, forms of telepathy or, to simply put it, magical creatures (like Mearas who understand speech of men though themselves do not speak as we do, but they are super horses in many ways), Dark Lord used various creatures of animal sort (birds especially) as spies, even in Silmarillion we have examples of an elf who could learn languages of animals (one of the sons of Feanor, Celegorm), Great Eagles of course too spoke in Lotr, one even sang to the people of Minas Tirith announcing the fall of Sauron (heard plainly by thousands of people in the city, including Faramir and Eowyn). Gandalf also spoke to the warg like things that attacked fellowship in Hollin so it implies they could understand him (though as it later turned out they were not typical wargs at all and it's not certain whether they actually were of this kind, as their corpses disappeared, possibly they were some sort of phantoms)
I think that if someone is looking for explanation then we can say that some creatures were simply enhanced and raised to higher level by the Valar (or Dark Lords) like maybe hound Huan, some are creatures that simply have their own ways of communication and various sentient people learn how to use them (call it magical ability if you will), and some might not be animals at all but things in such form (it is rather speculative but it might be that some of the ,,spirits from afar" sent ,,among the kelvar and the olvar" (plants and animals), these guardians like Yavanna envisioned the souls not of Ainur that formed new kinds of beings (like Ents, they breed and are alive, have souls but are not of the divine being Ainur).
It should be noted that in the movie one of the spiders (the one killed by Bilbo) spoke plainly after hobbit took off the Ring and thus he gave new name to his sword (the spider pierced by elven blade hisses ,,it stings" when Bilbo is already visible, without the ring, but in my opinion the scene of that event in book was much more awesome than this rushed sequence, Bilbo alone kills spider in brief and vicious struggle for life, then loses consciousness and declares after coming to and seeing spider's corpse ,,I shall name you Sting", even book battle with spiders was more glamorous at one point book-Bilbo throws himself from the tree branches to the ground to land in the cluster of spiders and starts slashing like a real warrior hero).