Carl,
If the cable is securely attached at the gearbox end the problem is probably not there.
Have you checked the cable connection at the back of the speedo? It is a finger nut and, if loose, could cause the speedo to cut in and out as the square end of the inner cable becomes disengaged from the drive hole.
As it sometimes works the inner cable is unlikely to be broken but it is still worth checking. Probably wortb stripping the cable out, cleaning and re-greasing while you are at it.
B……