Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,37 @@
|
|
1 |
-
os.system('pip uninstall -y numpy')
|
2 |
-
os.system('pip install numpy')
|
3 |
import librosa
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
def greet(name):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
#mel -> audio
|
14 |
|
15 |
iface = gr.Interface(fn=greet, inputs= gr.Image(label="Mel spectrogram", image_mode="L"), outputs=gr.Audio(label="Audio"))
|
|
|
|
|
|
|
1 |
import librosa
|
2 |
import gradio as gr
|
3 |
+
import soundfile as sf
|
4 |
|
5 |
def greet(name):
|
6 |
+
# step1 - converting a wav file to numpy array and then converting that to mel-spectrogram
|
7 |
+
my_audio_as_np_array, my_sample_rate= librosa.load("audio1.wav")
|
8 |
+
|
9 |
+
# step2 - converting audio np array to spectrogram
|
10 |
+
spec = librosa.feature.melspectrogram(y=my_audio_as_np_array,
|
11 |
+
sr=my_sample_rate,
|
12 |
+
n_fft=2048,
|
13 |
+
hop_length=512,
|
14 |
+
win_length=None,
|
15 |
+
window='hann',
|
16 |
+
center=True,
|
17 |
+
pad_mode='reflect',
|
18 |
+
power=2.0,
|
19 |
+
n_mels=128)
|
20 |
+
|
21 |
+
# step3 converting mel-spectrogrma back to wav file
|
22 |
+
res = librosa.feature.inverse.mel_to_audio(spec,
|
23 |
+
sr=my_sample_rate,
|
24 |
+
n_fft=2048,
|
25 |
+
hop_length=512,
|
26 |
+
win_length=None,
|
27 |
+
window='hann',
|
28 |
+
center=True,
|
29 |
+
pad_mode='reflect',
|
30 |
+
power=2.0,
|
31 |
+
n_iter=32)
|
32 |
+
|
33 |
+
# step4 - save it as a wav file
|
34 |
+
return sf.write("test1.wav", res, sashi_sr)
|
35 |
#mel -> audio
|
36 |
|
37 |
iface = gr.Interface(fn=greet, inputs= gr.Image(label="Mel spectrogram", image_mode="L"), outputs=gr.Audio(label="Audio"))
|