If following 0ccam's rule one favors the less drastic divergence, gunpowder would come from the East (the earliest Chinese references date from the early 9th C., but they were mixing saltpeter and sulfur since the 1st C. and had observed the powerful flame of burning saltpeter, so...) at a time when the Roman legionaries no longer used pilum and scutum.
As observed in
another thread here and in Flint & Drake 'Belisarius' series gunpowder would in all likelihood be used at first in crude grenades thrown with staff-sling. The technological jump is minimal -the stuff can be very crude as in the Chinese 'shit bombs' ; no need of priming powder, lock &c. No cultural jump -staff-slings and thrown incendiaries are used for centuries. The rate of fire is good -far better than that of a musket- and the range excellent for the time.
Such staff-slings could be used by skirmishers, but also by the legionaries. At that time the legions (now some 800 -1000 strong) were turning to 'mixed' units, first ranks shield and pole weapon, rear ranks bow: the formation used by Ancient Assyrians and Persians -which Alexander tried to 'update' in his experimental phalanx- and OTL ultimately by the Burgundians of Charles the Bold (1st rank pavisa-bearer, 2nd rk pikeman, then several ranks of 'archers', actually a mlxture of longbowmen, crossbowmen and handgunners). Grenadier staff-slingers would perfectly fit in such formation, probably in the rearmost rank since the weapon requires some room.
As a refinement the staff of the staff-sling can double as kind of boarspear (in the same way a some musket rests doubled as short halberds).
The next step would be probably be rockets and /or (heavy) guns revolutionizing siege and naval warfare. I suspect individual firearms with a barrel would only come later.
Pistol-type handguns firing a single volley just before impact as in the 'Highland charge' do have an intellectual appeal, being used exactly in the same way as the pilum of old. And certainly the Romans could build barrels, but would 'pistols' 'catch' in the first time?
At that time Roman soldiers carried a handful of plumbatae / martiobarbuli leaden darts clipped inside their shield. Primitive 'pistols' don't seem to offer advantages (other than the noise, flame and smoke frightening men and horses, which would not last long) insuring they 'catch'. No better range (quite the opposite); penetrating power is not an issue before the introduction of full suits of plate armor -3 darts thrown in quick succession have good chance to hit a weak point in scale / mail armor. Besides to shoot a handgun requires far more attention than instinctively throwing a dart, distracting you at a very wrong time; primitive handguns require both hand to be shot, so you give up using your shield at a very critical moment.... Pistols would certainly appear eventually, but later, probably at first as cavalry weapons as OTL.
So, I'm afraid, no flintlocks in the Roman legions for more than a century.