NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import numpy as np
import librosa
import soundfile as sf
import os
from django.http import HttpResponse
from django.shortcuts import render
from .forms import AudioUploadForm

# Define Equalizer Bands and Their Initial Settings
equalizer_bands = {
'Bass': [20, 200, 0], # Frequency range: 20Hz - 200Hz, initial gain: 0 dB
'Midrange': [200, 2000, 0], # Frequency range: 200Hz - 2kHz, initial gain: 0 dB
'Treble': [2000, 20000, 0] # Frequency range: 2kHz - 20kHz, initial gain: 0 dB
}


# Modify Audio Based on Equalizer Settings
def apply_equalizer(audio, sample_rate, equalizer_settings):
y, sr = librosa.load(audio, sr=sample_rate)
D = librosa.stft(y)
S, phase = librosa.magphase(D)

for band, settings in equalizer_settings.items():
low_freq, high_freq, gain_db = settings
start_bin = int(low_freq / (sample_rate / 2) * len(S[0]))
end_bin = int(high_freq / (sample_rate / 2) * len(S[0]))

# Apply gain in the specified frequency range
S[start_bin:end_bin, :] *= 10**(gain_db / 20.0)

# Reconstruct the modified audio
y_modified = librosa.istft(S * phase)
return y_modified


def process_audio(request):
if request.method == 'POST':
form = AudioUploadForm(request.POST, request.FILES)
if form.is_valid():
audio_file = request.FILES['file']
mode = form.cleaned_data['mode']

# Define the file paths for original and modified audio
original_audio_path = 'media/original_audio.wav'
modified_audio_path = 'media/modified_audio.wav'

# Save the original audio to a file
with open(original_audio_path, 'wb') as destination:
for chunk in audio_file.chunks():
destination.write(chunk)

if mode == 'Equalizer':
# Apply the equalizer settings and save the modified audio
modified_audio = apply_equalizer(original_audio_path, sample_rate=44100, equalizer_settings=equalizer_bands)
sf.write(modified_audio_path, modified_audio, 44100)

# Serve the modified audio for download
with open(modified_audio_path, 'rb') as audio_file:
response = HttpResponse(audio_file.read(), content_type='audio/wav')
response['Content-Disposition'] = 'attachment; filename="modified_audio.wav"'
return response
else:
form = AudioUploadForm()
return render(request, 'upload.html', {'form': form})
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.