diff --git a/file.wav b/file.wav new file mode 100644 index 0000000..b923e22 Binary files /dev/null and b/file.wav differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..e8651aa --- /dev/null +++ b/main.py @@ -0,0 +1,48 @@ +import streamlit as st +import numpy as np +import matplotlib.pyplot as plt +import librosa +import soundfile as sf +import wave + + + +st.set_option('deprecation.showPyplotGlobalUse', False) + +with st.sidebar : + p=st.slider("Hearing loss percentage",min_value=0,max_value=100,step=1) + p*=0.01 + filename = "file.wav" + f=open(filename,'rb') + y,sr = librosa.load(filename) + valider = st.button("Valider") + + +if valider: + fft_signal = np.fft.fft(y) + amp = np.abs(fft_signal) + frequencies = np.fft.fftfreq(len(y), 1/sr) + a=np.random.choice(len(fft_signal), size=int(len(fft_signal)*p), replace=False) + fft_signal[a]=0 + amp2 = np.abs(fft_signal) + y_filtered = np.fft.ifft(fft_signal).real + plt.plot(fft_signal) + plt.show() + y_norm = librosa.util.normalize(y_filtered) + sf.write('output_file.wav',y_norm, sr,'PCM_24') + audio_file = open('output_file.wav','rb') + st.write("Original file") + st.audio(f) + st.write("Transformed file") + st.audio(audio_file) + col1,col2=st.columns(2) + with col1: + st.header('Original audio') + fig, ax = plt.subplots() + ax.plot(frequencies,amp) + st.pyplot(fig) + with col2: + st.header('Transformed audio') + fig2, ax2 = plt.subplots() + ax2.plot(frequencies,amp2) + st.pyplot(fig2) \ No newline at end of file diff --git a/output_file.wav b/output_file.wav new file mode 100644 index 0000000..19ea194 Binary files /dev/null and b/output_file.wav differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d235bdf --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +streamlit==1.29.0 +numpy==1.26.2 +matplotlib==3.8.2 +librosa==0.10.1 +wave==0.0.2 +soundfile==0.12.1 \ No newline at end of file