def main(source, target='', pca='', start=0, seconds=10.): b = audio.Builder() mels = b.read(source, pca, start, seconds) if b.log: mels = np.exp(mels) # reconstruct the linearly-spaced spectrum by inverting the triangular # mel-spaced filterbank. since the filterbank converter is a rectangular # matrix, this will inevitably result in some loss, but by keeping the # number of mel filters relatively large we can minimize that loss. filters, _ = mel.filterbank(b.width // 2 + 1, mels.shape[1]) finv = np.linalg.pinv(filters) mags = np.dot(mels, finv) logging.info('inverting mels %s x inverse %s => mags %s', mels.shape, finv.shape, mags.shape) #lmj.plot.axes(211, spines=False).imshow(np.log(mels).T, origin='lower') #lmj.plot.axes(212, spines=False).imshow(np.log(mags).T, origin='lower') #lmj.plot.show() b.reconstruct(mags) b.write(target or source.replace('.npy', '.wav'))