The Speaker of the U.S. House is elected by the majority of the majority caucus. The minority caucus has no say.
That is true in real world politics, but not in theory. The whole House does vote on the Speaker. Occasionally conservative Democrats have broken ranks and voted for someone other than the Democrat, but not enough to make a difference.
In a closely divided House the minority party could get their speaker candidate elected by persuading a few people from the majority to switch sides. That happened a number of years ago in California if I remember correctly.
It is extremely unlikely but not totally impossible with the current makeup of the House of Representatives. I can't realistically see enough Republicans jumping ship to get Pelosi elected speaker, and I can't see Pelosi stepping aside to let another Democrat take that role who might be acceptable to "moderate" (i.e., liberal) Republicans.