NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


def fourier_transform(audio_file, sample_rate):
number_samples = len(audio_file)
T = 1 / sample_rate
magnitude = rfft(audio_file)
frequency = 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)


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)


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)

@csrf_exempt
def process_audio(request):
if request.method == 'POST':
form = AudioUploadForm(request.POST, request.FILES)
if form.is_valid():
try:
audio_file = request.FILES['audio_file']
print("audio_file:",audio_file)
temp_audio_filename = audio_file.name
print("temp_audio_filename:",temp_audio_filename)
wav_file_path = os.path.join(settings.MEDIA_ROOT, temp_audio_filename)
print("wav:", wav_file_path)
with open(wav_file_path, 'wb') as temp_audio:
for chunk in audio_file.chunks():
temp_audio.write(chunk)
data, sr = librosa.load(wav_file_path)
print("data:", data)
print("length_of_audio:", len(data) / sr)
# Process the audio using the provided code
mode = "Equalizer" # Set your processing mode here
show_spec = 1 # Set whether to show spectrogram (1 for yes, 0 for no)

# Define equalizer settings (if using Equalizer mode)
equalizer_settings = {
'Bass': [20, 200, 0], # Adjust these settings as needed
'Midrange': [200, 2000, 0],
'Treble': [2000, 20000, 0]
}

# Define default values for names, values_slider, and ranges
names = []
values_slider = []
ranges = {}

# Define frequency-based settings here (similar to the provided code)
if mode == 'Frequency':
dictionary_values = {"0:1000": [0, 1000, 0],
"1000:2000": [1000, 2000, 0],
"2000:3000": [2000, 3000, 0],
"3000:4000": [3000, 4000, 0],
"4000:5000": [4000, 5000, 0]}
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
names = list(dictionary_values.keys())
ranges = dictionary_values
# Define vowel-based settings here (similar to the provided code)
elif mode == 'Vowels':
dictionary_values = {"h": [1900, 5000, 0],
"R": [1500, 3000, 0],
"O": [500, 2000, 0],
"Y": [490, 2800, 0]}
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
names = list(dictionary_values.keys())
ranges = dictionary_values
# Define music instrument-based settings here (similar to the provided code)
elif mode == 'Music Instrument':
dictionary_values = {"Drum ": [0, 500, 0],
"Flute": [500, 1000, 0],
"Key": [1000, 2000, 0],
"Piano": [2000, 5000, 0]}
values_slider = [[0, 10, 1]] * len(list(dictionary_values.keys()))
names = list(dictionary_values.keys())
ranges = dictionary_values
# Define pitch shift settings here (similar to the provided code)
elif mode == 'Pitch Shift':
dictnoary_values = {"Pitch Step": [0, 0]}
values_slider = [[-12, 12, 1]]
pitch_step = st.slider(label="Pitch Shift", max_value=12, min_value=-12, step=1, value=5)
# Process the audio using the provided code
samples, sample_rate = data, sr
save_original_audio(samples, sample_rate, os.path.join(settings.MEDIA_ROOT, "original_audio.wav"))

if mode == 'Equalizer':
modified_audio = apply_equalizer(samples, sample_rate, equalizer_settings)
save_modified_audio(modified_audio, sample_rate,
os.path.join(settings.MEDIA_ROOT, "modified_audio.wav"))
# return HttpResponse("file upload successfully")
except Exception as e:
print(f"Error processing audio: {e}")
pass

else:
form=AudioUploadForm()
return render(request,"jitsi/equalizer_file.html",{"form":form})


def download_original_audio(request):
file_path = os.path.join(settings.MEDIA_ROOT, "original_audio.wav")
print("file_path:",file_path)
response = FileResponse(open(file_path, 'rb'))
print("r:",response)
return response


def download_modified_audio(request):
file_path = os.path.join(settings.MEDIA_ROOT,"modified_audio.wav")
print("file_path:", file_path)
response = FileResponse(open(file_path, 'rb'))
print("r:", response)
return response
     
 
what is notes.io
 

Notes.io is a web-based application for 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 12 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.