def home(request):
if request.method == 'POST':
audios = request.FILES.getlist('audios')
for s in audios:
sample_rate, sound_data = scipy.io.wavfile.read(s)
data_points = sound_data[:, 0].size
length = data_points / sample_rate
data_shape = sound_data.shape
data_type = sound_data[:, 0].dtype
y_fourrier = np.abs(fft(sound_data[:,0]))
x_fourrier = np.linspace(0.0, sample_rate, data_points, endpoint=True)
y_fourrier = y_fourrier[0:data_points // 2 + 1]
x_fourrier = x_fourrier[0:data_points // 2 + 1]
#transform to log scale
y_fourrier_db = np.log10(y_fourrier)
photo=plt.plot(x_fourrier, y_fourrier_db)
image=Image.objects.create(
photo=photo,
)
img = Image.objects.all()
return render(request, 'myapp/home.html', {'img':img})