Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
def to_librosa(file_uploaded):
if file_uploaded is not None:
y, sr = librosa.load(file_uploaded)
return y, sr
# Define the 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
}
# Define the apply_equalizer function
def apply_equalizer(audio, sample_rate, equalizer_settings):
magnitude_freq_domain, frequency_freq_domain = fourier_transform(audio, sample_rate)
for band, settings in equalizer_settings.items():
low_freq, high_freq, gain_db = settings
for i, freq in enumerate(frequency_freq_domain):
if low_freq <= freq <= high_freq:
magnitude_freq_domain[i] *= 10**(gain_db / 20.0)
return inverse_fourier_transform(magnitude_freq_domain)
# Define the Fourier transform and inverse Fourier transform functions
def fourier_transform(audio_file, sample_rate):
number_samples = len(audio_file)
T = 1 / sample_rate
magnitude = np.fft.rfft(audio_file)
frequency = np.fft.rfftfreq(number_samples, T)
return magnitude, frequency
def inverse_fourier_transform(magnitude_freq_domain):
magnitude_time_domain = np.fft.irfft(magnitude_freq_domain)
return np.real(magnitude_time_domain)
# Other audio processing functions and utilities can be defined here
def audio_after_show(audio, sample_rate):
sf.write("output.wav", audio, sample_rate)
def spectogram(audio, title_of_graph):
D = librosa.stft(audio)
S_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)
fig, ax = plt.subplots()
img = librosa.display.specshow(S_db, x_axis='time', y_axis='linear', ax=ax)
ax.set(title=title_of_graph)
fig.colorbar(img, ax=ax, format="%+2.f dB")
return plt.gcf()
# Define the main audio processing function
def main_processing(file_uploaded, mode, equalizer_settings, show_spec, names, values_slider, ranges):
samples, sample_rate = to_librosa(file_uploaded)
if mode == 'Equalizer':
modified_audio = apply_equalizer(samples, sample_rate, equalizer_settings)
audio_after_show(modified_audio, sample_rate)
if show_spec == 1:
spectogram(samples, "Before")
spectogram(modified_audio, "After")
# Handle other processing modes and functions here
# Save Original Audio Function
def save_original_audio(samples, sample_rate, output_filename):
sf.write(output_filename, samples, sample_rate)
# Modify and Save Modified Audio Function
def save_modified_audio(magnitude_time_after_inverse, sample_rate, output_filename):
sf.write(output_filename, magnitude_time_after_inverse, sample_rate)
# Function to process the audio and redirect to result page
def process_audio(request):
if request.method == 'POST':
form = AudioUploadForm(request.POST, request.FILES)
if form.is_valid():
audio_file = request.FILES['audio_file']
unique_name = audio_file.name
print("unique_name:",unique_name)
file_path = os.path.join('media', audio_file.name)
print("file_path:",file_path)
# Save the uploaded audio file
with open(file_path, 'wb') as destination:
for chunk in audio_file.chunks():
destination.write(chunk)
# Process the audio file
mode = 'Equalizer' # Set your desired processing mode here
show_spec = 1 # Adjust as needed
equalizer_settings = equalizer_bands # Adjust the equalizer settings
# Define default values for names, values_slider, and ranges
names = []
values_slider = []
ranges = {}
if mode == 'Frequency':
names = list(dictionary_values.keys())
print("names:",names)
ranges = dictionary_values
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
elif mode == 'Vowels':
names = list(dictionary_values.keys())
print("names:",names)
ranges = dictionary_values
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
elif mode == 'Music Instrument':
names = list(dictionary_values.keys())
ranges = dictionary_values
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
elif mode == 'Pitch Shift':
names = ["Pitch Step"]
values_slider = [[-12, 12, 1]]
samples, sample_rate = to_librosa(file_path)
# Save the original audio
# save_original_audio(samples, sample_rate, 'media/original_audio.wav')
save_original_audio(samples,sample_rate,file_path)
orignal_audio_url = os.path.join(settings.MEDIA_URL,unique_name )
if mode == 'Equalizer':
modified_audio = apply_equalizer(samples, sample_rate, equalizer_settings)
# Save the modified audio
save_modified_audio(modified_audio, sample_rate, 'media/modified_audio12.wav')
equalizer_audio_url = os.path.join(settings.MEDIA_URL, "modified_audio12.wav")
# Process the audio and store the result in 'media/output.wav'
main_processing(file_path, mode, equalizer_settings, show_spec, names, values_slider, ranges)
return render(request,"jitsi/equalizer_file.html",
{"form":form,"equalizer_audio_url":equalizer_audio_url,
"orignal_audio_url":orignal_audio_url})
else:
form = AudioUploadForm()
return render(request, 'jitsi/equalizer_file.html', {'form': form})
![]() |
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