A new technique for gamma-ray and X-ray spectral analyses is described. It employs an artificial neural network in order to meet requirements of easiness, compactness and promptness of the analysis. This technique only needs a suitable set of component spectra for the network training. Performance test of the network shows good results for gamma-ray spectra obtained by a 3"×3" NaI(Tl) spectrometer, and both for gamma- and X-ray spectra obtained with an 80cc high purity germanium detector. Degradation conditions and applicability to a PIXE analysis are discussed.