Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert .mp3 files to arrays of frequencies and amplitudes using python?

I wanted to design a neural network, which after training would take .mp3 files as input, and then based on training, it would decide if the music is good or bad on a scale of 1-10. But for this, I would need to convert the audio file into arrays of wavelength, frequencies, amplitude and all other parameters required to define music, and then use these arrays as input to the neural network. How should I approach this problem?

like image 552
Tarun Khare Avatar asked Feb 25 '18 08:02

Tarun Khare


1 Answers

if you convert your .mp3 files to .wav you can do:

from scipy.io import wavfile as wav
from scipy.fftpack import fft
import numpy as np
rate, data = wav.read('music.wav')
fft_out = fft(data)

From http://www.dummies.com/programming/python/performing-a-fast-fourier-transform-fft-on-a-sound-file/

like image 131
Nathan Avatar answered Nov 01 '22 17:11

Nathan