The verb דִּבֵּר (dibber), which is conjugated in binyan Pi'el, is commonly followed by prepositions to indicate the person to or with whom the speaker is speaking. For example, אֶל (Gen. 8:15), לְ (Jdg. 14:7), עִם (Gen. 31:29), אֵת (Gen. 23:8), עַל (Jer. 6:10), and of course, בְּ (Hab. 2:1).
In Num. 12:1 and 12:8, the context implies that Aharon and Miryam are speaking "against" Moshe. On the other hand, in Num. 12:2, the context implies that Yahveh is speaking "by" Moshe.1 However, in each, the individual spoken "by" or "against" is preceded by the same preposition, בְּ. This could obviously be a cause for confusion.
However, it's not necessarily a contradiction since the prefix בְּ when following the verb דִּבֵּר can mean both "by," "with," and even "against" depending on the context. We have already supplied one verse where it means "with" (Hab. 2:1), as well as "by" (see footnote 2), but for a verse where it means "against," see Num. 21:7.2
Footnotes
1 Gesenius cites other examples of speaking "by," including 2 Sam. 23:2; 1 Kings 22:28.
2 Also, Job 19:18; Psa. 50:20, 78:19
References
1 Gesenius, Wilhelm. Hebrew and Chaldee Lexicon to the Old Testamament Scriptures.