I say the wirecontacts need to be cleaned and ..but if that is not the case, the speed sensor is going out.
you can test this..the sensor is at the end of the trasnmission to the driver side. after you raised the car and have it secured and using a AC voltage scale..start the car and put it gear and check that the voltage increases with the speed of the car
If that does not happen change the sensor