We have studied the improvement of energy spectra of a cadmium telluride (CdTe) semiconductor detector by means of a neural network algorithm. The neural network recognized pulse shapes and determined the corrective magnification factors of digitally shaped pulse heights. That is to say, the neural network recognized the difference in the pulse shapes due to the incomplete charge collection and made up for the ballistic deficit of each pulse. We obtained the energy spectra of several gamma ray sources. After the processing, the energy spectra became more ideal profile and the energy resolution (FWHM) changed for the better.