Swap motor or upgrade
First, if you ask to use DCC, the motor need to be isolated from the frame of the locomotive; from the pictures you share yours is probably not.
This motor seems to be like the ones in many old brass models; it's an open frame motor; they are a little "has been" motors compared by tomorrow quality motors.
But you can upgrade them quiet easily and make them run better and slower; here is link how to improve them very easily by just changing the magnet of the motors.
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjgyfOZlpfpAhVQsKQKHRWIDuMQFjAAegQIAhAB&url=https%3A%2F%2Fmodel-railroad-hobbyist.com%2Fnode%2F17774&usg=AOvVaw2fWRIJm5puoKUkdTfm5c6Z
A swap of the motor is also an option, there are numerous good motors on the market, Mabushi, Faulhaber, Canon, Mashima, defunct Sagami; if place is tight some N scale motors like Kato or Atlas are excellent motors too.
Most of these modern motors have isolated frame, but test them with a anmeter for dcc use.
A swap motor need often a new support motor and the need to have the original gear on the motor shaft or a similar one; NWSL back in business, offer numerous gear arrangement.
They also offer some specialized upgrade kit for some existing models in brass.
Some of these new motors also comes with gear box, which give torque but also slower turning shaft which can achieve excellent slow speed performances
Adding a flywheel if place permit it, can also upgrade the performances of the locomotive
Sweet DCC locomotives need good electrical contact; it's important to check this or upgrade the wheels contact with the track.
Adding weigh after remotoring ang gearing is the only way to improve the running qualities of a locomotives.
The following formula can also help you to calculate a gear ratio if your locomotives run too fast
GEAR RATION = MOTOR SPEED AT 12v : PROTOTYPE MAX WHEEL RPM
You Tube offer some example of swap motors in different models of locomotives
A complete swap of the motor and the gearbox is an option too, but probably need great modification.
Better is to keep the original gearbox and just swap the motor.
You just need to make a support for the new motor; this is the biggest modification in this case; piece of styrene can do the job.
My opinion; I have made many swap in N scale locomotive including gerbox.
Iit's just quick suggestion from just the picture you share, so check if it's possible or not.
It seems from the pictures you share, the motor shaft pass through a soldered bearing.
I don't know if the gearboxes is soldered to the frame of the locomotive, but first try to study a way without unsolder the bearing, to take away the motor and the gearbox
Probably the gearbox will comes away with the motor attached to it; take care about the coupling between the gearbox and the cast lateral piston of the Heisler system
You can go with the magnet option upgrade here; the simplest to go, this one could be satisfactory for your needs; just when you put the assembly back isolate the motor from the frame of the locomotives with a thin shim of plastic and probably plastic screws.
Picture don't help a lot for me, but seems the motor shaft is first maintained in the brass bearing and there is also a form of maintain just next of the gear at the end of the shaft.
This could be a good news since the shaft is aligned and maintained in two places and the gear is between.
If this is the case and you ask to swap the motor, there are 2 options to my eyes.
First check original shaft diameter and the diameter of the future new motor; try to find the same if possible, this help a lot; the bigger motor you can put in the better is.
Find also a motor with two long shaft, you can cut them later to length with a dremel disk.
First take off the gear from the motor shaft ( NWSL has a tool for such job), if possible do it it without unsolder the brass bearing, seems to me is faisable .
If all go well put the gear back on the new motor shaft after placing it in the brass bearing; "...….. you just need to do a new support under the motor and align shaft and gear assembly onto the gearbox."""
If the original shaft is really maintained in place by the brass bearing and a second one after the gear, you can cut the existing motor shaft as far you can outside the brass bearing just along the collector of the motor.
Open frame motor are easy to disassemble and you can take of pieces front of the collector to have a longer shaft to work with
This way you have change nothing from the original gearbox and gear assembly; you just need to couple the new motor shaft with this gearbox by connecting it to the rest of the shaft of the open frame motors.
This would be an "easy" way to go to my eyes, probably the way I would go if this was my model.
Do it with a new shaft coupling or a simple plastic tube coupling, NWSL has coupling shaft too, to connect the motor shaft and the rest of the original one; there are numerous options to do it again, chech You Tube or forum thread about it; probably some shim will be needed to keep the gear on the good place in this case.
On the other side of the motor shaft you can put a flywheel, again NWSL is a good ressource for them.
Again just what I see from your pictures; this need for sure more study
Good luck