Transform audio into fourier series

For computing de distances among the songs, this library uses de frequencies of the analogous Fourier Series from the songs. This frequencies are obtained with numpy.fft function.

Because numpy.fft only reads WAV, firstly songs must be transformed from MP3 to WAV. In this library, we use this function:

foucluster.transform.mp3_to_wav(mp3_file, wav_file, encoder='mpg123')[source]

Transform mp3 file into wav format calling bash and using mpg123 or ffmpeg.

Parameters:
  • mp3_file (str) – path to the mp3 file.
  • wav_file (str) – path to the new wav file.
  • encoder (str) – Encode to use. It could be mpg123 or ffmpeg.
Returns:

Once MP3 songs are encoded to WAV, Fourier transform is applied. To avoid too much useless information, frequencies are limited (to 6000 Hz by default) and grouped by a step size.

foucluster.transform.wav_to_fourier(wav_file, rate_limit=6000.0, step=1.0)[source]

WAV file is loaded and transformed into Fourier Series. This Fourier Series is limited.

Parameters:
Returns:

Both process can be executed at one, included a plot of the Fourier series, with the following function.

foucluster.transform.time_to_frequency(song, temp_folder, output_folder, rate_limit=6000.0, overwrite=True, plot=True, image_folder=None, step=5.0)[source]

Transform a MP3 song into WAV format, and then into Fourier series.

Parameters:
  • song (str) – name of the song, with MP3 extension.
  • output_folder (str) – folder where pickle files from frequency series are saved.
  • temp_folder (str) – folder where wav files are saved.
  • rate_limit (float) – maximum frequency of the frequency series.
  • overwrite (bool) –
  • plot (bool) – if True, frequency series is plotted.
  • image_folder – if plotting is True, is the folder where the Fourier data is saved.
  • step (float) – step of the Fourier series.
Returns:

When this last function wants to be executed for a whole folder, with or without multiprocessing, this can be done with the main function

foucluster.transform.transform_folder(source_folder, output_folder, temp_folder, rate_limit=6000.0, overwrite=True, plot=False, image_folder=None, multiprocess=False, encoder='mpg123', step=5.0)[source]

Transform a directory full of MP3 files into WAV files, and then into Fourier series, working with directories.

Parameters:
  • source_folder (str) – folder where MP3 files are.
  • output_folder (str) – folder where pickle files from frequency series are saved.
  • temp_folder (str) – folder where wav files are saved.
  • rate_limit (float) – maximum frequency of the frequency series.
  • overwrite (bool) –
  • plot (bool) – if True, frequency series is plotted.
  • image_folder – if plotting is True, is the folder where the Fourier data is saved.
  • multiprocess (bool) – if True, encoding and Fourier transform are run in several cores. It may be unstable (consume to much RAM).
  • encoder (str) – encoder from MP3 to WAV.
  • step (float) – step of the Fourier series.