This paper revisits the classical problem “Can we hear the density of a string?”, which can be formulated as an inverse spectral problem for a Sturm-Liouville operator. Instead of inverting the map from density to spectral data directly, we propose a novel method to reconstruct the density based on inverting a sequence of trace formulas which bridge the density and its spectral data clearly in terms of a series of nonlinear integral equations. Numerical experiments are presented to verify the validity and effectiveness of the proposed numerical algorithm. The impact of different parameters involved in the algorithm is also discussed.