The determination of the spectral distribution of an x-ray beam from attenuation measurements in a narrow beam is an ill-conditioned problem that has aroused great interest since it was first proposed by Silberstein in 1932. In this work, the explicit reconstruction of the spectral distribution directly from the attenuation curve, without differentiating it, is carried out by a maximum likelihood method that allows one to impose a priori physical features of an x-ray spectral distribution, such as the positiveness of the solution, the boundness of its support, and the position and shape of the spikes and edges associated with the characteristic radiation. The numerical simulations made and the experimental validation of the proposed method have shown that it is possible to reconstruct x-ray spectra that, having a realistic shape, accurately fit the attenuation curve and predict the energy fluence. Nevertheless, the reconstruction of spectra including the K x rays of W is less accurate than the reconstruction of spectra including L x rays of W or K x rays of Mo, even when a priori information about the position and shape of the spikes and edges associated with the characteristic radiation is used.