NaI(Tl) and LaBr 3 (Ce) detectors are frequently operated under unstable temperature conditions when used in an open environment. These temperature changes result in a peak shift and spectral distortion during measurement. Two methods are proposed to stabilise the measured spectra; they are applied using a software algorithm, without the necessity of adjusting the gain. Both methods are based on the experimental observation that the relative channel displacement due to temperature changes is approximately the same for all channels. The first method corrects the spectrum using experimental data obtained under controlled conditions in the laboratory, and thus it only depends on the detector temperature. The second method uses one known peak in the spectrum to correct all of the channels: the NORM 40 K peak for the NaI(Tl) detector, the internal contaminant peak of 138 La for the LaBr 3 (Ce), or an external source when these two cannot be easily identified.